OpenClonk
StdArrayDefaultAdapt< T, D, M > Struct Template Reference

#include <StdAdaptors.h>

Public Member Functions

 StdArrayDefaultAdapt (T *pArray, size_t iSize, const D &rDefault, const M &map=M())
 
void CompileFunc (StdCompiler *pComp) const
 
bool operator== (const T *pDefaults) const
 
StdArrayDefaultAdaptoperator= (const T *pDefaults)
 

Public Attributes

T * pArray
 
size_t iSize
 
const D & rDefault
 
const M map
 

Detailed Description

template<class T, class D, class M = _IdFuncClass<T>>
struct StdArrayDefaultAdapt< T, D, M >

Definition at line 337 of file StdAdaptors.h.

Constructor & Destructor Documentation

◆ StdArrayDefaultAdapt()

template<class T, class D, class M = _IdFuncClass<T>>
StdArrayDefaultAdapt< T, D, M >::StdArrayDefaultAdapt ( T *  pArray,
size_t  iSize,
const D &  rDefault,
const M &  map = M() 
)
inline

Definition at line 339 of file StdAdaptors.h.

Member Function Documentation

◆ CompileFunc()

template<class T, class D, class M = _IdFuncClass<T>>
void StdArrayDefaultAdapt< T, D, M >::CompileFunc ( StdCompiler pComp) const
inline

Definition at line 343 of file StdAdaptors.h.

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

344  {
345  size_t i, iWrite = iSize;
346  bool deserializing = pComp->isDeserializer();
347  // Decompiling: Omit defaults
348  if (!deserializing && pComp->hasNaming())
349  while (iWrite > 0 && pArray[iWrite - 1] == rDefault)
350  iWrite--;
351  // Read/write values
352  for (i = 0; i < iWrite; i++)
353  {
354  // Separator?
355  if (i) if (!pComp->Separator(StdCompiler::SEP_SEP)) break;
356  // Expect a value. Default if not found.
357  pComp->Value(mkDefaultAdapt(map(pArray[i]), rDefault));
358  }
359  // Fill rest of array
360  if (deserializing)
361  for (; i < iSize; i++)
362  pArray[i] = rDefault;
363  }
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:119
virtual bool hasNaming()
Definition: StdCompiler.h:58
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
StdDefaultAdapt< T, D > mkDefaultAdapt(T &&rValue, const D &rDefault)
Definition: StdAdaptors.h:64
Here is the call graph for this function:

◆ operator=()

template<class T, class D, class M = _IdFuncClass<T>>
StdArrayDefaultAdapt& StdArrayDefaultAdapt< T, D, M >::operator= ( const T *  pDefaults)
inline

Definition at line 372 of file StdAdaptors.h.

References iSize.

373  {
374  for (size_t i = 0; i < iSize; i++)
375  pArray[i] = pDefaults[i];
376  return *this;
377  }

◆ operator==()

template<class T, class D, class M = _IdFuncClass<T>>
bool StdArrayDefaultAdapt< T, D, M >::operator== ( const T *  pDefaults) const
inline

Definition at line 365 of file StdAdaptors.h.

References iSize.

366  {
367  for (size_t i = 0; i < iSize; i++)
368  if (pArray[i] != pDefaults[i])
369  return false;
370  return true;
371  }

Member Data Documentation

◆ iSize

template<class T, class D, class M = _IdFuncClass<T>>
size_t StdArrayDefaultAdapt< T, D, M >::iSize

Definition at line 342 of file StdAdaptors.h.

◆ map

template<class T, class D, class M = _IdFuncClass<T>>
const M StdArrayDefaultAdapt< T, D, M >::map

Definition at line 342 of file StdAdaptors.h.

◆ pArray

template<class T, class D, class M = _IdFuncClass<T>>
T* StdArrayDefaultAdapt< T, D, M >::pArray

Definition at line 342 of file StdAdaptors.h.

◆ rDefault

template<class T, class D, class M = _IdFuncClass<T>>
const D& StdArrayDefaultAdapt< T, D, M >::rDefault

Definition at line 342 of file StdAdaptors.h.


The documentation for this struct was generated from the following file: