Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v28r2p1 (f1a77ff4)
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 <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 
25 
26 namespace GaudiUtils {
27  namespace details {
28 
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>
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>
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>
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_*/
Extension of the STL map.
Definition: Map.h:82
T end(T...args)
STL class.
iterator end()
Definition: Map.h:132
constexpr double m
Definition: SystemOfUnits.h:93
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition: SerializeSTL.h:35
iterator begin()
Definition: Map.h:131
dictionary l
Definition: gaudirun.py:421
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:149
Common class providing an architecture-independent hash map.
Definition: HashMap.h:77
string s
Definition: gaudirun.py:245
STL class.
std::ostream & operator()(std::ostream &os, T &&t) const
Definition: SerializeSTL.h:31
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