| The Gaudi Framework v28r2-patches (bc4ad17a)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

SerializeSTL.h
Go to the documentation of this file.
1
12 #ifndef GAUDIKERNEL_SERIALIZESTL_H_
13 #define GAUDIKERNEL_SERIALIZESTL_H_
14
15 #include <ostream>
16 #include <vector>
17 #include <array>
18 #include <list>
19 #include <map>
20 #include <utility>
21 #include "GaudiKernel/Map.h"
22 #include "GaudiKernel/HashMap.h"
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 { return os << std::forward<T>(t); }
32 };
33
34 template <typename Stream, typename Iterator, typename Separator, typename OutputElement = IdentityOutputter>
35 Stream& ostream_joiner(Stream& os, Iterator first, Iterator last, Separator sep, OutputElement output = OutputElement{}) {
36 if (first!=last) { output(os,*first); ++first; }
37 for (;first!=last;++first) { output(os << sep,*first); }
38 return os;
39 }
40
41 template <typename Stream, typename Container, typename Separator, typename OutputElement = IdentityOutputter>
42 Stream& ostream_joiner(Stream& os, const Container& c, Separator sep, OutputElement output = OutputElement{}) {
43 return ostream_joiner( os, std::begin(c), std::end(c), sep, output );
44 }
45
46 }
47
49 template <class T, class ALLOC>
50 inline std::ostream& operator<< ( std::ostream& s, const std::vector<T,ALLOC>& v )
51 {
52 return details::ostream_joiner( s << '[', v, ", " ) << ']';
53 }
54
56 template <class T, std::size_t N>
57 inline std::ostream& operator<< ( std::ostream& s, const std::array<T,N>& v )
58 {
59 return details::ostream_joiner( s << '[', v, ", " ) << ']';
60 }
61
63 template <class T, class ALLOC>
64 inline std::ostream& operator<< ( std::ostream& s, const std::list<T,ALLOC>& l )
65 {
66 return details::ostream_joiner( s << '[', l, ", " ) << ']';
67 }
68
70 template <class T1, class T2>
71 inline std::ostream& operator<< ( std::ostream& s, const std::pair<T1,T2>& p )
72 {
73 return s << '(' << p.first << ", " << p.second << ')';
74 }
75
77 template <class T1, class T2, class COMP, class ALLOC>
78 inline std::ostream& operator << ( std::ostream& s,
79 const std::map<T1,T2,COMP,ALLOC>& m )
80 {
81 return details::ostream_joiner( s << "{", m, ", ",
82 [](std::ostream& os, const std::pair<const T1,T2>& p)
83 -> std::ostream&
84 { return os << p.first << ": " << p.second; } )
85 << "}";
86 }
87
89 template <class K, class T, class M>
90 inline std::ostream& operator << ( std::ostream& s,
91 const GaudiUtils::Map<K,T,M>& m )
92 {
93 // Serialize the internal map.
94 return s << static_cast<const M&>(m);
95 }
96
100 template <class K, class T, class H, class M>
101 inline std::ostream& operator << ( std::ostream& s,
102 const GaudiUtils::HashMap<K,T,H,M>& m )
103 {
104 // Copy the hash map into a map to have it ordered by key.
105 return s << GaudiUtils::Map<K,T>(m.begin(),m.end());
106 }
107
108 } // namespace GaudiUtils
109
110 #endif /*GAUDIKERNEL_SERIALIZESTL_H_*/
GaudiUtils::Map
Extension of the STL map.
Definition: Map.h:82
gaudirun.c
c
Definition: gaudirun.py:391
gaudirun.output
output
Definition: gaudirun.py:388
std::end
T end(T...args)
Map.h
HashMap.h
std::map
STL class.
GaudiUtils::Map::end
iterator end()
Definition: Map.h:132
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:93
GaudiUtils::details::ostream_joiner
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition: SerializeSTL.h:35
GaudiUtils::Map::begin
iterator begin()
Definition: Map.h:131
gaudirun.l
dictionary l
Definition: gaudirun.py:421
std::pair
GaudiUtils::details::IdentityOutputter
Definition: SerializeSTL.h:29
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:149
GaudiUtils::HashMap
Common class providing an architecture-independent hash map.
Definition: HashMap.h:77
gaudirun.s
string s
Definition: gaudirun.py:245
SerializeSTLFwd.h
std::ostream
STL class.
GaudiUtils::details::IdentityOutputter::operator()
std::ostream & operator()(std::ostream &os, T &&t) const
Definition: SerializeSTL.h:31
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:50