CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Guid.cc
Go to the documentation of this file.
1 // ====================================================================
2 //
3 // Guid.cpp
4 // --------------------------------------------------------------------
5 //
6 // Package : Persistent Guid to identify objects in the persistent
7 // world.
8 //
9 // Author : Markus Frank
10 //
11 // ====================================================================
13 #include <cstring>
14 #include <cassert>
15 
16 namespace edm {
18  void Guid::init(bool usetime) {
19  if (usetime) {
20  ::uuid_generate_time(data_);
21  } else {
22  // uuid_generate() defaults to uuid_generate_random() if /dev/urandom
23  // is available; if /dev/urandom is not available, then it is better
24  // to let uuid_generate() choose the best fallback rather than forcing
25  // use of an inferior source of randomness
26  ::uuid_generate(data_);
27  }
28  }
29 
30  std::string const Guid::toBinary() const { return std::string(reinterpret_cast<const char*>(data_), sizeof(data_)); }
31 
33  assert(source.size() == sizeof(data_));
34  std::memcpy(data_, source.data(), sizeof(data_));
35  return *this;
36  }
37 
38  std::string const Guid::toString() const {
39  char out[UUID_STR_LEN];
40  ::uuid_unparse(data_, out);
41  return std::string(out);
42  }
43 
44  // fromString is used only in a unit test, so performance is not critical.
46  auto err = ::uuid_parse(source.c_str(), data_);
47  assert(err == 0);
48  return *this;
49  }
50 
51  bool Guid::operator<(Guid const& g) const { return ::uuid_compare(data_, g.data_) < 0; }
52 } // namespace edm
uuid_t data_
Definition: Guid.h:68
static std::string const source("source")
assert(be >=bs)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
std::string const toString() const
conversion to formatted string reprentation
Definition: Guid.cc:38
Guid const & fromBinary(std::string const &s)
conversion from binary string representation
Definition: Guid.cc:32
Definition: Guid.h:26
void init(bool usetime=false)
initialize a new Guid
Definition: Guid.cc:18
std::string const toBinary() const
conversion to binary string reprentation
Definition: Guid.cc:30
bool operator<(Guid const &g) const
Smaller operator.
Definition: Guid.cc:51
Guid const & fromString(std::string const &s)
conversion from formatted string representation
Definition: Guid.cc:45