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

Member Typedef Documentation

◆ Entry

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

Definition at line 892 of file StdAdaptors.h.

Constructor & Destructor Documentation

◆ StdBitfieldAdapt()

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

Definition at line 894 of file StdAdaptors.h.

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

References StdEnumAdapt< T, int_t >::pNames.

Member Function Documentation

◆ CompileFunc()

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

Definition at line 897 of file StdAdaptors.h.

898  {
899  // simply write for non-verbose compilers
900  if (!pComp->isVerbose())
901  {
902  pComp->Value(rVal);
903  return;
904  }
905  // writing?
906  if (!pComp->isDeserializer())
907  {
908  T val = rVal, orig_val = rVal;
909  // Write until value is comsumed
910  bool fFirst = true;
911  for (const Entry *pName = pNames; pName->Name; pName++)
912  if ((pName->Val & val) == pName->Val)
913  {
914  // Avoid writing meaningless none-values (e.g. Category=C4D_None|C4D_Object)
915  if (orig_val && !pName->Val) continue;
916  // Put "|"
917  if (!fFirst) pComp->Separator(StdCompiler::SEP_VLINE);
918  // Put name
919  pComp->String(const_cast<char **>(&pName->Name), StdCompiler::RCT_Idtf);
920  fFirst = false;
921  // Remove bits
922  val &= ~pName->Val;
923  }
924  // Anything left is written as number, or a simple 0 in case no default was used
925  if (val || fFirst)
926  {
927  // Put "|"
928  if (!fFirst) pComp->Separator(StdCompiler::SEP_VLINE);
929  // Put value
930  pComp->Value(val);
931  }
932  }
933  // reading?
934  else
935  {
936  T val = 0;
937  // Read
938  do
939  {
940 #ifdef STDCOMPILER_EXCEPTION_WORKAROUND
941  T tmp;
942  // Try to read as number
943  if (pComp->ValueSafe(tmp))
944  val |= tmp;
945  else
946  {
947 #else
948  // Try to read as number
949  try
950  {
951  T tmp;
952  pComp->Value(tmp);
953  val |= tmp;
954  }
955  catch (StdCompiler::NotFoundException *pEx)
956  {
957  delete pEx;
958 #endif
959  // Try to read as string
960  StdStrBuf Name;
961  pComp->Value(mkParAdapt(Name, StdCompiler::RCT_Idtf));
962  // Search in name list
963  const Entry *pName = pNames;
964  for (; pName->Name; pName++)
965  if (Name == pName->Name)
966  {
967  val |= pName->Val;
968  break;
969  }
970  // Not found? Warn
971  if (!pName->Name)
972  pComp->Warn("Unknown bit name: %s", Name.getData());
973  }
974  // Expect separation
975  } while (pComp->Separator(StdCompiler::SEP_VLINE));
976  // Write value back
977  rVal = val;
978  }
979  }
const char * Name
Definition: StdAdaptors.h:884
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:490
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:119
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isVerbose()
Definition: StdCompiler.h:62
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped)=0
void Warn(const char *szWarning,...)
Definition: StdCompiler.cpp:21
virtual bool isDeserializer()
Definition: StdCompiler.h:53
const char * getData() const
Definition: StdBuf.h:442
StdBitfieldEntry< T > Entry
Definition: StdAdaptors.h:892

References StdStrBuf::getData(), StdCompiler::isDeserializer(), StdCompiler::isVerbose(), mkParAdapt(), StdEnumEntry< T >::Name, 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().

Here is the call graph for this function:

◆ operator=()

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

Definition at line 982 of file StdAdaptors.h.

982 { rVal = nValue; return *this; }

References StdEnumAdapt< T, int_t >::rVal.

◆ operator==()

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

Definition at line 981 of file StdAdaptors.h.

981 { return rVal == nValue; }

References StdEnumAdapt< T, int_t >::rVal.

Member Data Documentation

◆ pNames

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

Definition at line 895 of file StdAdaptors.h.

◆ rVal

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

Definition at line 895 of file StdAdaptors.h.


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