2 #ifndef GAUDIPROPERTYPARSERS_PARSERVALUETOSTREAM_H
3 #define GAUDIPROPERTYPARSERS_PARSERVALUETOSTREAM_H 1
20 #include "GaudiKernel/Map.h"
21 #include "GaudiKernel/HashMap.h"
22 #include "GaudiKernel/VectorMap.h"
46 std::ostream&
toStream (
const TYPE& obj, std::ostream&
s ) ;
59 template <
class ITERATOR>
64 const std::string& open ,
65 const std::string& close ,
66 const std::string& delim ) ;
75 (
const std::string& obj , std::ostream&
s )
77 if ( std::string::npos == obj.find(
'\'') )
78 { s <<
"\'" << obj <<
"\'" ; }
80 { s <<
"\"" << obj <<
"\"" ; }
88 (
const bool obj , std::ostream& s )
89 {
return s << ( obj ?
"True" :
"False" ) ; }
95 (
const float obj , std::ostream& s ,
const int prec = 6 )
97 const int p = s.precision() ;
98 return s << std::setprecision ( prec ) << obj << std::setprecision ( p ) ;
105 (
const double obj , std::ostream& s ,
const int prec = 8 )
107 const int p = s.precision() ;
108 return s << std::setprecision ( prec ) << obj << std::setprecision ( p ) ;
115 (
const long double obj , std::ostream& s ,
const int prec = 10 )
117 const int p = s.precision() ;
118 return s << std::setprecision ( prec ) << obj << std::setprecision ( p ) ;
128 template<
class KTYPE,
class VTYPE>
130 (
const std::pair<KTYPE,VTYPE>& obj, std::ostream& s)
145 template<
class TYPE,
class ALLOCATOR>
147 (
const std::vector<TYPE,ALLOCATOR>& obj, std::ostream& s)
149 return toStream ( obj.begin() , obj.end () ,
s ,
"[ " ,
" ]" ,
" , " ) ;
158 template<
class TYPE,
class ALLOCATOR>
160 (
const std::list<TYPE,ALLOCATOR>& obj, std::ostream& s)
162 return toStream ( obj.begin() , obj.end () ,
s ,
"[ " ,
" ]" ,
" , " ) ;
171 template<
class TYPE,
class CMP,
class ALLOCATOR>
173 (
const std::set<TYPE,CMP,ALLOCATOR>& obj, std::ostream& s)
175 return toStream ( obj.begin() , obj.end () ,
s ,
"[ " ,
" ]" ,
" , " ) ;
185 template<
class KTYPE,
class VTYPE,
class CMP,
class ALLOCATOR>
187 (
const std::map<KTYPE,VTYPE,CMP,ALLOCATOR>& obj, std::ostream& s )
190 for (
typename std::map<KTYPE,VTYPE,CMP,ALLOCATOR>::const_iterator cur =
191 obj.begin() ; obj.end() != cur ; ++cur )
193 if ( obj.begin() != cur ) { s <<
" , " ; }
209 template<
class KTYPE,
class VTYPE,
class CMP,
class ALLOCATOR>
215 obj.
end() != cur ; ++cur )
217 if ( obj.
begin() != cur ) { s <<
" , " ; }
233 template<
class KTYPE,
class VTYPE,
class MAP>
239 obj.
end() != cur ; ++cur )
241 if ( obj.
begin() != cur ) { s <<
" , " ; }
257 template<
class KTYPE,
class VTYPE,
class HASH,
class MAP>
263 obj.
end() != cur ; ++cur )
265 if ( obj.
begin() != cur ) { s <<
" , " ; }
277 template <
class TYPE,
unsigned int N>
278 std::ostream&
toStream ( TYPE(&obj)[
N] , std::ostream& s )
280 return toStream ( obj , obj + N , s ,
"( " ,
" )" ,
" , " ) ;
287 template <
class TYPE,
unsigned int N>
288 std::ostream&
toStream (
const TYPE(&obj)[
N] , std::ostream& s )
290 return toStream ( obj , obj + N , s ,
"( " ,
" )" ,
" , " ) ;
297 template <
unsigned int N>
298 std::ostream&
toStream (
char (&obj)[
N] , std::ostream& s )
299 {
return toStream ( std::string ( obj , obj+N ) , s ) ; }
305 template <
unsigned int N>
306 std::ostream&
toStream (
const char (&obj)[N] , std::ostream& s )
307 {
return toStream ( std::string ( obj , obj+N ) , s ) ; }
313 inline std::ostream&
toStream (
const char* obj , std::ostream& s )
314 {
return toStream ( std::string ( obj ) , s ) ; }
322 inline std::ostream&
toStream (
const TYPE& obj, std::ostream& s )
323 {
return s << obj ; }
336 template <
class ITERATOR>
341 const std::string& open ,
342 const std::string& close ,
343 const std::string& delim )
346 for ( ITERATOR curr = first ; curr != last ; ++curr )
348 if ( first != curr ) { s << delim ; }
357 template<
class Tuple, std::
size_t N>
358 struct TuplePrinter {
359 static std::ostream&
toStream(
const Tuple& t, std::ostream& s)
368 template<
class Tuple>
369 struct TuplePrinter<
Tuple, 1>{
370 static std::ostream&
toStream(
const Tuple& t, std::ostream& s)
383 template<
typename... Args>
384 inline std::ostream&
toStream(
const std::tuple<Args...>& tuple, std::ostream& s) {
386 TuplePrinter<decltype(tuple),
sizeof...(Args)>::
toStream(tuple, s);
399 template <
class TYPE>
400 inline std::string
toString (
const TYPE& obj )
402 std::ostringstream
s;
403 std::ios::fmtflags orig_flags = s.flags();
404 s.setf(std::ios::showpoint);
A bit modified version of 'Loki::AssocVector' associative vector from Loki library by Andrei Alexandr...
Extension of the STL map.
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
iterator end() const
"end" iterator for sequential access (const-only version!)
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
iterator begin() const
"begin" iterator for sequential access (const-only version!)
map_type::const_iterator const_iterator
_vector::const_iterator const_iterator
visible const_iterator (exported)
Common class providing an architecture-independent hash map.
static std::ostream & toStream(const Tuple &t, std::ostream &s)
Helper functions to set/get the application return code.