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

Member Typedef Documentation

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

Definition at line 860 of file StdAdaptors.h.

Constructor & Destructor Documentation

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

Definition at line 862 of file StdAdaptors.h.

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

Member Function Documentation

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

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

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

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

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

Definition at line 949 of file StdAdaptors.h.

949 { return rVal == nValue; }

Member Data Documentation

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

Definition at line 863 of file StdAdaptors.h.

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

Definition at line 863 of file StdAdaptors.h.


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