client-cpp  0.10.0
UuidGenerator.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2016 CyberVision, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef UUIDGENERATOR_HPP_
18 #define UUIDGENERATOR_HPP_
19 
20 #include "kaa/KaaDefaults.hpp"
21 
22 #include <string>
23 #include <sstream>
24 #include <boost/uuid/uuid.hpp>
25 #include <boost/uuid/uuid_io.hpp>
26 #include <boost/uuid/name_generator.hpp>
27 #include <boost/uuid/random_generator.hpp>
28 
29 namespace kaa {
30 
32 public:
33  static std::string generateUuid() {
34  boost::uuids::basic_random_generator<boost::mt19937> gen;
35  boost::uuids::uuid uuid = gen();
36  std::stringstream ss;
37  ss << uuid;
38  return ss.str();
39  }
40 
41  static std::int32_t generateRandomInt() {
42  boost::uuids::basic_random_generator<boost::mt19937> gen;
43  boost::uuids::uuid uuid = gen();
44  std::int32_t rand = (uuid.data[12] << 24) | (uuid.data[13] << 16)
45  | (uuid.data[14] << 8) | (uuid.data[15]);
46  return rand;
47  }
48 
49  static void generateUuid(std::string& uuid_s) {
50  boost::uuids::basic_random_generator<boost::mt19937> gen;
51  boost::uuids::uuid uuid = gen();
52  std::stringstream ss;
53  ss << uuid;
54  uuid_s.assign(ss.str());
55  }
56 
57  static void generateUuid(std::string& uuid_s, std::string data) {
58  namespace buuids = boost::uuids;
59  buuids::uuid seed;
60  buuids::name_generator generator(seed);
61  buuids::uuid uuid = generator(data);
62 
63  std::stringstream ss;
64  ss << uuid;
65  uuid_s.assign(ss.str());
66  }
67 };
68 
69 } // namespace kaa
70 
71 #endif /* UUIDGENERATOR_HPP_ */
static std::int32_t generateRandomInt()
static void generateUuid(std::string &uuid_s)
static void generateUuid(std::string &uuid_s, std::string data)
static std::string generateUuid()