summaryrefslogtreecommitdiff
path: root/shared/guid.cpp
blob: d359c29c379f92b3f5be80e0abbe37e8fbc41623 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html       *
// * Copyright (C) 2008-2010 ZenJu (zhnmju123 AT gmx.de)                    *
// **************************************************************************
//
#include "guid.h"
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <cassert>
#include <algorithm>
#include <vector>

using namespace util;


struct UniqueId::IntData
{
    boost::uuids::uuid nativeRep;
};


UniqueId::UniqueId() : pData(new IntData)
{
    pData->nativeRep = boost::uuids::random_generator()();
}


bool UniqueId::operator==(const UniqueId rhs) const
{
    return pData->nativeRep == rhs.pData->nativeRep;
}


bool UniqueId::operator<(const UniqueId rhs) const
{
    return pData->nativeRep < rhs.pData->nativeRep;
}


UniqueId::UniqueId(wxInputStream& stream) : //read
    pData(new IntData)
{
    std::vector<char> rawData(boost::uuids::uuid::static_size());
    stream.Read(&rawData[0], rawData.size());

    std::copy(rawData.begin(), rawData.end(), pData->nativeRep.begin());
}


void UniqueId::toStream(wxOutputStream& stream) const //write
{
    std::vector<char> rawData;
    std::copy(pData->nativeRep.begin(), pData->nativeRep.end(), std::back_inserter(rawData));

    assert(boost::uuids::uuid::static_size() == rawData.size());

    stream.Write(&rawData[0], rawData.size());
}

bgstack15