ATLAS Offline Software
Loading...
Searching...
No Matches
v5_Guid.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5// ====================================================================
6//
7// Guid.cpp
8// --------------------------------------------------------------------
9//
10// Package : Persistent Guid to identify objects in the persistent
11// world.
12//
13// Author : Markus Frank
14//
15// ====================================================================
16#define POOL_GUID_CPP 1
17//$Id: v5_Guid.cxx 732100 2016-03-24 05:58:02Z salnikov $
18#include "v5_Guid.h"
19#include <cstdio>
20#include <cstring>
21
22#include "uuid/uuid.h"
23
24static const char* const fmt_Guid =
25 "%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX";
26
27//{ 0x0,0x0,0x0,{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}};
29 clid_null(std::string("00000000-0000-0000-0000-000000000000"));
30
34
37 uuid_t me_;
38 ::uuid_generate_time(me_);
39 unsigned int *d1=(unsigned int*)me_;
40 unsigned short *d2=(unsigned short*)(me_+4);
41 unsigned short *d3=(unsigned short*)(me_+6);
42 guid.Data1 = *d1;
43 guid.Data2 = *d2;
44 guid.Data3 = *d3;
45 for (int i=0; i<8; i++){
46 guid.Data4[i]=me_[i+8];
47 }
48}
49
50const std::string offline_poolCopy_v5::Guid::toString() const {
51 char text[128];
52 ::snprintf(text, 128, fmt_Guid,
53 static_cast<long unsigned int>(Data1),
54 Data2, Data3,
55 Data4[0], Data4[1], Data4[2], Data4[3],
56 Data4[4], Data4[5], Data4[6], Data4[7]);
57 return text;
58}
59
61 // Note: This looks funny, but the specs for sscanf formats say
62 // that the space of a pointer in the ellipsis may only be
63 // integer or short. Hence one has to reserve a bit more space
64 // otherwise the stack gets corrupted.
65 unsigned char d[8];
66 long unsigned int xData1;
67 ::sscanf( source.c_str(), fmt_Guid, &xData1, &Data2, &Data3,
68 &Data4[0], &Data4[1], &Data4[2], &Data4[3], &d[0], &d[1], &d[2], &d[3]);
69 Data1 = xData1;
70 //*(int*)&Data4[4] = *(int*)d;
71 ::memcpy(Data4+4, d, 4);
72 return *this;
73}
74
76 return ::memcmp(&g.Data1, &Data1, 16) < 0;
77}
unsigned short Data2
Definition v5_Guid.h:37
const std::string toString() const
Automatic conversion from string reprentation.
Definition v5_Guid.cxx:50
static const Guid & null()
NULL-Guid: static class method.
Definition v5_Guid.cxx:31
unsigned char Data4[8]
Definition v5_Guid.h:39
bool operator<(const Guid &g) const
Smaller operator.
Definition v5_Guid.cxx:75
static void create(Guid &guid)
Create a new Guid.
Definition v5_Guid.cxx:36
Guid()
Standard constructor (No initialization of data for performance reasons)
Definition v5_Guid.h:42
unsigned short Data3
Definition v5_Guid.h:38
const Guid & fromString(const std::string &s)
Automatic conversion to string representation.
Definition v5_Guid.cxx:60
static const char *const fmt_Guid
Definition v5_Guid.cxx:24
static const offline_poolCopy_v5::Guid clid_null(std::string("00000000-0000-0000-0000-000000000000"))