Dripline-Cpp  v2.4.2
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  try
38  {
39  return t_gen( a_id_str );
40  }
41  catch(...)
42  {
43  throw;
44  }
45  }
46 
47  uuid_t DRIPLINE_API uuid_from_string( const char* a_id_str )
48  {
49  static boost::uuids::string_generator t_gen;
50 
51  if( strcmp( a_id_str, "" ) == 0 ) return generate_nil_uuid();
52 
53  try
54  {
55  return t_gen( a_id_str );
56  }
57  catch(...)
58  {
59  throw;
60  }
61  }
62 
63  uuid_t DRIPLINE_API uuid_from_string( const std::string& 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  uuid_t DRIPLINE_API uuid_from_string( const char* a_id_str, bool& a_valid_flag )
78  {
79  a_valid_flag = true;
80  try
81  {
82  return uuid_from_string( a_id_str );
83  }
84  catch(...)
85  {
86  a_valid_flag = false;
87  return generate_nil_uuid();
88  }
89  }
90 
91 
92  std::string DRIPLINE_API string_from_uuid( const uuid_t& a_id )
93  {
94  return boost::uuids::to_string( a_id );
95  }
96 
97 
98 } /* namespace dripline */
#define DRIPLINE_API
Definition: dripline_api.hh:34
uuid_t uuid_from_string(const std::string &a_id_str)
Definition: uuid.cc:31
std::string string_from_uuid(const uuid_t &a_id)
Generates a string representation of the provided UUID.
Definition: uuid.cc:92
boost::uuids::uuid uuid_t
Universally-unique-identifier type containing 16 hexadecimal characters.
Definition: uuid.hh:26
std::string to_string(op_t an_op)
Gives the human-readable version of a message operation.
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