The Gaudi Framework  v33r2 (a6f0ec87)
SerializeSTL.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
22 #ifndef GAUDIKERNEL_SERIALIZESTL_H_
23 #define GAUDIKERNEL_SERIALIZESTL_H_
24 
25 #include "GaudiKernel/HashMap.h"
26 #include "GaudiKernel/Map.h"
27 #include <array>
28 #include <list>
29 #include <map>
30 #include <ostream>
31 #include <utility>
32 #include <vector>
33 
34 namespace GaudiUtils {
36  template <class T1, class T2>
38 
40  template <class T, class ALLOC>
42 
44  template <class T, std::size_t N>
46 
48  template <class T, class ALLOC>
50 
52  template <class T1, class T2, class COMP, class ALLOC>
54 
56  template <class K, class T, class M>
58 
60  template <class K, class T, class H, class M>
62 
63  namespace details {
64 
66  template <typename T>
67  std::ostream& operator()( std::ostream& os, T&& t ) const {
68  return os << std::forward<T>( t );
69  }
70  };
71 
72  template <typename Stream, typename Iterator, typename Separator, typename OutputElement = IdentityOutputter>
73  Stream& ostream_joiner( Stream& os, Iterator first, Iterator last, Separator sep,
74  OutputElement output = OutputElement{} ) {
75  if ( first != last ) output( os, *first++ );
76  while ( first != last ) output( os << sep, *first++ );
77  return os;
78  }
79 
80  template <typename Stream, typename Container, typename Separator, typename OutputElement = IdentityOutputter>
81  Stream& ostream_joiner( Stream& os, const Container& c, Separator sep, OutputElement output = OutputElement{} ) {
82  using std::begin, std::end;
83  return ostream_joiner( os, begin( c ), end( c ), sep, output );
84  }
85  } // namespace details
86 
87  template <class T1, class T2>
89  return s << '(' << p.first << ", " << p.second << ')';
90  }
91 
92  template <class T, class ALLOC>
94  return details::ostream_joiner( s << '[', v, ", " ) << ']';
95  }
96 
97  template <class T, std::size_t N>
99  return details::ostream_joiner( s << '[', v, ", " ) << ']';
100  }
101 
102  template <class T, class ALLOC>
104  return details::ostream_joiner( s << '[', l, ", " ) << ']';
105  }
106 
107  template <class T1, class T2, class COMP, class ALLOC>
109  return details::ostream_joiner( s << "{", m, ", ",
110  []( std::ostream& os, const std::pair<const T1, T2>& p ) -> std::ostream& {
111  return os << p.first << ": " << p.second;
112  } )
113  << "}";
114  }
115 
116  template <class K, class T, class M>
118  // Serialize the internal map.
119  return s << static_cast<const M&>( m );
120  }
121 
124  template <class K, class T, class H, class M>
126  // Copy the hash map into a map to have it ordered by key.
127  return s << GaudiUtils::Map<K, T>( m.begin(), m.end() );
128  }
129 
130 } // namespace GaudiUtils
131 
132 #endif /*GAUDIKERNEL_SERIALIZESTL_H_*/
Extension of the STL map.
Definition: Map.h:91
T end(T... args)
STL class.
constexpr double m
std::ostream & operator<<(std::ostream &s, const std::pair< T1, T2 > &p)
Serialize an std::pair in a python like format. E.g. "(1, 2)".
Definition: SerializeSTL.h:88
def end
Definition: IOTest.py:123
STL class.
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition: SerializeSTL.h:73
dictionary l
Definition: gaudirun.py:543
STL class.
std::ostream & operator()(std::ostream &os, T &&t) const
Definition: SerializeSTL.h:67
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:28
T begin(T... args)
Common class providing an architecture-independent hash map.
Definition: HashMap.h:83
string s
Definition: gaudirun.py:328
STL class.
AttribStringParser::Iterator begin(const AttribStringParser &parser)
STL class.