CMS 3D CMS Logo

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 
52  uuid_t tmp;
53  auto err = ::uuid_parse(source.c_str(), tmp);
54  return err == 0;
55  }
56 
57  bool Guid::operator<(Guid const& g) const { return ::uuid_compare(data_, g.data_) < 0; }
58 } // namespace edm
uuid_t data_
Definition: Guid.h:70
static std::string const source("source")
Guid const & fromBinary(std::string const &s)
conversion from binary string representation
Definition: Guid.cc:32
Guid const & fromString(std::string const &s)
conversion from formatted string representation
Definition: Guid.cc:45
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
Definition: Guid.h:26
std::string const toBinary() const
conversion to binary string reprentation
Definition: Guid.cc:30
void init(bool usetime=false)
initialize a new Guid
Definition: Guid.cc:18
std::string const toString() const
conversion to formatted string reprentation
Definition: Guid.cc:38
HLT enums.
static bool isValidString(std::string const &s)
Definition: Guid.cc:51
bool operator<(Guid const &g) const
Smaller operator.
Definition: Guid.cc:57
tmp
align.sh
Definition: createJobs.py:716