The Gaudi Framework
master (123e188a)
Toggle main menu visibility
Loading...
Searching...
No Matches
PropertyId.h
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 2022-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
#pragma once
12
13
#include <algorithm>
14
#include <functional>
15
#include <string>
16
#include <string_view>
17
#include <unordered_set>
18
#include <vector>
19
20
namespace
Gaudi::Details
{
28
class
SharedString
final {
29
public
:
32
SharedString
( std::string_view s = {} ) :
m_s
{
SharedString
::
get
( s ) } {}
33
34
operator
std::string()
const
{
return
*
m_s
; }
35
operator
std::string_view()
const
{
return
*
m_s
; }
36
37
bool
operator==
( std::string_view other )
const
{
return
*
m_s
== other; }
38
bool
operator==
(
const
SharedString
& other )
const
{
return
m_s
== other.
m_s
; }
39
40
template
<
typename
T>
41
bool
operator==
(
const
T& other )
const
{
42
return
*
m_s
== other;
43
}
44
45
private
:
46
const
std::string*
m_s
;
47
48
static
const
std::string*
get
( std::string_view s ) {
49
if
( s.empty() ) {
return
{}; }
50
return
&*(
storage
.emplace( s ).first );
51
}
52
53
static
std::unordered_set<std::string>
storage
;
54
};
55
65
class
PropertyId
final {
66
public
:
67
PropertyId
(
const
std::string& s ) :
PropertyId
(
std
::string_view{ s } ) {}
68
PropertyId
( std::string_view s ) {
69
m_hash
= std::hash<std::string_view>()( s );
70
if
( !s.empty() ) {
71
m_chunks
.reserve( std::count( begin( s ), end( s ),
'.'
) + 1 );
72
while
(
true
) {
73
if
(
auto
pos = s.find(
'.'
); pos != std::string_view::npos ) {
74
m_chunks
.emplace_back( s.substr( 0, pos ) );
75
s.remove_prefix( pos + 1 );
76
}
else
{
77
m_chunks
.emplace_back( s );
78
break
;
79
}
80
}
81
}
82
}
83
84
std::string
str
()
const
{
85
auto
it =
m_chunks
.begin();
86
std::string s{ *it++ };
87
while
( it !=
m_chunks
.end() ) {
88
s +=
'.'
;
89
s += *it++;
90
}
91
return
s;
92
}
93
94
operator
std::string()
const
{
return
str
(); }
95
96
std::size_t
hash
() const noexcept {
return
m_hash
; }
97
98
private
:
99
std::vector<SharedString>
m_chunks
;
100
std::size_t
m_hash
;
101
friend
bool
operator==
(
const
PropertyId
& lhs,
const
PropertyId
& rhs );
102
};
103
inline
bool
operator==
(
const
PropertyId
& lhs,
const
PropertyId
& rhs ) {
return
lhs.
m_chunks
== rhs.
m_chunks
; }
104
}
// namespace Gaudi::Details
105
106
template
<>
107
struct
std::hash<
Gaudi
::Details::PropertyId> {
108
std::size_t
operator()
(
Gaudi::Details::PropertyId
const
& s )
const
noexcept
{
return
s.hash(); }
109
};
Gaudi::Details::PropertyId
Helper to record a property identifier as a sequence of SharedString instances.
Definition
PropertyId.h:65
Gaudi::Details::PropertyId::operator==
friend bool operator==(const PropertyId &lhs, const PropertyId &rhs)
Definition
PropertyId.h:103
Gaudi::Details::PropertyId::PropertyId
PropertyId(std::string_view s)
Definition
PropertyId.h:68
Gaudi::Details::PropertyId::hash
std::size_t hash() const noexcept
Definition
PropertyId.h:96
Gaudi::Details::PropertyId::m_chunks
std::vector< SharedString > m_chunks
Definition
PropertyId.h:99
Gaudi::Details::PropertyId::str
std::string str() const
Definition
PropertyId.h:84
Gaudi::Details::PropertyId::PropertyId
PropertyId(const std::string &s)
Definition
PropertyId.h:67
Gaudi::Details::PropertyId::m_hash
std::size_t m_hash
Definition
PropertyId.h:100
Gaudi::Details::SharedString
std::string wrapper for static strings where identical values actually share the memory.
Definition
PropertyId.h:28
Gaudi::Details::SharedString::get
static const std::string * get(std::string_view s)
Definition
PropertyId.h:48
Gaudi::Details::SharedString::operator==
bool operator==(std::string_view other) const
Definition
PropertyId.h:37
Gaudi::Details::SharedString::SharedString
SharedString(std::string_view s={})
Create a new SharedString checking if the value is already in the shared storage otherwise adding it.
Definition
PropertyId.h:32
Gaudi::Details::SharedString::operator==
bool operator==(const SharedString &other) const
Definition
PropertyId.h:38
Gaudi::Details::SharedString::storage
static std::unordered_set< std::string > storage
Definition
PropertyId.h:53
Gaudi::Details::SharedString::m_s
const std::string * m_s
Definition
PropertyId.h:46
Gaudi::Details::SharedString::operator==
bool operator==(const T &other) const
Definition
PropertyId.h:41
Gaudi::Details
Definition
PropertyId.h:20
Gaudi::Details::operator==
bool operator==(const PropertyId &lhs, const PropertyId &rhs)
Definition
PropertyId.h:103
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition
__init__.py:1
std
STL namespace.
std::hash< Gaudi::Details::PropertyId >::operator()
std::size_t operator()(Gaudi::Details::PropertyId const &s) const noexcept
Definition
PropertyId.h:108
GaudiCoreSvc
src
JobOptionsSvc
PropertyId.h
Generated on
for The Gaudi Framework by
1.17.0