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

#include <C4Value.h>

Public Member Functions

 C4ValueNumbers ()
 
uint32_t GetNumberForValue (C4Value *v)
 
const C4ValueGetValue (uint32_t)
 
void Denumerate ()
 
void CompileFunc (StdCompiler *)
 
void CompileValue (StdCompiler *, C4Value *)
 

Detailed Description

Definition at line 256 of file C4Value.h.

Constructor & Destructor Documentation

C4ValueNumbers::C4ValueNumbers ( )
inline

Definition at line 259 of file C4Value.h.

259 {}

Member Function Documentation

void C4ValueNumbers::CompileFunc ( StdCompiler pComp)

Definition at line 494 of file C4Value.cpp.

References CompileValue(), StdCompiler::hasNaming(), StdCompiler::isDeserializer(), iSize, StdCompiler::SEP_SEP, StdCompiler::Separator(), and StdCompiler::Value().

495 {
496  bool deserializing = pComp->isDeserializer();
497  bool fNaming = pComp->hasNaming();
498  if (deserializing)
499  {
500  uint32_t iSize;
501  if (!fNaming) pComp->Value(iSize);
502  // Read new
503  do
504  {
505  // No entries left to read?
506  if (!fNaming && !iSize--)
507  break;
508  // Read entries
509  try
510  {
511  LoadedValues.push_back(C4Value());
512  CompileValue(pComp, &LoadedValues.back());
513  }
514  catch (StdCompiler::NotFoundException *pEx)
515  {
516  // No value found: Stop reading loop
517  delete pEx;
518  break;
519  }
520  }
521  while (pComp->Separator(StdCompiler::SEP_SEP));
522  }
523  else
524  {
525  // Note: the list grows during this loop due to nested data structures.
526  // Data structures with loops are fine because the beginning of the loop
527  // will be found in the map and not saved again.
528  // This may still work with the binary compilers due to double-compiling
529  if (!fNaming)
530  {
531  int32_t iSize = ValuesToSave.size();
532  pComp->Value(iSize);
533  }
534  for(std::list<C4Value *>::iterator i = ValuesToSave.begin(); i != ValuesToSave.end(); ++i)
535  {
536  CompileValue(pComp, *i);
537  if (i != ValuesToSave.end()) pComp->Separator(StdCompiler::SEP_SEP);
538  }
539  }
540 }
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:129
virtual bool hasNaming()
Definition: StdCompiler.h:68
void CompileValue(StdCompiler *, C4Value *)
Definition: C4Value.cpp:458
void Value(const T &rStruct)
Definition: StdCompiler.h:171
virtual bool isDeserializer()
Definition: StdCompiler.h:63
int iSize
Definition: TstC4NetIO.cpp:35

Here is the call graph for this function:

void C4ValueNumbers::CompileValue ( StdCompiler pComp,
C4Value v 
)

Definition at line 458 of file C4Value.cpp.

References C4Value::_getArray(), C4Value::_getPropList(), a, C4V_Array, C4V_PropList, StdCompiler::Character(), StdCompiler::excCorrupt(), C4Value::GetType(), StdCompiler::isDeserializer(), mkParAdapt(), mkPtrAdaptNoNull(), StdCompiler::SEP_END, StdCompiler::SEP_START, StdCompiler::Separator(), C4Value::SetArray(), C4Value::SetPropList(), and StdCompiler::Value().

Referenced by CompileFunc().

459 {
460  // Type
461  bool deserializing = pComp->isDeserializer();
462  char cC4VID;
463  switch(v->GetType())
464  {
465  case C4V_PropList: cC4VID = 'p'; break;
466  case C4V_Array: cC4VID = 'a'; break;
467  default: assert(deserializing); break;
468  }
469  pComp->Character(cC4VID);
471  switch(cC4VID)
472  {
473  case 'p':
474  {
475  C4PropList * p = v->_getPropList();
476  pComp->Value(mkParAdapt(mkPtrAdaptNoNull(p), this));
477  if (deserializing) v->SetPropList(p);
478  }
479  break;
480  case 'a':
481  {
482  C4ValueArray * a = v->_getArray();
483  pComp->Value(mkParAdapt(mkPtrAdaptNoNull(a), this));
484  if (deserializing) v->SetArray(a);
485  }
486  break;
487  default:
488  pComp->excCorrupt("Unexpected character '%c'", cC4VID);
489  break;
490  }
492 }
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:129
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:259
#define a
C4ValueArray * _getArray() const
Definition: C4Value.h:127
C4V_Type GetType() const
Definition: C4Value.h:161
StdPtrAdapt< T > mkPtrAdaptNoNull(T *&rpObj)
Definition: StdAdaptors.h:607
void SetArray(C4ValueArray *Array)
Definition: C4Value.h:139
void Value(const T &rStruct)
Definition: StdCompiler.h:171
virtual bool isDeserializer()
Definition: StdCompiler.h:63
virtual void Character(char &rChar)=0
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:459
void SetPropList(C4PropList *PropList)
Definition: C4Value.h:141
C4PropList * _getPropList() const
Definition: C4Value.h:129

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ValueNumbers::Denumerate ( )

Definition at line 283 of file C4Value.cpp.

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

284 {
285  for (std::vector<C4Value>::iterator i = LoadedValues.begin(); i != LoadedValues.end(); ++i)
286  i->Denumerate(this);
287 }

Here is the caller graph for this function:

uint32_t C4ValueNumbers::GetNumberForValue ( C4Value v)

Definition at line 289 of file C4Value.cpp.

References C4Value::GetData().

Referenced by C4Value::CompileFunc().

290 {
291  // This is only used for C4Values containing pointers
292  // Assume that all pointers have the same size
293  if (ValueNumbers.find(v->GetData()) == ValueNumbers.end())
294  {
295  ValuesToSave.push_back(v);
296  ValueNumbers[v->GetData()] = ValuesToSave.size();
297  return ValuesToSave.size();
298  }
299  return ValueNumbers[v->GetData()];
300 }
C4V_Data GetData() const
Definition: C4Value.h:160

Here is the call graph for this function:

Here is the caller graph for this function:

const C4Value & C4ValueNumbers::GetValue ( uint32_t  n)

Definition at line 245 of file C4Value.cpp.

References C4VNull, and LogF().

Referenced by C4Value::Denumerate(), and C4ScriptGuiWindow::Denumerate().

246 {
247  if (n <= LoadedValues.size())
248  return LoadedValues[n - 1];
249  LogF("ERROR: Value number %d is missing.", n);
250  return C4VNull;
251 }
const C4Value C4VNull
Definition: C4Value.cpp:32
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253

Here is the call graph for this function:

Here is the caller graph for this function:


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