diff options
Diffstat (limited to 'shared/guid.cpp')
-rw-r--r-- | shared/guid.cpp | 102 |
1 files changed, 21 insertions, 81 deletions
diff --git a/shared/guid.cpp b/shared/guid.cpp index 785ab200..7a2ec68f 100644 --- a/shared/guid.cpp +++ b/shared/guid.cpp @@ -5,116 +5,56 @@ // ************************************************************************** // #include "guid.h" -#include <stdexcept> - -#ifdef FFS_WIN -#include "Objbase.h" - -#elif defined FFS_LINUX -#include "ossp_uuid/uuid++.hh" -#endif +#include <boost/uuid/uuid.hpp> +#include <boost/uuid/uuid_generators.hpp> +#include <cassert> +#include <algorithm> +#include <vector> using namespace Utility; - - -#ifdef FFS_WIN + + struct UniqueId::IntData -{ - GUID nativeRep; +{ + boost::uuids::uuid nativeRep; }; -#elif defined FFS_LINUX -struct UniqueId::IntData -{ - uuid nativeRep; //ossp uuid -}; -#endif - + -UniqueId::UniqueId() : - pData(new IntData) +UniqueId::UniqueId() : pData(new IntData) { -#ifdef FFS_WIN - if (FAILED(::CoCreateGuid(&pData->nativeRep))) - throw std::runtime_error("Error creating UUID!"); -#elif defined FFS_LINUX - pData->nativeRep.make(UUID_MAKE_V1); -#endif + pData->nativeRep = boost::uuids::random_generator()(); } bool UniqueId::operator==(const UniqueId rhs) const { -#ifdef FFS_WIN - //return ::IsEqualGUID(pData->nativeRep, rhs.pData->nativeRep); -> harmonize with operator< - - const GUID& guidL = pData->nativeRep; - const GUID& guidR = rhs.pData->nativeRep; - - return guidL.Data1 == guidR.Data1 && - guidL.Data2 == guidR.Data2 && - guidL.Data3 == guidR.Data3 && - ::memcmp(guidL.Data4, guidR.Data4, sizeof(guidR.Data4)) == 0; -#elif defined FFS_LINUX return pData->nativeRep == rhs.pData->nativeRep; -#endif } bool UniqueId::operator<(const UniqueId rhs) const { -#ifdef FFS_WIN - const GUID& guidL = pData->nativeRep; - const GUID& guidR = rhs.pData->nativeRep; - - if (guidL.Data1 != guidR.Data1) - return guidL.Data1 < guidR.Data1; - if (guidL.Data2 != guidR.Data2) - return guidL.Data2 < guidR.Data2; - if (guidL.Data3 != guidR.Data3) - return guidL.Data3 < guidR.Data3; - - return ::memcmp(guidL.Data4, guidR.Data4, sizeof(guidR.Data4)) < 0; -#elif defined FFS_LINUX return pData->nativeRep < rhs.pData->nativeRep; -#endif -} +} UniqueId::UniqueId(wxInputStream& stream) : //read pData(new IntData) { -#ifdef FFS_WIN - stream.Read(&pData->nativeRep, sizeof(GUID)); -#elif defined FFS_LINUX - char buffer[UUID_LEN_BIN] = {0}; - stream.Read(buffer, sizeof(buffer)); + std::vector<char> rawData(boost::uuids::uuid::static_size()); + stream.Read(&rawData[0], rawData.size()); - pData->nativeRep.import(static_cast<void*>(buffer)); //warning: import is overloaded with void*/char*! -#endif + std::copy(rawData.begin(), rawData.end(), pData->nativeRep.begin()); } -#ifdef FFS_LINUX -struct MallocDeleter -{ - void operator() (void* ptr) - { - free(ptr); - } -}; -#endif - - void UniqueId::toStream(wxOutputStream& stream) const //write { -#ifdef FFS_WIN - stream.Write(&pData->nativeRep, sizeof(GUID)); -#elif defined FFS_LINUX - boost::shared_ptr<const void> buffer(pData->nativeRep.binary(), //caller has to "free" memory (of size UUID_LEN_BIN) - MallocDeleter()); + std::vector<char> rawData; + std::copy(pData->nativeRep.begin(), pData->nativeRep.end(), std::back_inserter(rawData)); - stream.Write(buffer.get(), UUID_LEN_BIN); -#endif -} + assert(boost::uuids::uuid::static_size() == rawData.size()); + stream.Write(&rawData[0], rawData.size()); +} |