blob: b20a1143bd3f131e484785c96af6d46040111b20 (
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
61
62
63
64
65
66
67
68
69
70
|
// **************************************************************************
// * 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>
//boost really should clean a bit up...
#ifdef __MINGW32__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#endif
#include <boost/uuid/uuid_generators.hpp>
#ifdef __MINGW32__
#pragma GCC diagnostic pop
#endif
#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());
}
|