35 #ifndef _Serialise_H__ 36 #define _Serialise_H__ 48 template <
class T>
inline uint32_t
returnSize(
const T& variable );
50 template <
class T>
inline void loadAndIncrease(
T& variable, uint8_t*& mem );
52 template <
class T>
inline void saveAndIncrease(
const T& variable, uint8_t*& mem );
54 template <
class T>
inline bool checkEquality(
const T& variable, uint8_t* mem );
61 return strlen(variable)+1;
67 std::memcpy(mem, variable, len);
76 variable =
new char[len];
77 std::memcpy(variable, mem, len);
83 return strcmp(variable, (
char*)mem)==0;
92 return sizeof(uint8_t);
97 *(uint8_t*)( &variable ) = *
static_cast<uint8_t*
>(mem);
103 *
static_cast<uint8_t*
>(mem) = *(uint8_t*)( &variable );
109 return *
static_cast<uint8_t*
>(mem) == *(uint8_t*)( &variable );
116 return sizeof(uint8_t);
121 *(uint8_t*)( &variable ) = *
static_cast<uint8_t*
>(mem);
127 *
static_cast<uint8_t*
>(mem) = *(uint8_t*)( &variable );
133 return *
static_cast<uint8_t*
>(mem) == *(uint8_t*)( &variable );
138 template <>
inline uint32_t
returnSize(
const unsigned char& )
140 return sizeof(uint8_t);
145 *(uint8_t*)( &variable ) = *
static_cast<uint8_t*
>(mem);
149 template <>
inline void saveAndIncrease(
const unsigned char& variable, uint8_t*& mem )
151 *
static_cast<uint8_t*
>(mem) = *(uint8_t*)( &variable );
155 template <>
inline bool checkEquality(
const unsigned char& variable, uint8_t* mem )
157 return *
static_cast<uint8_t*
>(mem) == *(uint8_t*)( &variable );
164 return sizeof(int16_t);
169 *(
short*)( &variable ) = *(int16_t*)(mem);
175 *(int16_t*)(mem) = variable;
179 template <>
inline bool checkEquality(
const short& variable, uint8_t* mem )
181 return *(int16_t*)(mem) ==
static_cast<int16_t
>(variable);
186 template <>
inline uint32_t
returnSize(
const unsigned short& )
188 return sizeof(uint16_t);
193 *(
unsigned short*)( &variable ) = *(uint16_t*)(mem);
197 template <>
inline void saveAndIncrease(
const unsigned short& variable, uint8_t*& mem )
199 *(uint16_t*)(mem) = variable;
203 template <>
inline bool checkEquality(
const unsigned short& variable, uint8_t* mem )
205 return *(uint16_t*)(mem) == variable;
212 return sizeof(int32_t);
217 *(
int *)( &variable ) = *(int32_t*)(mem);
223 *(int32_t*)(mem) = variable;
229 return *(int32_t*)(mem) == variable;
234 template <>
inline uint32_t
returnSize(
const unsigned int& )
236 return sizeof(uint32_t);
241 *(
unsigned int*)( &variable ) = *(uint32_t*)(mem);
245 template <>
inline void saveAndIncrease(
const unsigned int& variable, uint8_t*& mem )
247 *(uint32_t*)(mem) = variable;
251 template <>
inline bool checkEquality(
const unsigned int& variable, uint8_t* mem )
253 return *(uint32_t*)(mem) == variable;
260 return sizeof(int32_t);
265 *(
long*)( &variable ) = *(int32_t*)(mem);
271 *(int32_t*)(mem) = variable;
277 return *(int32_t*)(mem) == variable;
282 template <>
inline uint32_t
returnSize(
const unsigned long& )
284 return sizeof(uint32_t);
289 *(
unsigned long*)( &variable ) = *(uint32_t*)(mem);
293 template <>
inline void saveAndIncrease(
const unsigned long& variable, uint8_t*& mem )
295 *(uint32_t*)(mem) = variable;
299 template <>
inline bool checkEquality(
const unsigned long& variable, uint8_t* mem )
301 return *(uint32_t*)(mem) == variable;
308 return sizeof(int64_t);
313 *(
long long*)( &variable ) = *(int64_t*)(mem);
319 *(int64_t*)(mem) = variable;
323 template <>
inline bool checkEquality(
const long long& variable, uint8_t* mem )
325 return *(int64_t*)(mem) == variable;
330 template <>
inline uint32_t
returnSize(
const unsigned long long& )
332 return sizeof(uint64_t);
335 template <>
inline void loadAndIncrease(
unsigned long long& variable, uint8_t*& mem )
337 *(
unsigned long long*)( &variable ) = *(uint64_t*)(mem);
341 template <>
inline void saveAndIncrease(
const unsigned long long& variable, uint8_t*& mem )
343 *(uint64_t*)(mem) = variable;
347 template <>
inline bool checkEquality(
const unsigned long long& variable, uint8_t* mem )
349 return *(uint64_t*)(mem) == variable;
356 return sizeof(uint32_t);
361 *(uint32_t*)( &variable ) = *(uint32_t*)(mem);
367 *(uint32_t*)(mem) = *(uint32_t*)( &variable );
371 template <>
inline bool checkEquality(
const float& variable, uint8_t* mem )
373 return *(uint32_t*)(mem) == *(uint32_t*)( &variable );
380 return sizeof(uint64_t);
385 *(uint64_t*)( &variable ) = *(uint64_t*)(mem);
391 *(uint64_t*)(mem) = *(uint64_t*)( &variable );
395 template <>
inline bool checkEquality(
const double& variable, uint8_t* mem )
397 return *(uint64_t*)(mem) == *(uint64_t*)( &variable );
404 return sizeof(uint64_t);
410 memcpy(&temp, mem,
sizeof(uint64_t));
411 *(
long double*)( &variable ) =
static_cast<long double>(temp);
417 double temp =
static_cast<double>(variable);
418 memcpy(mem, &temp,
sizeof(uint64_t));
422 template <>
inline bool checkEquality(
const long double& variable, uint8_t* mem )
424 double temp =
static_cast<double>(variable);
425 return memcmp(&temp, mem,
sizeof(uint64_t))==0;
432 return variable.length()+1;
437 memcpy(mem, variable.c_str(), variable.length()+1);
438 mem += variable.length()+1;
444 mem += variable.length()+1;
450 return (
const char*)mem==variable;
457 return sizeof(Ogre::Real);
462 Ogre::Real r = variable.valueDegrees();
469 Ogre::Real* r = (Ogre::Real*)mem;
470 (Degree&)variable = *r;
474 template <>
inline bool checkEquality(
const Degree& variable, uint8_t* mem )
476 Ogre::Real* r = (Ogre::Real*)mem;
477 return variable==Degree(*r);
484 return sizeof(Ogre::Real);
489 Ogre::Real r = variable.valueRadians();
496 Ogre::Real* r = (Ogre::Real*)mem;
497 (Radian&)variable = *r;
501 template <>
inline bool checkEquality(
const Radian& variable, uint8_t* mem )
503 Ogre::Real* r = (Ogre::Real*)mem;
504 return variable==Degree(*r);
509 template <>
inline uint32_t
returnSize(
const Vector2& variable )
526 template <>
inline bool checkEquality(
const Vector2& variable, uint8_t* mem )
533 template <>
inline uint32_t
returnSize(
const Vector3& variable )
552 template <>
inline bool checkEquality(
const Vector3& variable, uint8_t* mem )
560 template <>
inline uint32_t
returnSize(
const Vector4& variable )
581 template <>
inline bool checkEquality(
const Vector4& variable, uint8_t* mem )
590 template <>
inline uint32_t
returnSize(
const Quaternion& variable )
611 template <>
inline bool checkEquality(
const Quaternion& variable, uint8_t* mem )
620 template <>
inline uint32_t
returnSize(
const ColourValue& variable )
641 template <>
inline bool checkEquality(
const ColourValue& variable, uint8_t* mem )
672 template <
class T>
inline uint32_t
returnSize(
const std::set<T>& variable )
674 uint32_t tempsize =
sizeof(uint32_t);
675 for(
const T& element : *((std::set<T>*)(&variable)))
680 template <
class T>
inline void saveAndIncrease(
const std::set<T>& variable, uint8_t*& mem )
683 for(
const T& elem : variable )
689 uint32_t nrOfElements = 0;
691 typename std::set<T>::iterator it = variable.begin();
692 for( uint32_t i = 0; i<nrOfElements; ++i )
696 while( it!=variable.end() && *it!=temp )
698 variable.erase(it++);
701 if( it==variable.end() )
703 variable.insert(temp);
708 template <
class T>
inline bool checkEquality(
const std::set<T>& variable, uint8_t* mem )
711 uint32_t nrOfElements;
713 if( variable.size() == nrOfElements )
716 for( uint32_t i=0; i<nrOfElements; ++i )
719 if( variable.find(tempT) == variable.end() )
::std::string string
Definition: gtest-port.h:756
bool checkEquality(T *&variable, uint8_t *mem)
checks whether the objectID of the variable is the same as in the bytestream
Definition: Serialise.h:72
uint32_t returnSize(T *&variable)
returns the size of the objectID needed to synchronise the pointer
Definition: Serialise.h:49
Declaration and implementation of several math-functions, typedefs of some Ogre::Math classes to the ...
mbool is a small helper class that acts like a bool, but keeps track of the number of its state chang...
Definition: mbool.h:58
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
void saveAndIncrease(T *&variable, uint8_t *&mem)
saves the objectID of a pointer into the bytestream and increases the mem pointer ...
Definition: Serialise.h:62
Shared library macros, enums, constants and forward declarations for the util library ...
Declaration and implementation of the orxonox::mbool class.
Definition: InputPrereqs.h:78
void loadAndIncrease(T *&variable, uint8_t *&mem)
reads the objectID of a pointer out of the bytestream and increases the mem pointer ...
Definition: Serialise.h:55