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 771 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 773 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 775 of file StdAdaptors.h.

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

Member Function Documentation

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

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

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

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

842 { 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 841 of file StdAdaptors.h.

841 { 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: