Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 28, 2009, 11:19:06 PM (15 years ago)
Author:
scheusso
Message:
  • moved serialise functions from SynchronisableVariableSpecialisation.cc

to util/Serialise.h

  • made MultiType serialisable (use functions importData/exportData or

operator << / >> )

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/netp2/src/util/MultiTypeValue.h

    r2171 r2861  
    4040#include "MathConvert.h"
    4141#include "MultiType.h"
     42#include "Serialise.h"
     43#include <cassert>
    4244
    4345namespace orxonox
     
    147149        /** @brief Puts the current value on the stream */
    148150        inline void toString(std::ostream& outstream) const { outstream << this->value_; }
     151       
     152        /** @brief loads data from the bytestream (mem) into the MT and increases the bytestream pointer by the size of the data */
     153        inline void importData( uint8_t*& mem )         { loadAndIncrease( /*(const T&)*/this->value_, mem ); }
     154        /** @brief saves data from the MT into the bytestream (mem) and increases the bytestream pointer by the size of the data */
     155        inline void exportData( uint8_t*& mem ) const   { saveAndIncrease( /*(const T&)*/this->value_, mem ); }
     156        /** @brief returns the size of the data that would be saved by exportData */
     157        inline uint8_t getSize() const { return returnSize( this->value_ ); }
    149158
    150159        T value_; //!< The stored value
    151160    };
     161   
     162    // Import / Export specialisation
     163    // ColourValue
     164    template <> inline void MT_Value<ColourValue>::importData( uint8_t*& mem )
     165    {
     166        loadAndIncrease( this->value_.r, mem );
     167        loadAndIncrease( this->value_.g, mem );
     168        loadAndIncrease( this->value_.b, mem );
     169        loadAndIncrease( this->value_.a, mem );
     170    }
     171    template <> inline void MT_Value<ColourValue>::exportData( uint8_t*& mem ) const
     172    {
     173        saveAndIncrease( this->value_.r, mem );
     174        saveAndIncrease( this->value_.g, mem );
     175        saveAndIncrease( this->value_.b, mem );
     176        saveAndIncrease( this->value_.a, mem );
     177    }
     178    template <> inline uint8_t MT_Value<ColourValue>::getSize() const
     179    {
     180        return 4*returnSize(this->value_.r);
     181    }
     182    // Ogre::Quaternion
     183    template <> inline void MT_Value<Ogre::Quaternion>::importData( uint8_t*& mem )
     184    {
     185        loadAndIncrease( this->value_.x, mem );
     186        loadAndIncrease( this->value_.y, mem );
     187        loadAndIncrease( this->value_.z, mem );
     188        loadAndIncrease( this->value_.w, mem );
     189    }
     190    template <> inline void MT_Value<Ogre::Quaternion>::exportData( uint8_t*& mem ) const
     191    {
     192        saveAndIncrease( this->value_.x, mem );
     193        saveAndIncrease( this->value_.y, mem );
     194        saveAndIncrease( this->value_.z, mem );
     195        saveAndIncrease( this->value_.w, mem );
     196    }template <> inline uint8_t MT_Value<Ogre::Quaternion>::getSize() const
     197    {
     198        return 4*returnSize(this->value_.x);
     199    }
     200    // Ogre::Vector2
     201    template <> inline void MT_Value<Ogre::Vector2>::importData( uint8_t*& mem )
     202    {
     203        loadAndIncrease( this->value_.x, mem );
     204        loadAndIncrease( this->value_.y, mem );
     205    }
     206    template <> inline void MT_Value<Ogre::Vector2>::exportData( uint8_t*& mem ) const
     207    {
     208        saveAndIncrease( this->value_.x, mem );
     209        saveAndIncrease( this->value_.y, mem );
     210    }
     211    template <> inline uint8_t MT_Value<Ogre::Vector2>::getSize() const
     212    {
     213        return 2*returnSize(this->value_.x);
     214    }
     215    // Ogre::Vector3
     216    template <> inline void MT_Value<Ogre::Vector3>::importData( uint8_t*& mem )
     217    {
     218        loadAndIncrease( this->value_.x, mem );
     219        loadAndIncrease( this->value_.y, mem );
     220        loadAndIncrease( this->value_.z, mem );
     221    }
     222    template <> inline void MT_Value<Ogre::Vector3>::exportData( uint8_t*& mem ) const
     223    {
     224        saveAndIncrease( this->value_.x, mem );
     225        saveAndIncrease( this->value_.y, mem );
     226        saveAndIncrease( this->value_.z, mem );
     227    }
     228    template <> inline uint8_t MT_Value<Ogre::Vector3>::getSize() const
     229    {
     230        return 3*returnSize(this->value_.x);
     231    }
     232    // Ogre::Vector4
     233    template <> inline void MT_Value<Ogre::Vector4>::importData( uint8_t*& mem )
     234    {
     235        loadAndIncrease( this->value_.x, mem );
     236        loadAndIncrease( this->value_.y, mem );
     237        loadAndIncrease( this->value_.z, mem );
     238        loadAndIncrease( this->value_.w, mem );
     239    }
     240    template <> inline void MT_Value<Ogre::Vector4>::exportData( uint8_t*& mem ) const
     241    {
     242        saveAndIncrease( this->value_.x, mem );
     243        saveAndIncrease( this->value_.y, mem );
     244        saveAndIncrease( this->value_.z, mem );
     245        saveAndIncrease( this->value_.w, mem );
     246    }
     247    template <> inline uint8_t MT_Value<Ogre::Vector4>::getSize() const
     248    {
     249        return 4*returnSize(this->value_.x);
     250    }
     251    template <> inline void MT_Value<void*>::importData( uint8_t*& mem )
     252    {
     253        assert(0);
     254    }
     255    template <> inline void MT_Value<void*>::exportData( uint8_t*& mem ) const
     256    {
     257        assert(0);
     258    }
     259    template <> inline uint8_t MT_Value<void*>::getSize() const
     260    {
     261        assert(0); return 0;
     262    }
    152263}
    153264
Note: See TracChangeset for help on using the changeset viewer.