Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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>
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_*/
T end(T...args)
constexpr double m
Definition: SystemOfUnits.h:92
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition: SerializeSTL.h:37
dictionary l
Definition: gaudirun.py:517
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
string s
Definition: gaudirun.py:312
STL class.
std::ostream & operator()(std::ostream &os, T &&t) const
Definition: SerializeSTL.h:31