The Gaudi Framework  v32r2 (46d42edc)
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  namespace details {
28 
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>
56  return details::ostream_joiner( s << '[', v, ", " ) << ']';
57  }
58 
60  template <class T, std::size_t N>
62  return details::ostream_joiner( s << '[', v, ", " ) << ']';
63  }
64 
66  template <class T, class ALLOC>
68  return details::ostream_joiner( s << '[', l, ", " ) << ']';
69  }
70 
72  template <class T1, class T2>
74  return s << '(' << p.first << ", " << p.second << ')';
75  }
76 
78  template <class T1, class T2, class COMP, class ALLOC>
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>
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>
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_*/
Extension of the STL map.
Definition: Map.h:81
T end(T... args)
STL class.
constexpr double m
Definition: SystemOfUnits.h:92
STL class.
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition: SerializeSTL.h:37
dictionary l
Definition: gaudirun.py:523
STL class.
std::ostream & operator()(std::ostream &os, T &&t) const
Definition: SerializeSTL.h:31
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:136
Common class providing an architecture-independent hash map.
Definition: HashMap.h:73
string s
Definition: gaudirun.py:318
STL class.
STL class.
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