Changeset 11083 for code/trunk/src/libraries/util
- Timestamp:
- Jan 21, 2016, 1:59:04 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/util/Serialise.h
r11071 r11083 48 48 template <class T> inline uint32_t returnSize( const T& variable ); 49 49 /** @brief loads the value of a variable out of the bytestream and increases the mem pointer */ 50 template <class T> inline void loadAndIncrease( constT& variable, uint8_t*& mem );50 template <class T> inline void loadAndIncrease( T& variable, uint8_t*& mem ); 51 51 /** @brief saves the value of a variable into the bytestream and increases the mem pointer */ 52 52 template <class T> inline void saveAndIncrease( const T& variable, uint8_t*& mem ); … … 57 57 // =========== char* 58 58 59 inline uint32_t returnSize( char*& variable )59 inline uint32_t returnSize(const char*& variable ) 60 60 { 61 61 return strlen(variable)+1; 62 62 } 63 63 64 inline void saveAndIncrease( char*& variable, uint8_t*& mem )64 inline void saveAndIncrease(const char*& variable, uint8_t*& mem ) 65 65 { 66 strcpy((char*)mem, variable); 67 mem += returnSize(variable); 66 uint32_t len = returnSize(variable); 67 std::memcpy(mem, variable, len); 68 mem += len; 68 69 } 69 70 … … 72 73 if( variable ) 73 74 delete variable; 74 uint32_t len = strlen((char*)mem)+1;75 uint32_t len = returnSize((const char*&)mem); 75 76 variable = new char[len]; 76 st rcpy((char*)variable, (char*)mem);77 std::memcpy(variable, mem, len); 77 78 mem += len; 78 79 } … … 92 93 } 93 94 94 template <> inline void loadAndIncrease( constbool& variable, uint8_t*& mem )95 template <> inline void loadAndIncrease( bool& variable, uint8_t*& mem ) 95 96 { 96 97 *(uint8_t*)( &variable ) = *static_cast<uint8_t*>(mem); … … 116 117 } 117 118 118 template <> inline void loadAndIncrease( c onst char& variable, uint8_t*& mem )119 template <> inline void loadAndIncrease( char& variable, uint8_t*& mem ) 119 120 { 120 121 *(uint8_t*)( &variable ) = *static_cast<uint8_t*>(mem); … … 140 141 } 141 142 142 template <> inline void loadAndIncrease( constunsigned char& variable, uint8_t*& mem )143 template <> inline void loadAndIncrease( unsigned char& variable, uint8_t*& mem ) 143 144 { 144 145 *(uint8_t*)( &variable ) = *static_cast<uint8_t*>(mem); … … 164 165 } 165 166 166 template <> inline void loadAndIncrease( constshort& variable, uint8_t*& mem )167 template <> inline void loadAndIncrease( short& variable, uint8_t*& mem ) 167 168 { 168 169 *(short*)( &variable ) = *(int16_t*)(mem); … … 188 189 } 189 190 190 template <> inline void loadAndIncrease( constunsigned short& variable, uint8_t*& mem )191 template <> inline void loadAndIncrease( unsigned short& variable, uint8_t*& mem ) 191 192 { 192 193 *(unsigned short*)( &variable ) = *(uint16_t*)(mem); … … 212 213 } 213 214 214 template <> inline void loadAndIncrease( constint& variable, uint8_t*& mem )215 template <> inline void loadAndIncrease( int& variable, uint8_t*& mem ) 215 216 { 216 217 *(int *)( &variable ) = *(int32_t*)(mem); … … 236 237 } 237 238 238 template <> inline void loadAndIncrease( constunsigned int& variable, uint8_t*& mem )239 template <> inline void loadAndIncrease( unsigned int& variable, uint8_t*& mem ) 239 240 { 240 241 *(unsigned int*)( &variable ) = *(uint32_t*)(mem); … … 260 261 } 261 262 262 template <> inline void loadAndIncrease( constlong& variable, uint8_t*& mem )263 template <> inline void loadAndIncrease( long& variable, uint8_t*& mem ) 263 264 { 264 265 *(long*)( &variable ) = *(int32_t*)(mem); … … 284 285 } 285 286 286 template <> inline void loadAndIncrease( constunsigned long& variable, uint8_t*& mem )287 template <> inline void loadAndIncrease( unsigned long& variable, uint8_t*& mem ) 287 288 { 288 289 *(unsigned long*)( &variable ) = *(uint32_t*)(mem); … … 308 309 } 309 310 310 template <> inline void loadAndIncrease( constlong long& variable, uint8_t*& mem )311 template <> inline void loadAndIncrease( long long& variable, uint8_t*& mem ) 311 312 { 312 313 *(long long*)( &variable ) = *(int64_t*)(mem); … … 332 333 } 333 334 334 template <> inline void loadAndIncrease( constunsigned long long& variable, uint8_t*& mem )335 template <> inline void loadAndIncrease( unsigned long long& variable, uint8_t*& mem ) 335 336 { 336 337 *(unsigned long long*)( &variable ) = *(uint64_t*)(mem); … … 356 357 } 357 358 358 template <> inline void loadAndIncrease( constfloat& variable, uint8_t*& mem )359 template <> inline void loadAndIncrease( float& variable, uint8_t*& mem ) 359 360 { 360 361 *(uint32_t*)( &variable ) = *(uint32_t*)(mem); … … 380 381 } 381 382 382 template <> inline void loadAndIncrease( constdouble& variable, uint8_t*& mem )383 template <> inline void loadAndIncrease( double& variable, uint8_t*& mem ) 383 384 { 384 385 *(uint64_t*)( &variable ) = *(uint64_t*)(mem); … … 404 405 } 405 406 406 template <> inline void loadAndIncrease( constlong double& variable, uint8_t*& mem )407 template <> inline void loadAndIncrease( long double& variable, uint8_t*& mem ) 407 408 { 408 409 double temp; … … 438 439 } 439 440 440 template <> inline void loadAndIncrease( conststd::string& variable, uint8_t*& mem )441 template <> inline void loadAndIncrease( std::string& variable, uint8_t*& mem ) 441 442 { 442 443 *(std::string*)( &variable ) = (const char *)mem; … … 464 465 } 465 466 466 template <> inline void loadAndIncrease( constDegree& variable, uint8_t*& mem )467 template <> inline void loadAndIncrease( Degree& variable, uint8_t*& mem ) 467 468 { 468 469 Ogre::Real* r = (Ogre::Real*)mem; … … 491 492 } 492 493 493 template <> inline void loadAndIncrease( constRadian& variable, uint8_t*& mem )494 template <> inline void loadAndIncrease( Radian& variable, uint8_t*& mem ) 494 495 { 495 496 Ogre::Real* r = (Ogre::Real*)mem; … … 517 518 } 518 519 519 template <> inline void loadAndIncrease( constVector2& variable, uint8_t*& mem )520 template <> inline void loadAndIncrease( Vector2& variable, uint8_t*& mem ) 520 521 { 521 522 loadAndIncrease( variable.x, mem ); … … 542 543 } 543 544 544 template <> inline void loadAndIncrease( constVector3& variable, uint8_t*& mem )545 template <> inline void loadAndIncrease( Vector3& variable, uint8_t*& mem ) 545 546 { 546 547 loadAndIncrease( variable.x, mem ); … … 570 571 } 571 572 572 template <> inline void loadAndIncrease( constVector4& variable, uint8_t*& mem )573 template <> inline void loadAndIncrease( Vector4& variable, uint8_t*& mem ) 573 574 { 574 575 loadAndIncrease( variable.w, mem ); … … 600 601 } 601 602 602 template <> inline void loadAndIncrease( constQuaternion& variable, uint8_t*& mem )603 template <> inline void loadAndIncrease( Quaternion& variable, uint8_t*& mem ) 603 604 { 604 605 loadAndIncrease( variable.w, mem ); … … 630 631 } 631 632 632 template <> inline void loadAndIncrease( constColourValue& variable, uint8_t*& mem )633 template <> inline void loadAndIncrease( ColourValue& variable, uint8_t*& mem ) 633 634 { 634 635 loadAndIncrease( variable.r, mem ); … … 657 658 } 658 659 659 template <> inline void loadAndIncrease( constmbool& variable, uint8_t*& mem )660 template <> inline void loadAndIncrease( mbool& variable, uint8_t*& mem ) 660 661 { 661 662 loadAndIncrease( (unsigned char&)((mbool&)variable).getMemory(), mem );
Note: See TracChangeset
for help on using the changeset viewer.