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 789 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 791 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 793 of file StdAdaptors.h.

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

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 796 of file StdAdaptors.h.

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

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

860 { rVal = nValue; return *this; }

◆ 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 859 of file StdAdaptors.h.

859 { return rVal == nValue; }

Member Data Documentation

◆ pNames

template<class T, class int_t = int32_t>
const Entry* StdEnumAdapt< T, int_t >::pNames

Definition at line 794 of file StdAdaptors.h.

◆ rVal

template<class T, class int_t = int32_t>
T& StdEnumAdapt< T, int_t >::rVal

Definition at line 794 of file StdAdaptors.h.


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