OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 769 of file StdAdaptors.h.

Member Typedef Documentation

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

Definition at line 771 of file StdAdaptors.h.

Constructor & Destructor Documentation

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

Definition at line 773 of file StdAdaptors.h.

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

Member Function Documentation

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

Definition at line 776 of file StdAdaptors.h.

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

777  {
778  // Write as int
779  if (!pComp->isVerbose())
780  {
781  pComp->Value(mkIntAdaptT<int_t>(rVal));
782  return;
783  }
784  // writing?
785  if (!pComp->isDeserializer())
786  {
787  // Find value
788  const Entry *pName = pNames;
789  for (; pName->Name; pName++)
790  if (pName->Val == rVal)
791  {
792  // Put name
793  pComp->String(const_cast<char **>(&pName->Name), StdCompiler::RCT_Idtf);
794  break;
795  }
796  // No name found?
797  if (!pName->Name)
798  // Put value as integer
799  pComp->Value(mkIntAdaptT<int_t>(rVal));
800  }
801  // reading?
802  else
803  {
804  int_t val = 0;
805 #ifdef STDCOMPILER_EXCEPTION_WORKAROUND
806  // Try to read as number
807  if (!pComp->ValueSafe(val))
808  {
809  rVal = T(val);
810 #else
811  // Try to read as number
812  try
813  {
814  pComp->Value(val);
815  rVal = T(val);
816  }
817  catch (StdCompiler::NotFoundException *pEx)
818  {
819  delete pEx;
820 #endif
821  // Try to read as string
822  StdStrBuf Name;
823  pComp->Value(mkParAdapt(Name, StdCompiler::RCT_Idtf));
824  // Search in name list
825  const Entry *pName = pNames;
826  for (; pName->Name; pName++)
827  if (Name == pName->Name)
828  {
829  rVal = pName->Val;
830  break;
831  }
832  // Not found? Warn
833  if (!pName->Name)
834  pComp->Warn("Unknown bit name: %s", Name.getData());
835  }
836  }
837  }
const char * getData() const
Definition: StdBuf.h:450
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped)=0
virtual bool isVerbose()
Definition: StdCompiler.h:72
void Value(const T &rStruct)
Definition: StdCompiler.h:171
virtual bool isDeserializer()
Definition: StdCompiler.h:63
const Entry * pNames
Definition: StdAdaptors.h:774
void Warn(const char *szWarning,...)
Definition: StdCompiler.cpp:26
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:456
StdEnumEntry< T > Entry
Definition: StdAdaptors.h:771

Here is the call graph for this function:

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

840 { rVal = nValue; return *this; }
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 839 of file StdAdaptors.h.

839 { return rVal == nValue; }

Member Data Documentation

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

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