|  | ATLAS Offline Software
    | 
 
 
 
Go to the documentation of this file.
    5 #ifndef PERSISTENTDATAMODEL_GUID_H 
    6 #define PERSISTENTDATAMODEL_GUID_H 
   17 #include <type_traits> 
   33        constexpr 
operator std::string_view()
 const {
 
   34            return std::string_view(
data(), 
size());
 
   36        constexpr std::string_view 
sv()
 const {
return std::string_view(
data(), 
size());}
 
   57    auto operator<=>(
const Guid&) 
const = 
default;
 
   64    constexpr 
void toString(std::span<char, StrLen> buf, 
bool uppercase = 
true) 
const noexcept;
 
   65    constexpr std::
string toString(
bool uppercase = true)
 const{
 
   75    static bool isGuid(std::string_view) noexcept;
 
   82    static const Guid& 
null() noexcept;
 
   97    unsigned char data4(
unsigned int i)
 const { 
if (
i < 8) 
return m_data4[
i]; 
return 0; }
 
  132     return os << static_cast<std::string_view>(
guid);
 
  145    if(std::is_constant_evaluated() && 
std::min(
sv.find_first_not_of(
' '), 
sv.size()) > 0){
 
  146         throw std::runtime_error(
"Remove spaces from GUID");
 
  149    auto last_non_space = 
sv.find_last_not_of(
' ');
 
  150    if (last_non_space == std::string_view::npos) {
 
  153       if(std::is_constant_evaluated() && (
sv.size() - last_non_space - 1)!=0){
 
  154          throw std::runtime_error(
"Remove spaces from GUID");
 
  156       sv.remove_suffix(
sv.size() - last_non_space - 1);
 
  160    if (
sv.size() != 36 ||
 
  161        sv[8] != 
'-' || 
sv[13] != 
'-' || 
sv[18] != 
'-' || 
sv[23] != 
'-') {
 
  163       if(std::is_constant_evaluated()){
 
  164          throw std::runtime_error(
"failed to compile time parse GUID");
 
  170    auto parse_hex = [&success](std::string_view 
part) -> 
unsigned long long {
 
  171       unsigned long long val = 0;
 
  172       for (
char c : 
part) {
 
  174          if (
c >= 
'0' && 
c <= 
'9') {
 
  175             val += 
static_cast<unsigned long long>(
c - 
'0');
 
  176          } 
else if (
c >= 
'a' && 
c <= 
'f') {
 
  177             val += 
static_cast<unsigned long long>(10 + 
c - 
'a');
 
  178          } 
else if (
c >= 
'A' && 
c <= 
'F') {
 
  179             val += 
static_cast<unsigned long long>(10 + 
c - 
'A');
 
  189    m_data1 = 
static_cast<unsigned int>(parse_hex(
sv.substr(0, 8)));
 
  192    m_data2 = 
static_cast<unsigned short>(parse_hex(
sv.substr(9, 4)));
 
  195    m_data3 = 
static_cast<unsigned short>(parse_hex(
sv.substr(14, 4)));
 
  200    for(
int i =0; 
i< 2; 
i++){
 
  201        auto val = parse_hex(
sv.substr(
pos, 2));
 
  207    for(
int i =2; 
i< 8; 
i++){
 
  208        auto val = parse_hex(
sv.substr(
pos, 2));
 
  215       if(std::is_constant_evaluated()){
 
  216          throw std::runtime_error(
"failed to compile time parse GUID");
 
  223 constexpr 
void Guid::toString(std::span<char, 36> buf, 
bool uppercase) 
const noexcept {
 
  225     constexpr 
char lowhex[] = 
"0123456789abcdef";
 
  226     constexpr 
char uphex[]  = 
"0123456789ABCDEF";
 
  227     const char *hex = uppercase ? uphex : lowhex;
 
  230     unsigned int v1 = m_data1;
 
  231     buf[0] = hex[(v1 >> 28) & 0xF];
 
  232     buf[1] = hex[(v1 >> 24) & 0xF];
 
  233     buf[2] = hex[(v1 >> 20) & 0xF];
 
  234     buf[3] = hex[(v1 >> 16) & 0xF];
 
  235     buf[4] = hex[(v1 >> 12) & 0xF];
 
  236     buf[5] = hex[(v1 >> 8) & 0xF];
 
  237     buf[6] = hex[(v1 >> 4) & 0xF];
 
  238     buf[7] = hex[v1 & 0xF];
 
  242     unsigned short v2 = m_data2;
 
  243     buf[9] = hex[(
v2 >> 12) & 0xF];
 
  244     buf[10] = hex[(
v2 >> 8) & 0xF];
 
  245     buf[11] = hex[(
v2 >> 4) & 0xF];
 
  246     buf[12] = hex[
v2 & 0xF];
 
  250     unsigned short v3 = m_data3;
 
  251     buf[14] = hex[(v3 >> 12) & 0xF];
 
  252     buf[15] = hex[(v3 >> 8) & 0xF];
 
  253     buf[16] = hex[(v3 >> 4) & 0xF];
 
  254     buf[17] = hex[v3 & 0xF];
 
  259     for(
int i =0; 
i<2;
i++){
 
  260       unsigned char c = m_data4[
i];
 
  261       buf[
pos] = hex[
c >> 4];
 
  262       buf[
pos+1] = hex[
c & 0xF];
 
  268     for(
int i =2; 
i<8;
i++){
 
  269       unsigned char c = m_data4[
i];
 
  284          static_assert(
sizeof(
Guid) == (
sizeof(
unsigned int) + 
sizeof(
unsigned short)
 
  285                 + 
sizeof(
unsigned short) + 
sizeof(std::array<unsigned char,8>)));
 
  286          const unsigned char* bytes = 
reinterpret_cast<const unsigned char*
>(&
g);
 
  289          constexpr 
size_t fnv_prime = 
sizeof(size_t) == 8 ? 0x100000001b3ULL : 0x01000193U;
 
  290          constexpr 
size_t fnv_offset = 
sizeof(size_t) == 8 ? 0xcbf29ce484222325ULL : 0x811c9dc5U;
 
  292          for (
size_t i = 0; 
i < 
sizeof(
Guid); ++
i) {
 
  
bool operator==(const Guid &) const =default
char data[hepevt_bytes_allocation_ATLAS]
span(T *ptr, std::size_t sz) -> span< T >
A couple needed deduction guides.
constexpr static int stringSize()
constexpr Guid()
Standard constructor.
std::ostream & operator<<(std::ostream &os, const Guid::string &guid)
static GuidGenMethod initGuidGenMethod()
Checks for POOL_GUID_TIME or POOL_GUID_RANDOM env variables.
void setData1(unsigned int data)
Allow modifiers for member data.
constexpr void setToNull() noexcept
constexpr void fromString(std::string_view s)
Automatic conversion from string representation.
constexpr Guid(const char *s)
static constexpr size_t StrLen
static constexpr int stringSize()
Guid(const std::string &s, FallBack)
bool const RAWDATA *ch2 const
constexpr Guid::string to_fixed_string(bool uppercase=true) const
void fromStringFallBack(const std::string &)
Guid(bool assign)
Standard constructor (With possible initialization)
Guid & operator=(const Guid &c)=default
unsigned int data1() const
Allow accessors to member data.
unsigned short data3() const
constexpr Guid(std::string_view s)
Constructor for Guid from string_view.
unsigned short data2() const
static void create(Guid &guid, GuidGenMethod method=GuidGenDefault)
Create a new Guid default method is currently Random, can be changed by param, API or environment.
constexpr void toString(std::span< char, StrLen > buf, bool uppercase=true) const noexcept
Automatic conversion to string representation.
auto operator(const Guid &) const =default
Magic spaceship operator.
size_t operator()(const Guid &g) const noexcept
constexpr std::string_view sv() const
This class provides a encapsulation of a GUID/UUID/CLSID/IID data structure (128 bit number).
A class designed to facilitate exchange of Guid::string objects without additional allocations.
static const GuidGenMethod m_guidGenMethod
Guid(const Guid &c)=default
Copy constructor.
friend std::ostream & operator<<(std::ostream &os, const Guid &rhs)
Extraction operators.
void setData3(unsigned short data)
unsigned char data4(unsigned int i) const
friend bool operator!=(std::string_view str, const Guid &rhs)
Non-equality operator.
void setData4(unsigned char data, unsigned int i)
std::array< unsigned char, 8 > m_data4
void setData2(unsigned short data)
static bool isGuid(std::string_view) noexcept
friend bool operator==(std::string_view str, const Guid &rhs)
Equality operator.
std::size_t hash_value(const SystematicSet &)
Hash function specifically for boost::hash.