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

Constructor & Destructor Documentation

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

Definition at line 695 of file StdAdaptors.h.

695 : rVal(rVal) { }

Member Function Documentation

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

Definition at line 698 of file StdAdaptors.h.

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

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

Here is the caller graph for this function:

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

Definition at line 704 of file StdAdaptors.h.

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

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

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

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

Definition at line 753 of file StdAdaptors.h.

753 { return rVal == nValue; }

Member Data Documentation

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

Definition at line 696 of file StdAdaptors.h.

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


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