Dripline-Cpp  v2.10.11
Dripline Implementation in C++
uuid.cc
Go to the documentation of this file.
1 /*
2  * uuid.cc
3  *
4  * Created on: Sep 16, 2015
5  * Author: nsoblath
6  */
7 
8 #define DRIPLINE_API_EXPORTS
9 
10 #include "uuid.hh"
11 
12 #include <boost/uuid/nil_generator.hpp>
13 #include <boost/uuid/random_generator.hpp>
14 #include <boost/uuid/string_generator.hpp>
15 
16 
17 namespace dripline
18 {
20  {
21  static boost::uuids::random_generator t_gen;
22 
23  return t_gen();
24  }
25 
27  {
28  return boost::uuids::nil_uuid();
29  }
30 
31  uuid_t DRIPLINE_API uuid_from_string( const std::string& a_id_str )
32  {
33  static boost::uuids::string_generator t_gen;
34 
35  if( a_id_str.empty() ) return generate_nil_uuid();
36 
37  return t_gen( a_id_str );
38  }
39 
40  uuid_t DRIPLINE_API uuid_from_string( const char* a_id_str )
41  {
42  static boost::uuids::string_generator t_gen;
43 
44  if( strcmp( a_id_str, "" ) == 0 ) return generate_nil_uuid();
45 
46  return t_gen( a_id_str );
47  }
48 
49  uuid_t DRIPLINE_API uuid_from_string( const std::string& a_id_str, bool& a_valid_flag )
50  {
51  a_valid_flag = true;
52  try
53  {
54  return uuid_from_string( a_id_str );
55  }
56  catch(...)
57  {
58  a_valid_flag = false;
59  return generate_nil_uuid();
60  }
61  }
62 
63  uuid_t DRIPLINE_API uuid_from_string( const char* a_id_str, bool& a_valid_flag )
64  {
65  a_valid_flag = true;
66  try
67  {
68  return uuid_from_string( a_id_str );
69  }
70  catch(...)
71  {
72  a_valid_flag = false;
73  return generate_nil_uuid();
74  }
75  }
76 
77 
78  std::string DRIPLINE_API string_from_uuid( const uuid_t& a_id )
79  {
80  return boost::uuids::to_string( a_id );
81  }
82 
83 
84 } /* namespace dripline */
#define DRIPLINE_API
Definition: dripline_api.hh:34
std::string string_from_uuid(const uuid_t &a_id)
Generates a string representation of the provided UUID.
Definition: uuid.cc:78
std::string to_string(op_t an_op)
Gives the human-readable version of a message operation.
uuid_t uuid_from_string(const std::string &a_id_str)
Definition: uuid.cc:31
uuid_t generate_random_uuid()
Generates a UUID containing random numbers (RNG is a Mersenne Twister)
Definition: uuid.cc:19
uuid_t generate_nil_uuid()
Generates a UUID containing all 0s.
Definition: uuid.cc:26
boost::uuids::uuid uuid_t
Universally-unique-identifier type containing 16 hexadecimal characters.
Definition: uuid.hh:26