OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
StdBitfieldAdapt< T > Struct Template Reference

#include <StdAdaptors.h>

Collaboration diagram for StdBitfieldAdapt< T >:
[legend]

Public Types

typedef StdBitfieldEntry< T > Entry
 

Public Member Functions

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

Public Attributes

T & rVal
 
const EntrypNames
 

Detailed Description

template<class T>
struct StdBitfieldAdapt< T >

Definition at line 856 of file StdAdaptors.h.

Member Typedef Documentation

template<class T>
typedef StdBitfieldEntry<T> StdBitfieldAdapt< T >::Entry

Definition at line 858 of file StdAdaptors.h.

Constructor & Destructor Documentation

template<class T>
StdBitfieldAdapt< T >::StdBitfieldAdapt ( T &  rVal,
const Entry pNames 
)
inline

Definition at line 860 of file StdAdaptors.h.

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

Member Function Documentation

template<class T>
void StdBitfieldAdapt< T >::CompileFunc ( StdCompiler pComp) const
inline

Definition at line 863 of file StdAdaptors.h.

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

864  {
865  // simply write for non-verbose compilers
866  if (!pComp->isVerbose())
867  {
868  pComp->Value(rVal);
869  return;
870  }
871  // writing?
872  if (!pComp->isDeserializer())
873  {
874  T val = rVal, orig_val = rVal;
875  // Write until value is comsumed
876  bool fFirst = true;
877  for (const Entry *pName = pNames; pName->Name; pName++)
878  if ((pName->Val & val) == pName->Val)
879  {
880  // Avoid writing meaningless none-values (e.g. Category=C4D_None|C4D_Object)
881  if (orig_val && !pName->Val) continue;
882  // Put "|"
883  if (!fFirst) pComp->Separator(StdCompiler::SEP_VLINE);
884  // Put name
885  pComp->String(const_cast<char **>(&pName->Name), StdCompiler::RCT_Idtf);
886  fFirst = false;
887  // Remove bits
888  val &= ~pName->Val;
889  }
890  // Anything left is written as number, or a simple 0 in case no default was used
891  if (val || fFirst)
892  {
893  // Put "|"
894  if (!fFirst) pComp->Separator(StdCompiler::SEP_VLINE);
895  // Put value
896  pComp->Value(val);
897  }
898  }
899  // reading?
900  else
901  {
902  T val = 0;
903  // Read
904  do
905  {
906 #ifdef STDCOMPILER_EXCEPTION_WORKAROUND
907  T tmp;
908  // Try to read as number
909  if (pComp->ValueSafe(tmp))
910  val |= tmp;
911  else
912  {
913 #else
914  // Try to read as number
915  try
916  {
917  T tmp;
918  pComp->Value(tmp);
919  val |= tmp;
920  }
921  catch (StdCompiler::NotFoundException *pEx)
922  {
923  delete pEx;
924 #endif
925  // Try to read as string
926  StdStrBuf Name;
927  pComp->Value(mkParAdapt(Name, StdCompiler::RCT_Idtf));
928  // Search in name list
929  const Entry *pName = pNames;
930  for (; pName->Name; pName++)
931  if (Name == pName->Name)
932  {
933  val |= pName->Val;
934  break;
935  }
936  // Not found? Warn
937  if (!pName->Name)
938  pComp->Warn("Unknown bit name: %s", Name.getData());
939  }
940  // Expect separation
941  } while (pComp->Separator(StdCompiler::SEP_VLINE));
942  // Write value back
943  rVal = val;
944  }
945  }
const char * getData() const
Definition: StdBuf.h:450
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:129
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:170
virtual bool isDeserializer()
Definition: StdCompiler.h:63
StdBitfieldEntry< T > Entry
Definition: StdAdaptors.h:858
void Warn(const char *szWarning,...)
Definition: StdCompiler.cpp:26
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:456
const char * Name
Definition: StdAdaptors.h:850
const Entry * pNames
Definition: StdAdaptors.h:861

Here is the call graph for this function:

template<class T>
template<class D >
StdBitfieldAdapt<T>& StdBitfieldAdapt< T >::operator= ( const D &  nValue)
inline

Definition at line 948 of file StdAdaptors.h.

948 { rVal = nValue; return *this; }
template<class T>
template<class D >
bool StdBitfieldAdapt< T >::operator== ( const D &  nValue) const
inline

Definition at line 947 of file StdAdaptors.h.

947 { return rVal == nValue; }

Member Data Documentation

template<class T>
const Entry* StdBitfieldAdapt< T >::pNames

Definition at line 861 of file StdAdaptors.h.

template<class T>
T& StdBitfieldAdapt< T >::rVal

Definition at line 861 of file StdAdaptors.h.


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