| The Gaudi Framework v32r1 (f65d50dc)

SerializeSTL.h
Go to the documentation of this file.
1
12 #ifndef GAUDIKERNEL_SERIALIZESTL_H_
13 #define GAUDIKERNEL_SERIALIZESTL_H_
14
15 #include "GaudiKernel/HashMap.h"
16 #include "GaudiKernel/Map.h"
17 #include <array>
18 #include <list>
19 #include <map>
20 #include <ostream>
21 #include <utility>
22 #include <vector>
23
24 #include "GaudiKernel/SerializeSTLFwd.h"
25
26 namespace GaudiUtils {
27 namespace details {
28
29 struct IdentityOutputter {
30 template <typename T>
31 std::ostream& operator()( std::ostream& os, T&& t ) const {
32 return os << std::forward<T>( t );
33 }
34 };
35
36 template <typename Stream, typename Iterator, typename Separator, typename OutputElement = IdentityOutputter>
37 Stream& ostream_joiner( Stream& os, Iterator first, Iterator last, Separator sep,
38 OutputElement output = OutputElement{} ) {
39 if ( first != last ) {
40 output( os, *first );
41 ++first;
42 }
43 for ( ; first != last; ++first ) { output( os << sep, *first ); }
44 return os;
45 }
46
47 template <typename Stream, typename Container, typename Separator, typename OutputElement = IdentityOutputter>
48 Stream& ostream_joiner( Stream& os, const Container& c, Separator sep, OutputElement output = OutputElement{} ) {
49 return ostream_joiner( os, std::begin( c ), std::end( c ), sep, output );
50 }
51 } // namespace details
52
54 template <class T, class ALLOC>
55 inline std::ostream& operator<<( std::ostream& s, const std::vector<T, ALLOC>& v ) {
56 return details::ostream_joiner( s << '[', v, ", " ) << ']';
57 }
58
60 template <class T, std::size_t N>
61 inline std::ostream& operator<<( std::ostream& s, const std::array<T, N>& v ) {
62 return details::ostream_joiner( s << '[', v, ", " ) << ']';
63 }
64
66 template <class T, class ALLOC>
67 inline std::ostream& operator<<( std::ostream& s, const std::list<T, ALLOC>& l ) {
68 return details::ostream_joiner( s << '[', l, ", " ) << ']';
69 }
70
72 template <class T1, class T2>
73 inline std::ostream& operator<<( std::ostream& s, const std::pair<T1, T2>& p ) {
74 return s << '(' << p.first << ", " << p.second << ')';
75 }
76
78 template <class T1, class T2, class COMP, class ALLOC>
79 inline std::ostream& operator<<( std::ostream& s, const std::map<T1, T2, COMP, ALLOC>& m ) {
80 return details::ostream_joiner( s << "{", m, ", ",
81 []( std::ostream& os, const std::pair<const T1, T2>& p ) -> std::ostream& {
82 return os << p.first << ": " << p.second;
83 } )
84 << "}";
85 }
86
88 template <class K, class T, class M>
89 inline std::ostream& operator<<( std::ostream& s, const GaudiUtils::Map<K, T, M>& m ) {
90 // Serialize the internal map.
91 return s << static_cast<const M&>( m );
92 }
93
97 template <class K, class T, class H, class M>
98 inline std::ostream& operator<<( std::ostream& s, const GaudiUtils::HashMap<K, T, H, M>& m ) {
99 // Copy the hash map into a map to have it ordered by key.
100 return s << GaudiUtils::Map<K, T>( m.begin(), m.end() );
101 }
102
103 } // namespace GaudiUtils
104
105 #endif /*GAUDIKERNEL_SERIALIZESTL_H_*/
GaudiUtils::Map
Extension of the STL map.
Definition: Map.h:81
gaudirun.c
c
Definition: gaudirun.py:487
gaudirun.output
output
Definition: gaudirun.py:484
std::end
T end(T... args)
Map.h
HashMap.h
std::map
STL class.
details
Definition: AnyDataWrapper.h:10
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:92
std::list
STL class.
GaudiUtils::details::ostream_joiner
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition: SerializeSTL.h:37
gaudirun.l
dictionary l
Definition: gaudirun.py:521
std::pair
GaudiUtils::details::IdentityOutputter
Definition: SerializeSTL.h:29
std::vector
STL class.
GaudiUtils::details::IdentityOutputter::operator()
std::ostream & operator()(std::ostream &os, T &&t) const
Definition: SerializeSTL.h:31
Iterator
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:18
std::begin
T begin(T... args)
GaudiUtils
Forward declarations for the functions in SerializeSTL.h.
Definition: GaudiHistoID.h:136
GaudiUtils::HashMap
Common class providing an architecture-independent hash map.
Definition: HashMap.h:73
gaudirun.s
string s
Definition: gaudirun.py:316
std::array
STL class.
SerializeSTLFwd.h
std::ostream
STL class.
GaudiUtils::operator<<
std::ostream & operator<<(std::ostream &s, const std::vector< T, ALLOC > &v)
Serialize an std::vector in a python like format. E.g. "[1, 2, 3]".
Definition: SerializeSTL.h:55