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

#include <C4Value.h>

Public Member Functions

 C4ValueNumbers ()=default
 
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 ( )
default

Member Function Documentation

void C4ValueNumbers::CompileFunc ( StdCompiler pComp)

Definition at line 492 of file C4Value.cpp.

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

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

Here is the call graph for this function:

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

Definition at line 456 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().

457 {
458  // Type
459  bool deserializing = pComp->isDeserializer();
460  char cC4VID;
461  switch(v->GetType())
462  {
463  case C4V_PropList: cC4VID = 'p'; break;
464  case C4V_Array: cC4VID = 'a'; break;
465  default: assert(deserializing); break;
466  }
467  pComp->Character(cC4VID);
469  switch(cC4VID)
470  {
471  case 'p':
472  {
473  C4PropList * p = v->_getPropList();
474  pComp->Value(mkParAdapt(mkPtrAdaptNoNull(p), this));
475  if (deserializing) v->SetPropList(p);
476  }
477  break;
478  case 'a':
479  {
480  C4ValueArray * a = v->_getArray();
481  pComp->Value(mkParAdapt(mkPtrAdaptNoNull(a), this));
482  if (deserializing) v->SetArray(a);
483  }
484  break;
485  default:
486  pComp->excCorrupt("Unexpected character '%c'", cC4VID);
487  break;
488  }
490 }
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:119
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:249
#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:606
void SetArray(C4ValueArray *Array)
Definition: C4Value.h:139
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
virtual void Character(char &rChar)=0
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:458
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 281 of file C4Value.cpp.

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

282 {
283  for (auto & LoadedValue : LoadedValues)
284  LoadedValue.Denumerate(this);
285 }

Here is the caller graph for this function:

uint32_t C4ValueNumbers::GetNumberForValue ( C4Value v)

Definition at line 287 of file C4Value.cpp.

References C4Value::GetData().

Referenced by C4Value::CompileFunc().

288 {
289  // This is only used for C4Values containing pointers
290  // Assume that all pointers have the same size
291  if (ValueNumbers.find(v->GetData()) == ValueNumbers.end())
292  {
293  ValuesToSave.push_back(v);
294  ValueNumbers[v->GetData()] = ValuesToSave.size();
295  return ValuesToSave.size();
296  }
297  return ValueNumbers[v->GetData()];
298 }
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 243 of file C4Value.cpp.

References C4VNull, and LogF().

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

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

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: