OpenClonk
StdEnumAdapt< T, int_t > Struct Template Reference

#include <StdAdaptors.h>

Collaboration diagram for StdEnumAdapt< T, int_t >:
[legend]

Public Types

typedef StdEnumEntry< T > Entry
 

Public Member Functions

 StdEnumAdapt (T &rVal, const Entry *pNames)
 
void CompileFunc (StdCompiler *pComp) const
 
template<class D >
bool operator== (const D &nValue) const
 
template<class D >
StdEnumAdapt< T, int_t > & operator= (const D &nValue)
 

Public Attributes

T & rVal
 
const EntrypNames
 

Detailed Description

template<class T, class int_t = int32_t>
struct StdEnumAdapt< T, int_t >

Definition at line 803 of file StdAdaptors.h.

Member Typedef Documentation

◆ Entry

template<class T , class int_t = int32_t>
typedef StdEnumEntry<T> StdEnumAdapt< T, int_t >::Entry

Definition at line 805 of file StdAdaptors.h.

Constructor & Destructor Documentation

◆ StdEnumAdapt()

template<class T , class int_t = int32_t>
StdEnumAdapt< T, int_t >::StdEnumAdapt ( T &  rVal,
const Entry pNames 
)
inline

Definition at line 807 of file StdAdaptors.h.

807 : rVal(rVal), pNames(pNames) { assert(pNames); }
const Entry * pNames
Definition: StdAdaptors.h:808

References StdEnumAdapt< T, int_t >::pNames.

Member Function Documentation

◆ CompileFunc()

template<class T , class int_t = int32_t>
void StdEnumAdapt< T, int_t >::CompileFunc ( StdCompiler pComp) const
inline

Definition at line 810 of file StdAdaptors.h.

811  {
812  // Write as int
813  if (!pComp->isVerbose())
814  {
815  pComp->Value(mkIntAdaptT<int_t>(rVal));
816  return;
817  }
818  // writing?
819  if (!pComp->isDeserializer())
820  {
821  // Find value
822  const Entry *pName = pNames;
823  for (; pName->Name; pName++)
824  if (pName->Val == rVal)
825  {
826  // Put name
827  pComp->String(const_cast<char **>(&pName->Name), StdCompiler::RCT_Idtf);
828  break;
829  }
830  // No name found?
831  if (!pName->Name)
832  // Put value as integer
833  pComp->Value(mkIntAdaptT<int_t>(rVal));
834  }
835  // reading?
836  else
837  {
838  int_t val = 0;
839 #ifdef STDCOMPILER_EXCEPTION_WORKAROUND
840  // Try to read as number
841  if (!pComp->ValueSafe(val))
842  {
843  rVal = T(val);
844 #else
845  // Try to read as number
846  try
847  {
848  pComp->Value(val);
849  rVal = T(val);
850  }
851  catch (StdCompiler::NotFoundException *pEx)
852  {
853  delete pEx;
854 #endif
855  // Try to read as string
856  StdStrBuf Name;
857  pComp->Value(mkParAdapt(Name, StdCompiler::RCT_Idtf));
858  // Search in name list
859  const Entry *pName = pNames;
860  for (; pName->Name; pName++)
861  if (Name == pName->Name)
862  {
863  rVal = pName->Val;
864  break;
865  }
866  // Not found? Warn
867  if (!pName->Name)
868  pComp->Warn("Unknown bit name: %s", Name.getData());
869  }
870  }
871  }
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:490
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isVerbose()
Definition: StdCompiler.h:62
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped)=0
void Warn(const char *szWarning,...)
Definition: StdCompiler.cpp:21
virtual bool isDeserializer()
Definition: StdCompiler.h:53
const char * getData() const
Definition: StdBuf.h:442
StdEnumEntry< T > Entry
Definition: StdAdaptors.h:805

References StdStrBuf::getData(), StdCompiler::isDeserializer(), StdCompiler::isVerbose(), mkParAdapt(), StdEnumEntry< T >::Name, StdEnumAdapt< T, int_t >::pNames, StdCompiler::RCT_Idtf, StdEnumAdapt< T, int_t >::rVal, StdCompiler::String(), StdEnumEntry< T >::Val, StdCompiler::Value(), and StdCompiler::Warn().

Here is the call graph for this function:

◆ operator=()

template<class T , class int_t = int32_t>
template<class D >
StdEnumAdapt<T, int_t>& StdEnumAdapt< T, int_t >::operator= ( const D &  nValue)
inline

Definition at line 874 of file StdAdaptors.h.

874 { rVal = nValue; return *this; }

References StdEnumAdapt< T, int_t >::rVal.

◆ operator==()

template<class T , class int_t = int32_t>
template<class D >
bool StdEnumAdapt< T, int_t >::operator== ( const D &  nValue) const
inline

Definition at line 873 of file StdAdaptors.h.

873 { return rVal == nValue; }

References StdEnumAdapt< T, int_t >::rVal.

Member Data Documentation

◆ pNames

◆ rVal


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