Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 3, 2010, 2:24:14 AM (14 years ago)
Author:
scheusso
Message:

std::set<T> is now synchronisable
this was neccessary to synchronise templates (now used in the Level class)
this was neccessary to synchronise lod templates and configuration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/src/libraries/util/Serialise.h

    r6746 r7105  
    3838
    3939#include <cstring>
     40#include <set>
    4041#include "Math.h"
    4142#include "mbool.h"
     
    635636        return checkEquality( (unsigned char&)((mbool&)variable).getMemory(), mem );
    636637    }
     638   
     639    // =========== std::set
     640   
     641    template <class T> inline uint32_t returnSize( const std::set<T>& variable )
     642    {
     643        uint32_t tempsize = sizeof(uint32_t); // for the number of entries
     644        for( typename std::set<T>::iterator it=((std::set<T>*)(&variable))->begin(); it!=((std::set<T>*)(&variable))->end(); ++it)
     645            tempsize += returnSize( *it );
     646        return tempsize;
     647    }
     648   
     649    template <class T> inline void saveAndIncrease(  const std::set<T>& variable, uint8_t*& mem )
     650    {
     651        typename std::set<T>::const_iterator it = variable.begin();
     652        saveAndIncrease( (uint32_t)variable.size(), mem );
     653        for( ; it!=variable.end(); ++it )
     654            saveAndIncrease( *it, mem );
     655    }
     656   
     657    template <class T> inline void loadAndIncrease( const std::set<T>& variable, uint8_t*& mem )
     658    {
     659        uint32_t nrOfElements = 0;
     660        loadAndIncrease( nrOfElements, mem );
     661        typename std::set<T>::const_iterator it = variable.begin();
     662        for( uint32_t i = 0; i<nrOfElements; ++i )
     663        {
     664            T temp;
     665            loadAndIncrease(temp, mem);
     666            while( it!=variable.end() && *it!=temp )
     667            {
     668                ((std::set<T>*)(&variable))->erase(it++);
     669                ++it;
     670            }
     671            if( it==variable.end() )
     672            {
     673                ((std::set<T>*)(&variable))->insert(temp);
     674            }
     675        }
     676    }
     677   
     678    template <class T> inline bool checkEquality( const std::set<T>& variable, uint8_t* mem )
     679    {
     680        uint8_t* temp = mem;
     681        uint32_t nrOfElements;
     682        loadAndIncrease(nrOfElements, mem);
     683        if( variable.size() == nrOfElements )
     684        {
     685            T tempT;
     686            for( uint32_t i=0; i<nrOfElements; ++i )
     687            {
     688                loadAndIncrease(tempT, mem);
     689                if( variable.find(tempT) == variable.end() )
     690                {
     691                    mem = temp;
     692                    return false;
     693                }
     694            }
     695        }
     696        else
     697        {
     698            mem = temp;
     699            return false;
     700        }
     701        return true;
     702    }
    637703}
    638704
Note: See TracChangeset for help on using the changeset viewer.