12 #ifndef ZYPP_BASE_LOGTOOLS_H 13 #define ZYPP_BASE_LOGTOOLS_H 22 #include <zypp-core/base/Hash.h> 23 #include <zypp-core/base/Logger.h> 24 #include <zypp-core/base/String.h> 25 #include <zypp-core/base/Iterator.h> 26 #include <zypp-core/Globals.h> 91 template<
class TIterator>
93 TIterator begin, TIterator end,
94 const std::string & intro =
"{",
95 const std::string & pfx =
"\n ",
96 const std::string & sep =
"\n ",
97 const std::string & sfx =
"\n",
98 const std::string & extro =
"}" )
103 str << pfx << *begin;
104 for ( ++begin; begin != end; ++begin )
105 str << sep << *begin;
114 template<
class TIterator>
116 TIterator begin, TIterator end )
117 {
return dumpRange(
str, begin, end,
"(",
"",
", ",
"",
")" ); }
119 template<
class TContainer>
131 template<
class TIterator>
143 template<
class TIterator>
144 std::ostream & operator<<( std::ostream & str, const RangeLine<TIterator> & obj )
157 template<
class TIterator>
161 template<
class TContainer>
163 {
return rangeLine( cont.begin(), cont.end() ); }
166 std::ostream & operator<<( std::ostream & str, const std::vector<Tp> & obj )
169 template<
class Tp,
class TCmp,
class TAlloc>
170 std::ostream & operator<<( std::ostream & str, const std::set<Tp,TCmp,TAlloc> & obj )
174 std::ostream & operator<<( std::ostream & str, const std::unordered_set<Tp> & obj )
178 std::ostream & operator<<( std::ostream & str, const std::multiset<Tp> & obj )
182 std::ostream & operator<<( std::ostream & str, const std::list<Tp> & obj )
186 std::ostream & operator<<( std::ostream & str, const Iterable<Tp> & obj )
190 namespace _logtoolsdetail
202 template<
class TPair>
218 template<
class TPair>
219 std::ostream & operator<<( std::ostream & str, const MapEntry<TPair> & obj )
221 return str <<
'[' << obj.pair().first <<
"] = " << obj.pair().second;
225 template<
class TPair>
248 {
return mapEntry( pair_r ); }
251 typedef transform_iterator<Transformer, typename MapType::const_iterator>
274 std::ostream & operator<<( std::ostream & str, const DumpMap<TMap> & obj )
319 std::ostream & operator<<( std::ostream & str, const DumpKeys<TMap> & obj )
364 std::ostream & operator<<( std::ostream & str, const DumpValues<TMap> & obj )
377 using _logtoolsdetail::mapEntry;
378 using _logtoolsdetail::dumpMap;
379 using _logtoolsdetail::dumpKeys;
380 using _logtoolsdetail::dumpValues;
382 template<
class TKey,
class Tp>
383 std::ostream & operator<<( std::ostream & str, const std::map<TKey, Tp> & obj )
384 {
return str << dumpMap( obj ); }
386 template<
class TKey,
class Tp>
387 std::ostream & operator<<( std::ostream & str, const std::unordered_map<TKey, Tp> & obj )
388 {
return str << dumpMap( obj ); }
390 template<
class TKey,
class Tp>
391 std::ostream & operator<<( std::ostream & str, const std::multimap<TKey, Tp> & obj )
392 {
return str << dumpMap( obj ); }
403 inline std::ostream & operator<<( std::ostream & str, const std::basic_ios<char> & obj )
405 std::string ret(
"[" );
406 ret += ( obj.good() ?
'g' :
'_' );
407 ret += ( obj.eof() ?
'e' :
'_' );
408 ret += ( obj.fail() ?
'F' :
'_' );
409 ret += ( obj.bad() ?
'B' :
'_' );
429 std::ostream & operator<<( std::ostream & str, const Dump<Tp> & obj )
445 inline std::ostream &
hexdumpOn( std::ostream & outs,
const unsigned char *ptr,
size_t size )
448 unsigned width = 0x10;
449 outs <<
str::form(
"hexdump %10.10ld bytes (0x%8.8lx):\n", (
long)size, (
long)size );
451 for ( i = 0; i < size; i += width ) {
452 outs <<
str::form(
"%4.4lx: ", (
long)i );
454 for ( c = 0; c < width; ++c ) {
461 for ( c = 0; (c < width) && (i+c < size); ++c ) {
462 char x = (ptr[i+c] >= 0x20 && ptr[i+c] < 0x7f) ? ptr[i+c] :
'.';
470 inline std::ostream &
hexdumpOn( std::ostream & outs,
const char *ptr,
size_t size )
471 {
return hexdumpOn( outs, (
const unsigned char *)ptr, size ); }
475 #endif // ZYPP_BASE_LOGTOOLS_H
std::ostream & dumpOn(std::ostream &str, const PoolQueryIterator &obj)
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\ ", const std::string &sep="\ ", const std::string &sfx="\, const std::string &extro="}")
Print range defined by iterators (multiline style).
String related utilities and Regular expression matching.
transform_iterator< GetPairSecond< typename MapType::value_type >, typename MapType::const_iterator > Value_const_iterator
The value iterator type.
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_begin(const TMap &map_r)
Convenience to create the value iterator from container::begin()
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
MapKVIteratorTraits< TMap >::Key_const_iterator make_map_key_begin(const TMap &map_r)
Convenience to create the key iterator from container::begin()
MapEntry(const TPair &pair_r)
MapEntry< TPair > mapEntry(const TPair &pair_r)
std::pair wrapper for std::map output.
iomanip::RangeLine< TIterator > rangeLine(TIterator begin, TIterator end)
Iomanip printing dumpRangeLine style.
MapKVIteratorTraits< TMap >::Key_const_iterator make_map_key_end(const TMap &map_r)
Convenience to create the key iterator from container::end()
std::ostream & hexdumpOn(std::ostream &outs, const unsigned char *ptr, size_t size)
hexdump data on stream
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_end(const TMap &map_r)
Convenience to create the value iterator from container::end()
transform_iterator< GetPairFirst< typename MapType::value_type >, typename MapType::const_iterator > Key_const_iterator
The key iterator type.
const TPair & pair() const
std::ostream & dumpRangeLine(std::ostream &str, TIterator begin, TIterator end)
Print range defined by iterators (single line style).
RangeLine(TIterator begin, TIterator end)
Easy-to use interface to the ZYPP dependency resolver.
detail::Dump< Tp > dump(const Tp &obj_r)