The Gaudi Framework
master (37c0b60a)
SerializeSTL.h
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2024 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
<
class
T,
class
ALLOC>
43
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::vector<T, ALLOC>
&
v
);
44
46
template
<
class
T, std::
size_t
N>
47
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::array<T, N>
&
v
);
48
50
template
<
class
T,
class
ALLOC>
51
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::list<T, ALLOC>
&
l
);
52
54
template
<
class
T1,
class
T2,
class
COMP,
class
ALLOC>
55
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::map<T1, T2, COMP, ALLOC>
&
m
);
56
58
template
<
class
K,
class
T,
class
M>
59
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
GaudiUtils::Map<K, T, M>
&
m
);
60
62
template
<
class
K,
class
T,
class
H,
class
M>
63
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
GaudiUtils::HashMap<K, T, H, M>
&
m
);
64
65
namespace
details
{
66
67
struct
IdentityOutputter
{
68
template
<
typename
T>
69
std::ostream
&
operator()
(
std::ostream
& os, T&&
t
)
const
{
70
return
os << std::forward<T>(
t
);
71
}
72
};
73
74
template
<
typename
Stream,
typename
Iterator,
typename
Separator,
typename
OutputElement = IdentityOutputter>
75
Stream&
ostream_joiner
( Stream& os,
Iterator
first,
Iterator
last, Separator sep,
76
OutputElement
output
= OutputElement{} ) {
77
if
( first != last )
output
( os, *first++ );
78
while
( first != last )
output
( os << sep, *first++ );
79
return
os;
80
}
81
82
template
<
typename
Stream,
typename
Container,
typename
Separator,
typename
OutputElement = IdentityOutputter>
83
Stream&
ostream_joiner
( Stream& os,
const
Container&
c
, Separator sep, OutputElement
output
= OutputElement{} ) {
84
using
std::begin
,
std::end
;
85
return
ostream_joiner
( os,
begin
(
c
),
end
(
c
), sep,
output
);
86
}
87
}
// namespace details
88
89
template
<
class
T1,
class
T2>
90
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::pair<T1, T2>
& p ) {
91
return
s
<<
'('
<< p.first <<
", "
<< p.second <<
')'
;
92
}
93
94
template
<
class
T,
class
ALLOC>
95
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::vector<T, ALLOC>
&
v
) {
96
return
details::ostream_joiner
(
s
<<
'['
,
v
,
", "
) <<
']'
;
97
}
98
99
template
<
class
T, std::
size_t
N>
100
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::array<T, N>
&
v
) {
101
return
details::ostream_joiner
(
s
<<
'['
,
v
,
", "
) <<
']'
;
102
}
103
104
template
<
class
T,
class
ALLOC>
105
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::list<T, ALLOC>
&
l
) {
106
return
details::ostream_joiner
(
s
<<
'['
,
l
,
", "
) <<
']'
;
107
}
108
109
template
<
class
T,
class
ALLOC>
110
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::set<T, ALLOC>
&
l
) {
111
return
details::ostream_joiner
(
s
<<
'['
,
l
,
", "
) <<
']'
;
112
}
113
114
template
<
class
T,
class
ALLOC>
115
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::unordered_set<T, ALLOC>
&
l
) {
116
auto
ordered =
std::set
(
l
.begin(),
l
.end() );
// ensure reproducible printout
117
s
<< ordered;
118
return
s
;
119
}
120
121
template
<
class
T1,
class
T2,
class
COMP,
class
ALLOC>
122
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
std::map<T1, T2, COMP, ALLOC>
&
m
) {
123
return
details::ostream_joiner
(
s
<<
"{"
,
m
,
", "
,
124
[](
std::ostream
& os,
const
std::pair<const T1, T2>
& p ) ->
std::ostream
& {
125
return
os << p.first <<
": "
<< p.second;
126
} )
127
<<
"}"
;
128
}
129
130
template
<
class
K,
class
T,
class
M>
131
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
GaudiUtils::Map<K, T, M>
&
m
) {
132
// Serialize the internal map.
133
return
s << static_cast<const M&>(
m
);
134
}
135
138
template
<
class
K,
class
T,
class
H,
class
M>
139
std::ostream
&
operator<<
(
std::ostream
&
s
,
const
GaudiUtils::HashMap<K, T, H, M>
&
m
) {
140
// Copy the hash map into a map to have it ordered by key.
141
return
s << GaudiUtils::Map<K, T>(
m
.begin(),
m
.end() );
142
}
143
144
}
// namespace GaudiUtils
145
146
#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.
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:69
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:90
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:67
std::array
STL class.
GaudiUtils::Map
Definition:
Map.h:91
std::map
STL class.
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:75
Iterator
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition:
Iterator.h:28
GaudiKernel
include
GaudiKernel
SerializeSTL.h
Generated on Thu Dec 19 2024 15:35:02 for The Gaudi Framework by
1.8.18