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 <cstdio>
14 #include <cstring>
15 #include "uuid/uuid.h"
16 
17 namespace edm {
18  static char const* fmt_Guid =
19  "%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX";
20 
21  //{ 0x0,0x0,0x0,{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}};
22  static Guid const
23  clid_null(std::string("00000000-0000-0000-0000-000000000000"));
24 
25  Guid const& Guid::null() {
26  return clid_null;
27  }
28 
30  void Guid::create(Guid& guid) {
31  uuid_t me_;
32  ::uuid_generate_time(me_);
33  unsigned int *d1 = reinterpret_cast<unsigned int*>(me_);
34  unsigned short *d2 = reinterpret_cast<unsigned short*>(me_+4);
35  unsigned short *d3 = reinterpret_cast<unsigned short*>(me_+6);
36  guid.Data1 = *d1;
37  guid.Data2 = *d2;
38  guid.Data3 = *d3;
39  for (int i = 0; i < 8; ++i){
40  guid.Data4[i]=me_[i+8];
41  }
42  }
43 
44  std::string const Guid::toString() const {
45  char text[128];
46  ::sprintf(text, fmt_Guid,
47  Data1, Data2, Data3,
48  Data4[0], Data4[1], Data4[2], Data4[3],
49  Data4[4], Data4[5], Data4[6], Data4[7]);
50  return text;
51  }
52 
53  Guid const& Guid::fromString(std::string const& source) {
54  // Note: This looks funny, but the specs for sscanf formats say
55  // that the space of a pointer in the ellipsis may only be
56  // integer or short. Hence one has to reserve a bit more space
57  // otherwise the stack gets corrupted.
58  unsigned char d[8];
59  ::sscanf( source.c_str(), fmt_Guid, &Data1, &Data2, &Data3,
60  &Data4[0], &Data4[1], &Data4[2], &Data4[3], &d[0], &d[1], &d[2], &d[3]);
61  //*(int*)&Data4[4] = *(int*)d;
62  unsigned int * p = reinterpret_cast<unsigned int *>(&Data4[4]);
63  unsigned int const* q = reinterpret_cast<unsigned int const*>(&d[0]);
64  *p = *q;
65  return *this;
66  }
67 
68  bool Guid::operator<(Guid const& g) const {
69  return ::memcmp(&g.Data1, &Data1, 16) < 0;
70  }
71 }
int i
Definition: DBlmapReader.cc:9
static char const * fmt_Guid
Definition: Guid.cc:18
unsigned short Data2
Definition: Guid.h:26
static void create(Guid &guid)
Create a new Guid.
Definition: Guid.cc:30
static Guid const clid_null(std::string("00000000-0000-0000-0000-000000000000"))
tuple d1
Definition: debug_cff.py:7
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:44
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
static Guid const & null()
NULL-Guid: static class method.
Definition: Guid.cc:25
string const
Definition: compareJSON.py:14
bool operator<(Guid const &g) const
Smaller operator.
Definition: Guid.cc:68
Guid const & fromString(std::string const &s)
Automatic conversion to string representation.
Definition: Guid.cc:53