The Gaudi Framework  v33r0 (d5ea422b)
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 
35 
36 namespace GaudiUtils {
37  namespace details {
38 
40  template <typename T>
41  std::ostream& operator()( std::ostream& os, T&& t ) const {
42  return os << std::forward<T>( t );
43  }
44  };
45 
46  template <typename Stream, typename Iterator, typename Separator, typename OutputElement = IdentityOutputter>
47  Stream& ostream_joiner( Stream& os, Iterator first, Iterator last, Separator sep,
48  OutputElement output = OutputElement{} ) {
49  if ( first != last ) {
50  output( os, *first );
51  ++first;
52  }
53  for ( ; first != last; ++first ) { output( os << sep, *first ); }
54  return os;
55  }
56 
57  template <typename Stream, typename Container, typename Separator, typename OutputElement = IdentityOutputter>
58  Stream& ostream_joiner( Stream& os, const Container& c, Separator sep, OutputElement output = OutputElement{} ) {
59  return ostream_joiner( os, std::begin( c ), std::end( c ), sep, output );
60  }
61  } // namespace details
62 
64  template <class T, class ALLOC>
66  return details::ostream_joiner( s << '[', v, ", " ) << ']';
67  }
68 
70  template <class T, std::size_t N>
72  return details::ostream_joiner( s << '[', v, ", " ) << ']';
73  }
74 
76  template <class T, class ALLOC>
78  return details::ostream_joiner( s << '[', l, ", " ) << ']';
79  }
80 
82  template <class T1, class T2>
84  return s << '(' << p.first << ", " << p.second << ')';
85  }
86 
88  template <class T1, class T2, class COMP, class ALLOC>
90  return details::ostream_joiner( s << "{", m, ", ",
91  []( std::ostream& os, const std::pair<const T1, T2>& p ) -> std::ostream& {
92  return os << p.first << ": " << p.second;
93  } )
94  << "}";
95  }
96 
98  template <class K, class T, class M>
100  // Serialize the internal map.
101  return s << static_cast<const M&>( m );
102  }
103 
107  template <class K, class T, class H, class M>
109  // Copy the hash map into a map to have it ordered by key.
110  return s << GaudiUtils::Map<K, T>( m.begin(), m.end() );
111  }
112 
113 } // namespace GaudiUtils
114 
115 #endif /*GAUDIKERNEL_SERIALIZESTL_H_*/
Extension of the STL map.
Definition: Map.h:91
T end(T... args)
STL class.
constexpr double m
STL class.
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition: SerializeSTL.h:47
dictionary l
Definition: gaudirun.py:543
STL class.
std::ostream & operator()(std::ostream &os, T &&t) const
Definition: SerializeSTL.h:41
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:28
T begin(T... args)
Forward declarations for the functions in SerializeSTL.h.
Definition: GaudiHistoID.h:146
Common class providing an architecture-independent hash map.
Definition: HashMap.h:83
string s
Definition: gaudirun.py:328
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:65