OpenClonk
StdIntPackAdapt< T > Struct Template Reference

#include <StdAdaptors.h>

Public Member Functions

 StdIntPackAdapt (T &rVal)
 
clearUpper (T x) const
 
void CompileFunc (StdCompiler *pComp) const
 
template<class D >
bool operator== (const D &nValue) const
 
template<class D >
StdIntPackAdaptoperator= (const D &nValue)
 

Public Attributes

T & rVal
 

Detailed Description

template<class T>
struct StdIntPackAdapt< T >

Definition at line 727 of file StdAdaptors.h.

Constructor & Destructor Documentation

◆ StdIntPackAdapt()

template<class T >
StdIntPackAdapt< T >::StdIntPackAdapt ( T &  rVal)
inline

Definition at line 729 of file StdAdaptors.h.

729 : rVal(rVal) { }

Member Function Documentation

◆ clearUpper()

template<class T >
T StdIntPackAdapt< T >::clearUpper ( x) const
inline

Definition at line 732 of file StdAdaptors.h.

733  {
734  const int CLEARBITS = 8 * sizeof(T) - 7;
735  return (x << CLEARBITS) >> CLEARBITS;
736  }

Referenced by StdIntPackAdapt< T >::CompileFunc().

Here is the caller graph for this function:

◆ CompileFunc()

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

Definition at line 738 of file StdAdaptors.h.

739  {
740  // simply write for textual compilers
741  if (pComp->hasNaming())
742  {
743  pComp->Value(rVal);
744  return;
745  }
746  T val; uint8_t tmp;
747  // writing?
748  if (!pComp->isDeserializer())
749  {
750  val = rVal;
751  for (;;)
752  {
753  tmp = uint8_t(clearUpper(val));
754  // last byte?
755  if (clearUpper(val) == val)
756  break;
757  // write byte
758  tmp ^= 0x80; pComp->Value(tmp);
759  // advance
760  val >>= 7;
761  }
762  // write last byte
763  pComp->Value(tmp);
764  }
765  // reading?
766  else
767  {
768  // read first byte
769  pComp->Value(tmp);
770  val = clearUpper(T(tmp));
771  // read remaining bytes
772  int i = 7; T data = val;
773  while ( uint8_t(data) != tmp )
774  {
775  // read byte
776  pComp->Value(tmp);
777  // add to value
778  data = clearUpper(T(tmp));
779  val = (data << i) | (val & ((1 << i) - 1));
780  // next byte
781  i+=7;
782  }
783  // write
784  rVal = val;
785  }
786  }
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
virtual bool hasNaming()
Definition: StdCompiler.h:58
T clearUpper(T x) const
Definition: StdAdaptors.h:732

References StdIntPackAdapt< T >::clearUpper(), StdCompiler::hasNaming(), StdCompiler::isDeserializer(), StdIntPackAdapt< T >::rVal, and StdCompiler::Value().

Here is the call graph for this function:

◆ operator=()

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

Definition at line 788 of file StdAdaptors.h.

788 { rVal = nValue; return *this; }

References StdIntPackAdapt< T >::rVal.

◆ operator==()

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

Definition at line 787 of file StdAdaptors.h.

787 { return rVal == nValue; }

References StdIntPackAdapt< T >::rVal.

Member Data Documentation

◆ rVal

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

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