Changeset 6192 for code/branches/presentation2/src/libraries/util
- Timestamp:
- Dec 2, 2009, 11:35:24 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/libraries/util/Serialise.h
r6123 r6192 37 37 #include <cstring> 38 38 #include "util/Math.h" 39 #include "util/mbool.h" 39 40 40 41 namespace orxonox{ … … 374 375 double temp; 375 376 memcpy(&temp, mem, sizeof(uint64_t)); 376 *(long double*)( &variable ) = static_cast< constlong double>(temp);377 *(long double*)( &variable ) = static_cast<long double>(temp); 377 378 mem += returnSize( variable ); 378 379 } … … 469 470 return variable==Degree(*r); 470 471 } 472 473 // =========== Vector2 474 475 template <> inline uint32_t returnSize( const Vector2& variable ) 476 { 477 return returnSize( variable.x )+returnSize( variable.y ); 478 } 479 480 template <> inline void saveAndIncrease( const Vector2& variable, uint8_t*& mem ) 481 { 482 saveAndIncrease( variable.x, mem ); 483 saveAndIncrease( variable.y, mem ); 484 } 485 486 template <> inline void loadAndIncrease( const Vector2& variable, uint8_t*& mem ) 487 { 488 loadAndIncrease( variable.x, mem ); 489 loadAndIncrease( variable.y, mem ); 490 } 491 492 template <> inline bool checkEquality( const Vector2& variable, uint8_t* mem ) 493 { 494 return checkEquality(variable.x, mem) && checkEquality(variable.y, mem+returnSize(variable.x)); 495 } 496 497 // =========== Vector3 498 499 template <> inline uint32_t returnSize( const Vector3& variable ) 500 { 501 return returnSize( variable.x )+returnSize( variable.y )+returnSize( variable.z ); 502 } 503 504 template <> inline void saveAndIncrease( const Vector3& variable, uint8_t*& mem ) 505 { 506 saveAndIncrease( variable.x, mem ); 507 saveAndIncrease( variable.y, mem ); 508 saveAndIncrease( variable.z, mem ); 509 } 510 511 template <> inline void loadAndIncrease( const Vector3& variable, uint8_t*& mem ) 512 { 513 loadAndIncrease( variable.x, mem ); 514 loadAndIncrease( variable.y, mem ); 515 loadAndIncrease( variable.z, mem ); 516 } 517 518 template <> inline bool checkEquality( const Vector3& variable, uint8_t* mem ) 519 { 520 return checkEquality(variable.x, mem) && checkEquality(variable.y, mem+returnSize(variable.x)) && 521 checkEquality(variable.z, mem+returnSize(variable.x)+returnSize(variable.y)); 522 } 523 524 // =========== Vector4 525 526 template <> inline uint32_t returnSize( const Vector4& variable ) 527 { 528 return returnSize( variable.w )+returnSize( variable.x )+returnSize( variable.y )+returnSize( variable.z ); 529 } 530 531 template <> inline void saveAndIncrease( const Vector4& variable, uint8_t*& mem ) 532 { 533 saveAndIncrease( variable.w, mem ); 534 saveAndIncrease( variable.x, mem ); 535 saveAndIncrease( variable.y, mem ); 536 saveAndIncrease( variable.z, mem ); 537 } 538 539 template <> inline void loadAndIncrease( const Vector4& variable, uint8_t*& mem ) 540 { 541 loadAndIncrease( variable.w, mem ); 542 loadAndIncrease( variable.x, mem ); 543 loadAndIncrease( variable.y, mem ); 544 loadAndIncrease( variable.z, mem ); 545 } 546 547 template <> inline bool checkEquality( const Vector4& variable, uint8_t* mem ) 548 { 549 return checkEquality(variable.w, mem) && checkEquality(variable.x, mem+returnSize(variable.w)) && 550 checkEquality(variable.y, mem+returnSize(variable.w)+returnSize(variable.x)) && 551 checkEquality(variable.y, mem+returnSize(variable.w)+returnSize(variable.x)+returnSize(variable.y)); 552 } 553 554 // =========== Quaternion 555 556 template <> inline uint32_t returnSize( const Quaternion& variable ) 557 { 558 return returnSize( variable.w )+returnSize( variable.x )+returnSize( variable.y )+returnSize( variable.z ); 559 } 560 561 template <> inline void saveAndIncrease( const Quaternion& variable, uint8_t*& mem ) 562 { 563 saveAndIncrease( variable.w, mem ); 564 saveAndIncrease( variable.x, mem ); 565 saveAndIncrease( variable.y, mem ); 566 saveAndIncrease( variable.z, mem ); 567 } 568 569 template <> inline void loadAndIncrease( const Quaternion& variable, uint8_t*& mem ) 570 { 571 loadAndIncrease( variable.w, mem ); 572 loadAndIncrease( variable.x, mem ); 573 loadAndIncrease( variable.y, mem ); 574 loadAndIncrease( variable.z, mem ); 575 } 576 577 template <> inline bool checkEquality( const Quaternion& variable, uint8_t* mem ) 578 { 579 return checkEquality(variable.w, mem) && checkEquality(variable.x, mem+returnSize(variable.w)) && 580 checkEquality(variable.y, mem+returnSize(variable.w)+returnSize(variable.x)) && 581 checkEquality(variable.y, mem+returnSize(variable.w)+returnSize(variable.x)+returnSize(variable.y)); 582 } 583 584 // =========== ColourValue 585 586 template <> inline uint32_t returnSize( const ColourValue& variable ) 587 { 588 return returnSize( variable.r )+returnSize( variable.g )+returnSize( variable.b )+returnSize( variable.a ); 589 } 590 591 template <> inline void saveAndIncrease( const ColourValue& variable, uint8_t*& mem ) 592 { 593 saveAndIncrease( variable.r, mem ); 594 saveAndIncrease( variable.g, mem ); 595 saveAndIncrease( variable.b, mem ); 596 saveAndIncrease( variable.a, mem ); 597 } 598 599 template <> inline void loadAndIncrease( const ColourValue& variable, uint8_t*& mem ) 600 { 601 loadAndIncrease( variable.r, mem ); 602 loadAndIncrease( variable.g, mem ); 603 loadAndIncrease( variable.b, mem ); 604 loadAndIncrease( variable.a, mem ); 605 } 606 607 template <> inline bool checkEquality( const ColourValue& variable, uint8_t* mem ) 608 { 609 return checkEquality(variable.r, mem) && checkEquality(variable.g, mem+returnSize(variable.r)) && 610 checkEquality(variable.b, mem+returnSize(variable.r)+returnSize(variable.g)) && 611 checkEquality(variable.a, mem+returnSize(variable.r)+returnSize(variable.g)+returnSize(variable.b)); 612 } 613 614 // =========== mbool 615 616 template <> inline uint32_t returnSize( const mbool& variable ) 617 { 618 return returnSize( (unsigned char&)((mbool&)variable).getMemory() ); 619 } 620 621 template <> inline void saveAndIncrease( const mbool& variable, uint8_t*& mem ) 622 { 623 saveAndIncrease( (unsigned char&)((mbool&)variable).getMemory(), mem ); 624 } 625 626 template <> inline void loadAndIncrease( const mbool& variable, uint8_t*& mem ) 627 { 628 loadAndIncrease( (unsigned char&)((mbool&)variable).getMemory(), mem ); 629 } 630 631 template <> inline bool checkEquality( const mbool& variable, uint8_t* mem ) 632 { 633 return checkEquality( (unsigned char&)((mbool&)variable).getMemory(), mem ); 634 } 471 635 } 472 636
Note: See TracChangeset
for help on using the changeset viewer.