The Gaudi Framework
master (da3d77e1)
SerializeSTL.h
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-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
\***********************************************************************************/
22
#ifndef GAUDIKERNEL_SERIALIZESTL_H_
23
#define GAUDIKERNEL_SERIALIZESTL_H_
24
25
#include <
GaudiKernel/HashMap.h
>
26
#include <
GaudiKernel/Map.h
>
27
#include <array>
28
#include <list>
29
#include <map>
30
#include <ostream>
31
#include <set>
32
#include <unordered_set>
33
#include <utility>
34
#include <vector>
35
36
namespace
GaudiUtils
{
38
template
<
class
T1,
class
T2>
39
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::pair<T1, T2>
& p );
40
42
template
<
typename
... Args>
43
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::tuple<Args...>
& tuple );
44
46
template
<
class
T,
class
ALLOC>
47
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::vector<T, ALLOC>
&
v
);
48
50
template
<
class
T, std::
size_t
N>
51
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::array<T, N>
&
v
);
52
54
template
<
class
T,
class
ALLOC>
55
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::list<T, ALLOC>
&
l
);
56
58
template
<
class
T,
class
ALLOC>
59
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::set<T, ALLOC>
&
l
);
60
62
template
<
class
T,
class
ALLOC>
63
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::unordered_set<T, ALLOC>
&
l
);
64
66
template
<
class
T1,
class
T2,
class
COMP,
class
ALLOC>
67
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::map<T1, T2, COMP, ALLOC>
&
m
);
68
70
template
<
class
K,
class
T,
class
M>
71
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
GaudiUtils::Map<K, T, M>
&
m
);
72
74
template
<
class
K,
class
T,
class
H,
class
M>
75
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
GaudiUtils::HashMap<K, T, H, M>
&
m
);
76
77
namespace
details
{
78
79
struct
IdentityOutputter
{
80
template
<
typename
T>
81
std::ostream
&
operator()
(
std::ostream
& os, T&&
t
)
const
{
82
return
os << std::forward<T>(
t
);
83
}
84
};
85
86
template
<
typename
Stream,
typename
Iterator,
typename
Separator,
typename
OutputElement = IdentityOutputter>
87
Stream&
ostream_joiner
( Stream& os,
Iterator
first,
Iterator
last, Separator sep,
88
OutputElement
output
= OutputElement{} ) {
89
if
( first != last )
output
( os, *first++ );
90
while
( first != last )
output
( os << sep, *first++ );
91
return
os;
92
}
93
94
template
<
typename
Stream,
typename
Container,
typename
Separator,
typename
OutputElement = IdentityOutputter>
95
Stream&
ostream_joiner
( Stream& os,
const
Container&
c
, Separator sep, OutputElement
output
= OutputElement{} ) {
96
using
std::begin
,
std::end
;
97
return
ostream_joiner
( os,
begin
(
c
),
end
(
c
), sep,
output
);
98
}
99
}
// namespace details
100
101
template
<
class
T1,
class
T2>
102
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::pair<T1, T2>
& p ) {
103
return
s
<<
'('
<< p.first <<
", "
<< p.second <<
')'
;
104
}
105
106
template
<
typename
... Args>
107
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::tuple<Args...>
& tup ) {
108
return
std::apply(
109
[&
s
](
const
auto
&... a ) -> decltype(
auto
) {
110
unsigned
n
=
sizeof
...( a );
111
if
(
n
== 1 )
n
= 2;
// special case in python...
112
s
<<
" ("
;
113
( (
s
<<
" "
<< a << ( --
n
== 0 ?
""
:
","
) ), ... );
114
return
s
<<
" )"
;
115
},
116
tup );
117
}
118
119
template
<
class
T,
class
ALLOC>
120
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::vector<T, ALLOC>
&
v
) {
121
return
details::ostream_joiner
(
s
<<
'['
,
v
,
", "
) <<
']'
;
122
}
123
124
template
<
class
T, std::
size_t
N>
125
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::array<T, N>
&
v
) {
126
return
details::ostream_joiner
(
s
<<
'['
,
v
,
", "
) <<
']'
;
127
}
128
129
template
<
class
T,
class
ALLOC>
130
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::list<T, ALLOC>
&
l
) {
131
return
details::ostream_joiner
(
s
<<
'['
,
l
,
", "
) <<
']'
;
132
}
133
134
template
<
class
T,
class
ALLOC>
135
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::set<T, ALLOC>
&
l
) {
136
return
details::ostream_joiner
(
s
<<
'['
,
l
,
", "
) <<
']'
;
137
}
138
139
template
<
class
T,
class
ALLOC>
140
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::unordered_set<T, ALLOC>
&
l
) {
141
auto
ordered =
std::set
(
l
.begin(),
l
.end() );
// ensure reproducible printout
142
s
<< ordered;
143
return
s
;
144
}
145
146
template
<
class
T1,
class
T2,
class
COMP,
class
ALLOC>
147
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::map<T1, T2, COMP, ALLOC>
&
m
) {
148
return
details::ostream_joiner
(
s
<<
"{"
,
m
,
", "
,
149
[](
std::ostream
& os,
const
std::pair<const T1, T2>
& p ) ->
std::ostream
& {
150
return
os << p.first <<
": "
<< p.second;
151
} )
152
<<
"}"
;
153
}
154
155
template
<
class
K,
class
T,
class
M>
156
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
GaudiUtils::Map<K, T, M>
&
m
) {
157
// Serialize the internal map.
158
return
s << static_cast<const M&>(
m
);
159
}
160
163
template
<
class
K,
class
T,
class
H,
class
M>
164
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
GaudiUtils::HashMap<K, T, H, M>
&
m
) {
165
// Copy the hash map into a map to have it ordered by key.
166
return
s << GaudiUtils::Map<K, T>(
m
.begin(),
m
.end() );
167
}
168
169
}
// namespace GaudiUtils
170
171
#endif
/*GAUDIKERNEL_SERIALIZESTL_H_*/
std::list
STL class.
std::unordered_set
STL class.
std::pair
gaudirun.s
string s
Definition:
gaudirun.py:346
std::vector
STL class.
std::tuple
gaudirun.c
c
Definition:
gaudirun.py:525
gaudirun.output
output
Definition:
gaudirun.py:521
HashMap.h
bug_34121.t
t
Definition:
bug_34121.py:31
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition:
AttribStringParser.h:136
GaudiUtils::details::IdentityOutputter::operator()
std::ostream & operator()(std::ostream &os, T &&t) const
Definition:
SerializeSTL.h:81
GaudiUtils::operator<<
std::ostream & operator<<(std::ostream &s, const std::pair< T1, T2 > &p)
Serialize an std::pair in a python like format. E.g. "(1, 2)".
Definition:
SerializeSTL.h:102
details
Definition:
AnyDataWrapper.h:19
Gaudi::Units::m
constexpr double m
Definition:
SystemOfUnits.h:108
std::ostream
STL class.
GaudiUtils::details::IdentityOutputter
Definition:
SerializeSTL.h:79
std::array
STL class.
GaudiUtils::Map
Definition:
Map.h:91
std::map
STL class.
cpluginsvc.n
n
Definition:
cpluginsvc.py:234
gaudirun.l
dictionary l
Definition:
gaudirun.py:583
std::begin
T begin(T... args)
Properties.v
v
Definition:
Properties.py:122
std::end
T end(T... args)
Map.h
GaudiUtils::HashMap
Definition:
HashMap.h:83
IOTest.end
end
Definition:
IOTest.py:125
GaudiUtils
Definition:
Allocator.h:72
std::set
STL class.
GaudiUtils::details::ostream_joiner
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition:
SerializeSTL.h:87
Iterator
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition:
Iterator.h:28
GaudiKernel
include
GaudiKernel
SerializeSTL.h
Generated on Mon Feb 24 2025 11:10:45 for The Gaudi Framework by
1.8.18