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 <list>
18 #include <map>
19 #include <utility>
20 #include "GaudiKernel/Map.h"
21 #include "GaudiKernel/HashMap.h"
22 
23 #include "GaudiKernel/SerializeSTLFwd.h"
24 
25 namespace GaudiUtils {
26  //static const int NUMBERS_PER_LINE = 6;
27 
29  template <class T, class ALLOC>
30  inline std::ostream& operator<< ( std::ostream& s, const std::vector<T,ALLOC>& v )
31  {
32  s << "[";
33  //int cnt = 0;
34  for(typename std::vector<T,ALLOC>::const_iterator i=v.begin(); i!=v.end(); ++i) {
35  if ( i != v.begin()) s << ", ";
36  s << (*i);
37  //if ((++cnt)%NUMBERS_PER_LINE == 0) s << std::endl;
38  }
39  s << "]";
40  return s;
41  }
42 
44  template <class T, class ALLOC>
45  inline std::ostream& operator<< ( std::ostream& s, const std::list<T,ALLOC>& l )
46  {
47  s << "[";
48  //int cnt = 0;
49  for(typename std::list<T,ALLOC>::const_iterator i=l.begin(); i!=l.end(); ++i) {
50  if ( i != l.begin()) s << ", ";
51  s << (*i);
52  //if ((++cnt)%NUMBERS_PER_LINE == 0) s << std::endl;
53  }
54  s << "]";
55  return s;
56  }
57 
59  template <class T1, class T2>
60  inline std::ostream& operator<< ( std::ostream& s, const std::pair<T1,T2>& p )
61  {
62  return s << "(" << p.first << ", " << p.second << ")";
63  }
64 
66  template <class T1, class T2, class COMP, class ALLOC>
67  inline std::ostream& operator << ( std::ostream& s,
68  const std::map<T1,T2,COMP,ALLOC>& m )
69  {
70  s << "{";
71  for ( typename std::map<T1,T2,COMP,ALLOC>::const_iterator i = m.begin();
72  i != m.end(); ++i ) {
73  if ( i != m.begin() ) s << ", ";
74  s << i->first << ": " << i->second;
75  }
76  s << "}";
77  return s;
78  }
79 
81  template <class K, class T, class M>
82  inline std::ostream& operator << ( std::ostream& s,
83  const GaudiUtils::Map<K,T,M>& m )
84  {
85  // Serialize the internal map.
86  return s << (M)m;
87  }
88 
92  template <class K, class T, class H, class M>
93  inline std::ostream& operator << ( std::ostream& s,
95  {
96  // Copy the hash map into a map to have it ordered by key.
97  return s << GaudiUtils::Map<K,T>(m.begin(),m.end());
98  }
99 
100 } // namespace GaudiUtils
101 
102 #endif /*GAUDIKERNEL_SERIALIZESTL_H_*/
Extension of the STL map.
Definition: Map.h:82
iterator end()
Definition: Map.h:132
constexpr double m
Definition: SystemOfUnits.h:93
iterator begin()
Definition: Map.h:131
dictionary l
Definition: gaudirun.py:422
Forward declarations for the functions in SerializeSTL.h.
Definition: GaudiHistoID.h:139
Common class providing an architecture-independent hash map.
Definition: HashMap.h:77
string s
Definition: gaudirun.py:246
list i
Definition: ana.py:128
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:30