xoreos  0.0.5
uuid.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/atomic.h"
26 
27 #include <sstream>
28 
29 #include <boost/uuid/uuid.hpp>
30 #include <boost/uuid/uuid_generators.hpp>
31 #include <boost/uuid/uuid_io.hpp>
32 
33 #include "src/common/uuid.h"
34 
35 namespace Common {
36 
38  std::stringstream ss;
39 
40  ss << boost::uuids::random_generator()();
41 
42  return ss.str();
43 }
44 
45 static boost::atomic<uint32> idNumber(1);
47  return idNumber.fetch_add(1, boost::memory_order_relaxed);
48 }
49 
51  std::string str;
52  str.reserve(20);
53 
54  do {
55  str += "0123456789"[i % 10];
56  i /= 10;
57  } while (i);
58 
59  std::reverse(str.begin(), str.end());
60 
61  return str;
62 }
63 
64 static boost::atomic<uint64> idNumberString(1);
66  return uint64ToString(idNumberString.fetch_add(1, boost::memory_order_relaxed));
67 }
68 
69 } // End of namespace Common
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
UString generateIDNumberString()
Definition: uuid.cpp:65
uint64_t uint64
Definition: types.h:206
Utility functions for generating unique IDs.
static boost::atomic< uint64 > idNumberString(1)
static boost::atomic< uint32 > idNumber(1)
static UString uint64ToString(uint64 i)
Definition: uuid.cpp:50
Helper header to include boost::atomic.
uint32_t uint32
Definition: types.h:204
UString generateIDRandomString()
Definition: uuid.cpp:37
uint32 generateIDNumber()
Definition: uuid.cpp:46