The Gaudi Framework  v29r0 (ff2e7097)
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 
25 
26 namespace GaudiUtils
27 {
28  namespace details
29  {
30 
32  template <typename T>
33  std::ostream& operator()( std::ostream& os, T&& t ) const
34  {
35  return os << std::forward<T>( t );
36  }
37  };
38 
39  template <typename Stream, typename Iterator, typename Separator, typename OutputElement = IdentityOutputter>
40  Stream& ostream_joiner( Stream& os, Iterator first, Iterator last, Separator sep,
41  OutputElement output = OutputElement{} )
42  {
43  if ( first != last ) {
44  output( os, *first );
45  ++first;
46  }
47  for ( ; first != last; ++first ) {
48  output( os << sep, *first );
49  }
50  return os;
51  }
52 
53  template <typename Stream, typename Container, typename Separator, typename OutputElement = IdentityOutputter>
54  Stream& ostream_joiner( Stream& os, const Container& c, Separator sep, OutputElement output = OutputElement{} )
55  {
56  return ostream_joiner( os, std::begin( c ), std::end( c ), sep, output );
57  }
58  }
59 
61  template <class T, class ALLOC>
62  inline std::ostream& operator<<( std::ostream& s, const std::vector<T, ALLOC>& v )
63  {
64  return details::ostream_joiner( s << '[', v, ", " ) << ']';
65  }
66 
68  template <class T, std::size_t N>
69  inline std::ostream& operator<<( std::ostream& s, const std::array<T, N>& v )
70  {
71  return details::ostream_joiner( s << '[', v, ", " ) << ']';
72  }
73 
75  template <class T, class ALLOC>
76  inline std::ostream& operator<<( std::ostream& s, const std::list<T, ALLOC>& l )
77  {
78  return details::ostream_joiner( s << '[', l, ", " ) << ']';
79  }
80 
82  template <class T1, class T2>
83  inline std::ostream& operator<<( std::ostream& s, const std::pair<T1, T2>& p )
84  {
85  return s << '(' << p.first << ", " << p.second << ')';
86  }
87 
89  template <class T1, class T2, class COMP, class ALLOC>
90  inline std::ostream& operator<<( std::ostream& s, const std::map<T1, T2, COMP, ALLOC>& m )
91  {
92  return details::ostream_joiner( s << "{", m, ", ",
93  []( std::ostream& os, const std::pair<const T1, T2>& p ) -> std::ostream& {
94  return os << p.first << ": " << p.second;
95  } )
96  << "}";
97  }
98 
100  template <class K, class T, class M>
101  inline std::ostream& operator<<( std::ostream& s, const GaudiUtils::Map<K, T, M>& m )
102  {
103  // Serialize the internal map.
104  return s << static_cast<const M&>( m );
105  }
106 
110  template <class K, class T, class H, class M>
111  inline std::ostream& operator<<( std::ostream& s, const GaudiUtils::HashMap<K, T, H, M>& m )
112  {
113  // Copy the hash map into a map to have it ordered by key.
114  return s << GaudiUtils::Map<K, T>( m.begin(), m.end() );
115  }
116 
117 } // namespace GaudiUtils
118 
119 #endif /*GAUDIKERNEL_SERIALIZESTL_H_*/
T end(T...args)
constexpr double m
Definition: SystemOfUnits.h:94
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition: SerializeSTL.h:40
dictionary l
Definition: gaudirun.py:440
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:18
T begin(T...args)
Forward declarations for the functions in SerializeSTL.h.
Definition: GaudiHistoID.h:140
string s
Definition: gaudirun.py:253
STL class.
std::ostream & operator()(std::ostream &os, T &&t) const
Definition: SerializeSTL.h:33