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

Constructor & Destructor Documentation

◆ StdIntPackAdapt()

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

Definition at line 715 of file StdAdaptors.h.

715 : rVal(rVal) { }

Member Function Documentation

◆ clearUpper()

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

Definition at line 718 of file StdAdaptors.h.

719  {
720  const int CLEARBITS = 8 * sizeof(T) - 7;
721  return (x << CLEARBITS) >> CLEARBITS;
722  }

◆ CompileFunc()

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

Definition at line 724 of file StdAdaptors.h.

References StdCompiler::hasNaming(), StdCompiler::isDeserializer(), and StdCompiler::Value().

725  {
726  // simply write for textual compilers
727  if (pComp->hasNaming())
728  {
729  pComp->Value(rVal);
730  return;
731  }
732  T val; uint8_t tmp;
733  // writing?
734  if (!pComp->isDeserializer())
735  {
736  val = rVal;
737  for (;;)
738  {
739  tmp = uint8_t(clearUpper(val));
740  // last byte?
741  if (clearUpper(val) == val)
742  break;
743  // write byte
744  tmp ^= 0x80; pComp->Value(tmp);
745  // advance
746  val >>= 7;
747  }
748  // write last byte
749  pComp->Value(tmp);
750  }
751  // reading?
752  else
753  {
754  // read first byte
755  pComp->Value(tmp);
756  val = clearUpper(T(tmp));
757  // read remaining bytes
758  int i = 7; T data = val;
759  while ( uint8_t(data) != tmp )
760  {
761  // read byte
762  pComp->Value(tmp);
763  // add to value
764  data = clearUpper(T(tmp));
765  val = (data << i) | (val & ((1 << i) - 1));
766  // next byte
767  i+=7;
768  }
769  // write
770  rVal = val;
771  }
772  }
virtual bool hasNaming()
Definition: StdCompiler.h:58
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
T clearUpper(T x) const
Definition: StdAdaptors.h:718
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 774 of file StdAdaptors.h.

774 { rVal = nValue; return *this; }

◆ operator==()

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

Definition at line 773 of file StdAdaptors.h.

773 { return rVal == nValue; }

Member Data Documentation

◆ rVal

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

Definition at line 716 of file StdAdaptors.h.


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