OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ValueMapData Class Reference

#include <C4ValueMap.h>

Collaboration diagram for C4ValueMapData:
[legend]

Public Member Functions

 C4ValueMapData ()
 
 C4ValueMapData (const C4ValueMapData &DataToCopy)
 
virtual ~C4ValueMapData ()
 
C4ValueMapDataoperator= (const C4ValueMapData &DataToCopy)
 
bool operator== (const C4ValueMapData &Data) const
 
C4ValueGetItem (const char *strName)
 
C4ValueGetItem (int32_t iNr)
 
void SetNameList (C4ValueMapNames *pnNames)
 
C4ValueMapNamesCreateTempNameList ()
 
void Reset ()
 
void ResetContent ()
 
int32_t GetAnzItems ()
 
C4Valueoperator[] (int32_t iNr)
 
C4Valueoperator[] (const char *strName)
 
void Denumerate (C4ValueNumbers *)
 
void CompileFunc (StdCompiler *pComp, C4ValueNumbers *)
 

Public Attributes

C4ValuepData
 
C4ValueMapNamespNames
 
bool bTempNameList
 

Friends

class C4ValueMapNames
 

Detailed Description

Definition at line 27 of file C4ValueMap.h.

Constructor & Destructor Documentation

C4ValueMapData::C4ValueMapData ( )

Definition at line 24 of file C4ValueMap.cpp.

25  : pData(0), pNames(0), bTempNameList(false), pNext(0)
26 {
27 
28 }
bool bTempNameList
Definition: C4ValueMap.h:48
C4ValueMapNames * pNames
Definition: C4ValueMap.h:44
C4Value * pData
Definition: C4ValueMap.h:41
C4ValueMapData::C4ValueMapData ( const C4ValueMapData DataToCopy)

Definition at line 30 of file C4ValueMap.cpp.

References C4ValueMapNames::iSize, pData, pNames, and SetNameList().

31  : pData(0), pNames(0), bTempNameList(false), pNext(0)
32 {
33  SetNameList(DataToCopy.pNames);
34  if (pNames) for (int32_t i = 0; i < pNames->iSize; i++)
35  pData[i].Set(DataToCopy.pData[i]);
36 }
bool bTempNameList
Definition: C4ValueMap.h:48
void SetNameList(C4ValueMapNames *pnNames)
Definition: C4ValueMap.cpp:83
C4ValueMapNames * pNames
Definition: C4ValueMap.h:44
C4Value * pData
Definition: C4ValueMap.h:41

Here is the call graph for this function:

C4ValueMapData::~C4ValueMapData ( )
virtual

Definition at line 56 of file C4ValueMap.cpp.

References Reset().

57 {
58  Reset();
59 }

Here is the call graph for this function:

Member Function Documentation

void C4ValueMapData::CompileFunc ( StdCompiler pComp,
C4ValueNumbers numbers 
)

Definition at line 266 of file C4ValueMap.cpp.

References CreateTempNameList(), StdStrBuf::GrabPointer(), StdCompiler::isDeserializer(), C4ValueMapNames::iSize, mkDefaultAdapt(), mkParAdapt(), pData, pNames, C4ValueMapNames::pNames, StdCompiler::RCT_Idtf, StdStrBuf::Ref(), Reset(), StdCompiler::SEP_SEP2, StdCompiler::SEP_SET, StdCompiler::Separator(), C4ValueMapNames::SetNameArray(), SetNameList(), and StdCompiler::Value().

267 {
268  bool deserializing = pComp->isDeserializer();
269  C4ValueMapNames *pOldNames = pNames;
270  if (deserializing) Reset();
271  // Compile item count
272  int32_t iValueCnt;
273  if (!deserializing) iValueCnt = pNames ? pNames->iSize : 0;
274  pComp->Value(mkDefaultAdapt(iValueCnt, 0));
275  // nuthing 2do for no items
276  if (!iValueCnt) return;
277  // Separator (';')
279  // Data
280  char **ppNames = !deserializing ? pNames->pNames : new char * [iValueCnt];
281  if (deserializing) for (int32_t i = 0; i < iValueCnt; i++) ppNames[i] = 0;
282  C4Value *pValues = !deserializing ? pData : new C4Value [iValueCnt];
283  // Compile
284  try
285  {
286  for (int32_t i = 0; i < iValueCnt; i++)
287  {
288  // Separate
289  if (i) pComp->Separator();
290  // Name
291  StdStrBuf Name;
292  if (!deserializing) Name.Ref(ppNames[i]);
293  pComp->Value(mkParAdapt(Name, StdCompiler::RCT_Idtf));
294  if (deserializing) ppNames[i] = Name.GrabPointer();
295  // Separator ('=')
297  // Value
298  pComp->Value(mkParAdapt(pValues[i], numbers));
299  }
300  }
301  catch (...)
302  {
303  // make sure no mem is leaked on compiler error in name list
304  if (deserializing)
305  {
306  for (int32_t i = 0; i < iValueCnt; i++) if (ppNames[i]) free(ppNames[i]);
307  delete [] ppNames;
308  delete [] pValues;
309  }
310  throw;
311  }
312  // Set
313  if (deserializing)
314  {
315  // Set
317  pNames->SetNameArray(const_cast<const char **>(ppNames), iValueCnt);
318  for (int32_t i = 0; i < iValueCnt; i++) free(ppNames[i]);
319  delete [] ppNames; delete [] pData;
320  pData = pValues;
321  // Assign old name list
322  if (pOldNames) SetNameList(pOldNames);
323  }
324 }
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:129
char * GrabPointer()
Definition: StdBuf.h:467
void SetNameList(C4ValueMapNames *pnNames)
Definition: C4ValueMap.cpp:83
void SetNameArray(const char **pnNames, int32_t nSize)
Definition: C4ValueMap.cpp:433
C4ValueMapNames * pNames
Definition: C4ValueMap.h:44
void Value(const T &rStruct)
Definition: StdCompiler.h:171
virtual bool isDeserializer()
Definition: StdCompiler.h:63
void Ref(const char *pnData)
Definition: StdBuf.h:463
C4ValueMapNames * CreateTempNameList()
Definition: C4ValueMap.cpp:151
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:459
StdDefaultAdapt< T, D > mkDefaultAdapt(T &&rValue, const D &rDefault)
Definition: StdAdaptors.h:65
char ** pNames
Definition: C4ValueMap.h:106
C4Value * pData
Definition: C4ValueMap.h:41

Here is the call graph for this function:

C4ValueMapNames * C4ValueMapData::CreateTempNameList ( )

Definition at line 151 of file C4ValueMap.cpp.

References bTempNameList, and C4ValueMapNames.

Referenced by CompileFunc().

152 {
153  // create new list
154  C4ValueMapNames *pTempNames = new C4ValueMapNames();
155 
156  // register (this func will unreg if necessary, too)
157  Register(pTempNames);
158 
159  // error?
160  if (pNames != pTempNames)
161  {
162  delete pTempNames;
163  return 0;
164  }
165 
166  // set flag
167  bTempNameList = true;
168 
169  return pTempNames;
170 }
bool bTempNameList
Definition: C4ValueMap.h:48
friend class C4ValueMapNames
Definition: C4ValueMap.h:29
C4ValueMapNames * pNames
Definition: C4ValueMap.h:44

Here is the caller graph for this function:

void C4ValueMapData::Denumerate ( C4ValueNumbers numbers)

Definition at line 259 of file C4ValueMap.cpp.

References C4ValueMapNames::iSize, and pData.

Referenced by C4ObjectInfoCore::CompileFunc(), and C4PlayerInfoCore::CompileFunc().

260 {
261  if (!pNames) return;
262  for (int32_t i = 0; i < pNames->iSize; i++)
263  pData[i].Denumerate(numbers);
264 }
void Denumerate(C4ValueNumbers *)
Definition: C4ValueMap.cpp:259
C4ValueMapNames * pNames
Definition: C4ValueMap.h:44
C4Value * pData
Definition: C4ValueMap.h:41

Here is the caller graph for this function:

int32_t C4ValueMapData::GetAnzItems ( )

Definition at line 253 of file C4ValueMap.cpp.

References C4ValueMapNames::iSize.

254 {
255  if (!pNames) return 0;
256  return pNames->iSize;
257 }
C4ValueMapNames * pNames
Definition: C4ValueMap.h:44
C4Value * C4ValueMapData::GetItem ( const char *  strName)

Definition at line 240 of file C4ValueMap.cpp.

References C4ValueMapNames::GetItemNr(), and pData.

Referenced by operator[](), and C4AulCompiler::ConstantResolver::visit().

241 {
242  assert(pNames);
243  if (!pNames) return 0;
244 
245  int32_t iNr = pNames->GetItemNr(strName);
246  assert(iNr != -1);
247 
248  if (iNr == -1) return 0;
249 
250  return &pData[iNr];
251 }
C4ValueMapNames * pNames
Definition: C4ValueMap.h:44
int32_t GetItemNr(const char *strName) const
Definition: C4ValueMap.cpp:469
C4Value * pData
Definition: C4ValueMap.h:41

Here is the call graph for this function:

Here is the caller graph for this function:

C4Value * C4ValueMapData::GetItem ( int32_t  iNr)

Definition at line 227 of file C4ValueMap.cpp.

References iSize, C4ValueMapNames::iSize, and pData.

228 {
229  assert(pNames);
230  assert(iNr < pNames->iSize);
231  assert(iNr >= 0);
232  // the list is nothing without name list...
233  if (!pNames) return 0;
234 
235  if (iNr >= pNames->iSize) return 0;
236 
237  return &pData[iNr];
238 }
C4ValueMapNames * pNames
Definition: C4ValueMap.h:44
int iSize
Definition: TstC4NetIO.cpp:35
C4Value * pData
Definition: C4ValueMap.h:41
C4ValueMapData & C4ValueMapData::operator= ( const C4ValueMapData DataToCopy)

Definition at line 38 of file C4ValueMap.cpp.

References C4ValueMapNames::iSize, pData, pNames, and SetNameList().

39 {
40  SetNameList(DataToCopy.pNames);
41  if (pNames) for (int32_t i = 0; i < pNames->iSize; i++)
42  pData[i].Set(DataToCopy.pData[i]);
43  return *this;
44 }
void SetNameList(C4ValueMapNames *pnNames)
Definition: C4ValueMap.cpp:83
C4ValueMapNames * pNames
Definition: C4ValueMap.h:44
C4Value * pData
Definition: C4ValueMap.h:41

Here is the call graph for this function:

bool C4ValueMapData::operator== ( const C4ValueMapData Data) const

Definition at line 46 of file C4ValueMap.cpp.

References C4ValueMapNames::iSize, pData, and pNames.

47 {
48  if (pNames != Data.pNames) return false;
49  if (pNames)
50  for (int i = 0; i < pNames->iSize; i++)
51  if (pData[i] != Data.pData[i])
52  return false;
53  return true;
54 }
C4ValueMapNames * pNames
Definition: C4ValueMap.h:44
C4Value * pData
Definition: C4ValueMap.h:41
C4Value& C4ValueMapData::operator[] ( int32_t  iNr)
inline

Definition at line 67 of file C4ValueMap.h.

References GetItem().

67 { return *GetItem(iNr); }
C4Value * GetItem(const char *strName)
Definition: C4ValueMap.cpp:240

Here is the call graph for this function:

C4Value& C4ValueMapData::operator[] ( const char *  strName)
inline

Definition at line 68 of file C4ValueMap.h.

References GetItem().

68 { return *GetItem(strName); }
C4Value * GetItem(const char *strName)
Definition: C4ValueMap.cpp:240

Here is the call graph for this function:

void C4ValueMapData::Reset ( )

Definition at line 61 of file C4ValueMap.cpp.

References pData, and pNames.

Referenced by CompileFunc(), C4ObjectInfoCore::Default(), C4PlayerInfoCore::Default(), and ~C4ValueMapData().

62 {
63  // unreg from name list (if using one)
64  if (pNames) UnRegister();
65  pNames = 0;
66  // free data
67  delete[] pData;
68  pData = 0;
69 }
C4ValueMapNames * pNames
Definition: C4ValueMap.h:44
C4Value * pData
Definition: C4ValueMap.h:41

Here is the caller graph for this function:

void C4ValueMapData::ResetContent ( )

Definition at line 71 of file C4ValueMap.cpp.

References pData, and pNames.

72 {
73  if (pNames)
74  // Realloc list (will destroy all data)
75  ReAllocList();
76  else
77  {
78  delete[] pData;
79  pData = 0;
80  }
81 }
C4ValueMapNames * pNames
Definition: C4ValueMap.h:44
C4Value * pData
Definition: C4ValueMap.h:41
void C4ValueMapData::SetNameList ( C4ValueMapNames pnNames)

Definition at line 83 of file C4ValueMap.cpp.

References bTempNameList, C4ValueMapNames::iSize, pNames, and C4ValueMapNames::pNames.

Referenced by C4ValueMapData(), CompileFunc(), C4AulScriptEngine::Link(), and operator=().

84 {
85  if (pNames == pnNames) return;
86  if (pNames)
87  {
88  // save name array from old name list
89  char **pOldNames = pNames->pNames;
90  int32_t iOldSize = pNames->iSize;
91 
92  // unreg from old name list
93  // (manually, because Data::UnRegister() would destroy content)
94  C4ValueMapNames *pNames = this->pNames;
95 
96  pNames->UnRegister(this);
97 
98  // register at new name list
99  pnNames->Register(this);
100 
101  // call OnNameListChanged to copy data and realloc data array
102  OnNameListChanged(const_cast<const char **>(pOldNames), iOldSize);
103 
104  // delete old names list, if it is temporary
105  if (bTempNameList)
106  delete pNames;
107  bTempNameList = false;
108 
109  // ok
110  }
111  else
112  {
113  // simply register...
114  Register(pnNames);
115  }
116 }
bool bTempNameList
Definition: C4ValueMap.h:48
C4ValueMapNames * pNames
Definition: C4ValueMap.h:44
char ** pNames
Definition: C4ValueMap.h:106

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4ValueMapNames
friend

Definition at line 29 of file C4ValueMap.h.

Referenced by CreateTempNameList().

Member Data Documentation

bool C4ValueMapData::bTempNameList

Definition at line 48 of file C4ValueMap.h.

Referenced by CreateTempNameList(), and SetNameList().

C4Value* C4ValueMapData::pData
C4ValueMapNames* C4ValueMapData::pNames

The documentation for this class was generated from the following files: