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

Member Typedef Documentation

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

Definition at line 861 of file StdAdaptors.h.

Constructor & Destructor Documentation

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

Definition at line 863 of file StdAdaptors.h.

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

Member Function Documentation

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

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

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

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

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

Definition at line 950 of file StdAdaptors.h.

950 { return rVal == nValue; }

Member Data Documentation

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

Definition at line 864 of file StdAdaptors.h.

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

Definition at line 864 of file StdAdaptors.h.


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