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> 106 template<
class TIterator>
108 TIterator begin, TIterator end,
109 const std::string & intro =
"{",
110 const std::string & pfx =
"\n ",
111 const std::string & sep =
"\n ",
112 const std::string & sfx =
"\n",
113 const std::string & extro =
"}" )
118 str << pfx << *begin;
119 for ( ++begin; begin != end; ++begin )
120 str << sep << *begin;
129 template<
class TIterator>
131 TIterator begin, TIterator end )
132 {
return dumpRange(
str, begin, end,
"(",
"",
", ",
"",
")" ); }
134 template<
class TContainer>
146 template<
class TIterator>
158 template<
class TIterator>
159 std::ostream & operator<<( std::ostream & str, const RangeLine<TIterator> & obj )
172 template<
class TIterator>
176 template<
class TContainer>
178 {
return rangeLine( cont.begin(), cont.end() ); }
181 std::ostream & operator<<( std::ostream & str, const std::vector<Tp> & obj )
184 template<
class Tp,
class TCmp,
class TAlloc>
185 std::ostream & operator<<( std::ostream & str, const std::set<Tp,TCmp,TAlloc> & obj )
189 std::ostream & operator<<( std::ostream & str, const std::unordered_set<Tp> & obj )
193 std::ostream & operator<<( std::ostream & str, const std::multiset<Tp> & obj )
197 std::ostream & operator<<( std::ostream & str, const std::list<Tp> & obj )
201 std::ostream & operator<<( std::ostream & str, const Iterable<Tp> & obj )
205 namespace _logtoolsdetail
217 template<
class TPair>
233 template<
class TPair>
234 std::ostream & operator<<( std::ostream & str, const MapEntry<TPair> & obj )
236 return str <<
'[' << obj.pair().first <<
"] = " << obj.pair().second;
240 template<
class TPair>
263 {
return mapEntry( pair_r ); }
266 typedef transform_iterator<Transformer, typename MapType::const_iterator>
289 std::ostream & operator<<( std::ostream & str, const DumpMap<TMap> & obj )
334 std::ostream & operator<<( std::ostream & str, const DumpKeys<TMap> & obj )
379 std::ostream & operator<<( std::ostream & str, const DumpValues<TMap> & obj )
392 using _logtoolsdetail::mapEntry;
393 using _logtoolsdetail::dumpMap;
394 using _logtoolsdetail::dumpKeys;
395 using _logtoolsdetail::dumpValues;
397 template<
class TKey,
class Tp>
398 std::ostream & operator<<( std::ostream & str, const std::map<TKey, Tp> & obj )
399 {
return str << dumpMap( obj ); }
401 template<
class TKey,
class Tp>
402 std::ostream & operator<<( std::ostream & str, const std::unordered_map<TKey, Tp> & obj )
403 {
return str << dumpMap( obj ); }
405 template<
class TKey,
class Tp>
406 std::ostream & operator<<( std::ostream & str, const std::multimap<TKey, Tp> & obj )
407 {
return str << dumpMap( obj ); }
418 inline std::ostream & operator<<( std::ostream & str, const std::basic_ios<char> & obj )
420 std::string ret(
"[" );
421 ret += ( obj.good() ?
'g' :
'_' );
422 ret += ( obj.eof() ?
'e' :
'_' );
423 ret += ( obj.fail() ?
'F' :
'_' );
424 ret += ( obj.bad() ?
'B' :
'_' );
444 std::ostream & operator<<( std::ostream & str, const Dump<Tp> & obj )
460 inline std::ostream &
hexdumpOn( std::ostream & outs,
const unsigned char *ptr,
size_t size )
463 unsigned width = 0x10;
464 outs <<
str::form(
"hexdump %10.10ld bytes (0x%8.8lx):\n", (
long)size, (
long)size );
466 for ( i = 0; i < size; i += width ) {
467 outs <<
str::form(
"%4.4lx: ", (
long)i );
469 for ( c = 0; c < width; ++c ) {
476 for ( c = 0; (c < width) && (i+c < size); ++c ) {
477 char x = (ptr[i+c] >= 0x20 && ptr[i+c] < 0x7f) ? ptr[i+c] :
'.';
485 inline std::ostream &
hexdumpOn( std::ostream & outs,
const char *ptr,
size_t size )
486 {
return hexdumpOn( outs, (
const unsigned char *)ptr, size ); }
490 #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::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
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()
Helper to produce not-NL-terminated multi line output.
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)