OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 695 of file StdAdaptors.h.

Constructor & Destructor Documentation

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

Definition at line 697 of file StdAdaptors.h.

697 : rVal(rVal) { }

Member Function Documentation

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

Definition at line 700 of file StdAdaptors.h.

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

701  {
702  const int CLEARBITS = 8 * sizeof(T) - 7;
703  return (x << CLEARBITS) >> CLEARBITS;
704  }

Here is the caller graph for this function:

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

Definition at line 706 of file StdAdaptors.h.

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

707  {
708  // simply write for textual compilers
709  if (pComp->hasNaming())
710  {
711  pComp->Value(rVal);
712  return;
713  }
714  T val; uint8_t tmp;
715  // writing?
716  if (!pComp->isDeserializer())
717  {
718  val = rVal;
719  for (;;)
720  {
721  tmp = uint8_t(clearUpper(val));
722  // last byte?
723  if (clearUpper(val) == val)
724  break;
725  // write byte
726  tmp ^= 0x80; pComp->Value(tmp);
727  // advance
728  val >>= 7;
729  }
730  // write last byte
731  pComp->Value(tmp);
732  }
733  // reading?
734  else
735  {
736  // read first byte
737  pComp->Value(tmp);
738  val = clearUpper(T(tmp));
739  // read remaining bytes
740  int i = 7; T data = val;
741  while ( uint8_t(data) != tmp )
742  {
743  // read byte
744  pComp->Value(tmp);
745  // add to value
746  data = clearUpper(T(tmp));
747  val = (data << i) | (val & ((1 << i) - 1));
748  // next byte
749  i+=7;
750  }
751  // write
752  rVal = val;
753  }
754  }
virtual bool hasNaming()
Definition: StdCompiler.h:58
T clearUpper(T x) const
Definition: StdAdaptors.h:700
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53

Here is the call graph for this function:

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

Definition at line 756 of file StdAdaptors.h.

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

Definition at line 755 of file StdAdaptors.h.

755 { return rVal == nValue; }

Member Data Documentation

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

Definition at line 698 of file StdAdaptors.h.

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


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