26#include <unordered_set>
46 std::ostream&
toStream(
const TYPE& obj, std::ostream& s );
58 template <
class ITERATOR>
59 inline std::ostream&
toStream( ITERATOR first,
62 const std::string& open,
63 const std::string& close,
64 const std::string& delim );
71 inline std::ostream&
toStream(
const std::string& obj, std::ostream& s ) {
return s << std::quoted( obj,
'\'' ); }
76 inline std::ostream&
toStream(
const bool obj, std::ostream& s ) {
return s << ( obj ?
"True" :
"False" ); }
81 inline std::ostream&
toStream(
const float obj, std::ostream& s ) {
return s << std::format(
"{}", obj ); }
86 inline std::ostream&
toStream(
const double obj, std::ostream& s ) {
return s << std::format(
"{}", obj ); }
91 inline std::ostream&
toStream(
const long double obj, std::ostream& s ) {
return s << std::format(
"{}", obj ); }
99 template <
class KTYPE,
class VTYPE>
100 inline std::ostream&
toStream(
const std::pair<KTYPE, VTYPE>& obj, std::ostream& s ) {
101 return toStream( obj.second,
toStream( obj.first, s <<
"( " ) <<
" , " ) <<
" )";
104 template <
typename... Args>
105 inline std::ostream&
toStream(
const std::tuple<Args...>& tuple, std::ostream& s );
113 template <
class TYPE,
class ALLOCATOR>
114 inline std::ostream&
toStream(
const std::vector<TYPE, ALLOCATOR>& obj, std::ostream& s ) {
115 return toStream( obj.begin(), obj.end(), s,
"[ ",
" ]",
" , " );
121 inline std::ostream&
toStream(
const std::vector<bool>& obj, std::ostream& s ) {
123 return ostream_joiner(
124 s <<
"[ ", obj,
" , ",
125 []( std::ostream& os,
bool b ) -> std::ostream& {
return os << ( b ?
"True" :
"False" ); } )
134 template <
class TYPE,
class ALLOCATOR>
135 inline std::ostream&
toStream(
const std::list<TYPE, ALLOCATOR>& obj, std::ostream& s ) {
136 return toStream( obj.begin(), obj.end(), s,
"[ ",
" ]",
" , " );
144 template <
class TYPE,
class CMP,
class ALLOCATOR>
145 inline std::ostream&
toStream(
const std::set<TYPE, CMP, ALLOCATOR>& obj, std::ostream& s ) {
146 return toStream( obj.begin(), obj.end(), s,
"[ ",
" ]",
" , " );
151 template <
class TYPE,
class HASH,
class CMP,
class ALLOCATOR>
152 inline std::ostream&
toStream(
const std::unordered_set<TYPE, HASH, CMP, ALLOCATOR>& obj, std::ostream& s ) {
153 auto ordered = std::set( obj.begin(), obj.end() );
154 return obj.empty() ? s <<
"set()" :
toStream( ordered.begin(), ordered.end(), s,
"{ ",
" }",
" , " );
163 template <
class KTYPE,
class VTYPE,
class CMP,
class ALLOCATOR>
164 inline std::ostream&
toStream(
const std::map<KTYPE, VTYPE, CMP, ALLOCATOR>& obj, std::ostream& s ) {
166 return ostream_joiner( s <<
"{ ", obj,
" , ",
167 []( std::ostream& os,
const std::pair<const KTYPE, VTYPE>& i ) -> std::ostream& {
180 template <
class KTYPE,
class VTYPE,
class CMP,
class ALLOCATOR>
183 return ostream_joiner( s <<
"{ ", obj,
" , ",
184 []( std::ostream& os,
const std::pair<const KTYPE, VTYPE>& i ) -> std::ostream& {
197 template <
class KTYPE,
class VTYPE,
class MAP>
200 return ostream_joiner( s <<
"{ ", obj,
" , ",
201 []( std::ostream& os,
const std::pair<const KTYPE, VTYPE>& i ) -> std::ostream& {
214 template <
class KTYPE,
class VTYPE,
class HASH,
class MAP>
223 template <
class TYPE,
unsigned int N>
224 std::ostream&
toStream(
const TYPE ( &obj )[N], std::ostream& s ) {
225 if constexpr ( N == 1 ) {
226 return toStream( obj[0], s <<
"( " ) <<
" , )";
228 return toStream( obj, obj + N, s,
"( ",
" )",
" , " );
235 template <
class TYPE, std::
size_t N>
236 std::ostream&
toStream(
const std::array<TYPE, N>& obj, std::ostream& s ) {
237 if constexpr ( N == 1 ) {
238 return toStream( obj[0], s <<
"( " ) <<
" , )";
247 template <
unsigned int N>
248 std::ostream&
toStream(
const char ( &obj )[N], std::ostream& s ) {
249 return toStream( std::string( obj, obj + N ), s );
255 inline std::ostream&
toStream(
const char* obj, std::ostream& s ) {
return toStream( std::string( obj ), s ); }
261 template <
class TYPE>
262 inline std::ostream&
toStream(
const TYPE& obj, std::ostream& s ) {
266 template <
class Tuple, std::
size_t N>
268 static std::ostream&
toStream(
const Tuple& t, std::ostream& s ) {
274 template <
class Tuple>
276 static std::ostream&
toStream(
const Tuple& t, std::ostream& s ) {
287 template <
typename... Args>
288 inline std::ostream&
toStream(
const std::tuple<Args...>& tuple, std::ostream& s ) {
290 if constexpr ( std::tuple_size_v<std::tuple<Args...>> == 1 ) {
306 template <
class ITERATOR>
310 const std::string& open,
311 const std::string& close,
312 const std::string& delim )
314 using ref_t =
typename std::iterator_traits<ITERATOR>::reference;
316 return ostream_joiner( s << open, first, last, delim,
317 []( std::ostream& os, ref_t i ) -> std::ostream& {
return toStream( i, os ); } )
328 template <
class TYPE>
330 std::ostringstream s;
331 std::ios::fmtflags orig_flags = s.flags();
332 s.setf( std::ios::showpoint );
334 s.flags( orig_flags );
Provide serialization function (output only) for some common STL classes (vectors,...
Common class providing an architecture-independent hash map.
Extension of the STL map.
A bit modified version of 'Loki::AssocVector' associative vector from Loki library by Andrei Alexandr...
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
AttribStringParser::Iterator begin(const AttribStringParser &parser)
std::ostream & toStream(ITERATOR first, ITERATOR last, std::ostream &s, const std::string &open, const std::string &close, const std::string &delim)
the helper function to print the sequence
AttribStringParser::Iterator end(const AttribStringParser &)
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
static std::ostream & toStream(const Tuple &t, std::ostream &s)
static std::ostream & toStream(const Tuple &t, std::ostream &s)