CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 // ====================================================================
12 #include "Guid.h"
13 #include <cassert>
14 #include <cstdio>
15 #include <cstring>
16 #include <stdlib.h>
17 #include <string>
18 #include "uuid/uuid.h"
19 
20 namespace edm {
21  static char const* fmt_Guid =
22  "%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX";
23 
24  static int const bufSize = 128;
25 
27  void Guid::init() {
28  uuid_t me_;
29  ::uuid_generate_time(me_);
30  unsigned int* d1 = reinterpret_cast<unsigned int*>(me_);
31  unsigned short* d2 = reinterpret_cast<unsigned short*>(me_+4);
32  unsigned short* d3 = reinterpret_cast<unsigned short*>(me_+6);
33  Data1 = *d1;
34  Data2 = *d2;
35  Data3 = *d3;
36  for(int i = 0; i < 8; ++i){
37  Data4[i] = me_[i + 8];
38  }
39  }
40 
41  std::string const Guid::toString() const {
42  char text[bufSize];
43  ::snprintf(text, sizeof(text),
44  fmt_Guid,
45  Data1, Data2, Data3,
46  Data4[0], Data4[1], Data4[2], Data4[3],
47  Data4[4], Data4[5], Data4[6], Data4[7]);
48  return text;
49  }
50 
51  // fromString is used only in a unit test, so performance is not critical.
53  char const dash = '-';
54  size_t const iSize = 8;
55  size_t const sSize = 4;
56  size_t const cSize = 2;
57  size_t offset = 0;
58  Data1 = strtol(source.substr(offset, iSize).c_str(), 0, 16);
59  offset += iSize;
60  assert(dash == source[offset++]);
61  Data2 = strtol(source.substr(offset, sSize).c_str(), 0, 16);
62  offset += sSize;
63  assert(dash == source[offset++]);
64  Data3 = strtol(source.substr(offset, sSize).c_str(), 0, 16);
65  offset += sSize;
66  assert(dash == source[offset++]);
67  Data4[0] = strtol(source.substr(offset, cSize).c_str(), 0, 16);
68  offset += cSize;
69  Data4[1] = strtol(source.substr(offset, cSize).c_str(), 0, 16);
70  offset += cSize;
71  assert(dash == source[offset++]);
72  Data4[2] = strtol(source.substr(offset, cSize).c_str(), 0, 16);
73  offset += cSize;
74  Data4[3] = strtol(source.substr(offset, cSize).c_str(), 0, 16);
75  offset += cSize;
76  Data4[4] = strtol(source.substr(offset, cSize).c_str(), 0, 16);
77  offset += cSize;
78  Data4[5] = strtol(source.substr(offset, cSize).c_str(), 0, 16);
79  offset += cSize;
80  Data4[6] = strtol(source.substr(offset, cSize).c_str(), 0, 16);
81  offset += cSize;
82  Data4[7] = strtol(source.substr(offset, cSize).c_str(), 0, 16);
83  offset += cSize;
84  assert(source.size() == offset);
85  return *this;
86  }
87 
88  bool Guid::operator<(Guid const& g) const {
89  return ::memcmp(&g.Data1, &Data1, 16) < 0;
90  }
91 }
int i
Definition: DBlmapReader.cc:9
static char const * fmt_Guid
Definition: Guid.cc:21
unsigned short Data2
Definition: Guid.h:26
void init()
initialize a new Guid
Definition: Guid.cc:27
static std::string const source("source")
assert(m_qm.get())
static int const bufSize
Definition: Guid.cc:24
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
unsigned int Data1
Definition: Guid.h:25
std::string const toString() const
Automatic conversion from string reprentation.
Definition: Guid.cc:41
Definition: Guid.h:23
unsigned short Data3
Definition: Guid.h:27
tuple text
Definition: runonSM.py:42
unsigned char Data4[8]
Definition: Guid.h:28
bool operator<(Guid const &g) const
Smaller operator.
Definition: Guid.cc:88
Guid const & fromString(std::string const &s)
Automatic conversion to string representation.
Definition: Guid.cc:52