client-cpp  0.0.1-SNAPSHOT
UuidGenerator.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 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 <string>
21 #include <sstream>
22 #include <boost/uuid/uuid.hpp>
23 #include <boost/uuid/uuid_io.hpp>
24 #include <boost/uuid/name_generator.hpp>
25 #include <boost/uuid/random_generator.hpp>
26 
27 namespace kaa {
28 
30 public:
31  static std::string generateUuid() {
32  boost::uuids::basic_random_generator<boost::mt19937> gen;
33  boost::uuids::uuid uuid = gen();
34  std::stringstream ss;
35  ss << uuid;
36  return ss.str();
37  }
38 
39  static void generateUuid(std::string& uuid_s) {
40  boost::uuids::basic_random_generator<boost::mt19937> gen;
41  boost::uuids::uuid uuid = gen();
42  std::stringstream ss;
43  ss << uuid;
44  uuid_s.assign(ss.str());
45  }
46 
47  static void generateUuid(std::string& uuid_s, std::string data) {
48  namespace buuids = boost::uuids;
49  buuids::uuid seed;
50  buuids::name_generator generator(seed);
51  buuids::uuid uuid = generator(data);
52 
53  std::stringstream ss;
54  ss << uuid;
55  uuid_s.assign(ss.str());
56  }
57 };
58 
59 } // namespace kaa
60 
61 #endif /* UUIDGENERATOR_HPP_ */
static void generateUuid(std::string &uuid_s)
static void generateUuid(std::string &uuid_s, std::string data)
static std::string generateUuid()