File indexing completed on 2025-01-30 10:07:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #ifndef GAUDIKERNEL_SERIALIZESTL_H_
0023 #define GAUDIKERNEL_SERIALIZESTL_H_
0024
0025 #include "GaudiKernel/HashMap.h"
0026 #include "GaudiKernel/Map.h"
0027 #include <array>
0028 #include <list>
0029 #include <map>
0030 #include <ostream>
0031 #include <utility>
0032 #include <vector>
0033
0034 namespace GaudiUtils {
0035
0036 template <class T1, class T2>
0037 std::ostream& operator<<( std::ostream& s, const std::pair<T1, T2>& p );
0038
0039
0040 template <class T, class ALLOC>
0041 std::ostream& operator<<( std::ostream& s, const std::vector<T, ALLOC>& v );
0042
0043
0044 template <class T, std::size_t N>
0045 std::ostream& operator<<( std::ostream& s, const std::array<T, N>& v );
0046
0047
0048 template <class T, class ALLOC>
0049 std::ostream& operator<<( std::ostream& s, const std::list<T, ALLOC>& l );
0050
0051
0052 template <class T1, class T2, class COMP, class ALLOC>
0053 std::ostream& operator<<( std::ostream& s, const std::map<T1, T2, COMP, ALLOC>& m );
0054
0055
0056 template <class K, class T, class M>
0057 std::ostream& operator<<( std::ostream& s, const GaudiUtils::Map<K, T, M>& m );
0058
0059
0060 template <class K, class T, class H, class M>
0061 std::ostream& operator<<( std::ostream& s, const GaudiUtils::HashMap<K, T, H, M>& m );
0062
0063 namespace details {
0064
0065 struct IdentityOutputter {
0066 template <typename T>
0067 std::ostream& operator()( std::ostream& os, T&& t ) const {
0068 return os << std::forward<T>( t );
0069 }
0070 };
0071
0072 template <typename Stream, typename Iterator, typename Separator, typename OutputElement = IdentityOutputter>
0073 Stream& ostream_joiner( Stream& os, Iterator first, Iterator last, Separator sep,
0074 OutputElement output = OutputElement{} ) {
0075 if ( first != last ) output( os, *first++ );
0076 while ( first != last ) output( os << sep, *first++ );
0077 return os;
0078 }
0079
0080 template <typename Stream, typename Container, typename Separator, typename OutputElement = IdentityOutputter>
0081 Stream& ostream_joiner( Stream& os, const Container& c, Separator sep, OutputElement output = OutputElement{} ) {
0082 using std::begin, std::end;
0083 return ostream_joiner( os, begin( c ), end( c ), sep, output );
0084 }
0085 }
0086
0087 template <class T1, class T2>
0088 std::ostream& operator<<( std::ostream& s, const std::pair<T1, T2>& p ) {
0089 return s << '(' << p.first << ", " << p.second << ')';
0090 }
0091
0092 template <class T, class ALLOC>
0093 std::ostream& operator<<( std::ostream& s, const std::vector<T, ALLOC>& v ) {
0094 return details::ostream_joiner( s << '[', v, ", " ) << ']';
0095 }
0096
0097 template <class T, std::size_t N>
0098 std::ostream& operator<<( std::ostream& s, const std::array<T, N>& v ) {
0099 return details::ostream_joiner( s << '[', v, ", " ) << ']';
0100 }
0101
0102 template <class T, class ALLOC>
0103 std::ostream& operator<<( std::ostream& s, const std::list<T, ALLOC>& l ) {
0104 return details::ostream_joiner( s << '[', l, ", " ) << ']';
0105 }
0106
0107 template <class T1, class T2, class COMP, class ALLOC>
0108 std::ostream& operator<<( std::ostream& s, const std::map<T1, T2, COMP, ALLOC>& m ) {
0109 return details::ostream_joiner( s << "{", m, ", ",
0110 []( std::ostream& os, const std::pair<const T1, T2>& p ) -> std::ostream& {
0111 return os << p.first << ": " << p.second;
0112 } )
0113 << "}";
0114 }
0115
0116 template <class K, class T, class M>
0117 std::ostream& operator<<( std::ostream& s, const GaudiUtils::Map<K, T, M>& m ) {
0118
0119 return s << static_cast<const M&>( m );
0120 }
0121
0122
0123
0124 template <class K, class T, class H, class M>
0125 std::ostream& operator<<( std::ostream& s, const GaudiUtils::HashMap<K, T, H, M>& m ) {
0126
0127 return s << GaudiUtils::Map<K, T>( m.begin(), m.end() );
0128 }
0129
0130 }
0131
0132 #endif