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>
46 inline std::ostream &
operator<<( std::ostream &
str, MLSep & obj )
47 {
if ( obj._first ) obj._first =
false;
else str << endl;
return str; }
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>
149 RangeLine( TIterator begin, TIterator end )
158 template<
class TIterator>
159 std::ostream &
operator<<( std::ostream &
str,
const RangeLine<TIterator> & obj )
172 template<
class TIterator>
173 iomanip::RangeLine<TIterator>
rangeLine( TIterator begin, TIterator end )
174 {
return iomanip::RangeLine<TIterator>( begin, end ); }
176 template<
class TContainer>
177 auto rangeLine(
const TContainer & cont ) ->
decltype(
rangeLine( cont.begin(), cont.end() ) )
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>
241 MapEntry<TPair> mapEntry(
const TPair & pair_r )
242 {
return MapEntry<TPair>( pair_r ); }
257 typedef typename TMap::value_type
PairType;
263 {
return mapEntry( pair_r ); }
274 const TMap &
map()
const
278 {
return make_transform_iterator(
map().
begin(), Transformer() ); }
281 {
return make_transform_iterator(
map().
end(), Transformer() );}
284 const TMap *
const _map;
289 std::ostream &
operator<<( std::ostream &
str,
const DumpMap<TMap> & obj )
294 DumpMap<TMap> dumpMap(
const TMap & map_r )
295 {
return DumpMap<TMap>( map_r ); }
319 const TMap &
map()
const
329 const TMap *
const _map;
334 std::ostream &
operator<<( std::ostream &
str,
const DumpKeys<TMap> & obj )
339 DumpKeys<TMap> dumpKeys(
const TMap & map_r )
340 {
return DumpKeys<TMap>( map_r ); }
364 const TMap &
map()
const
374 const TMap *
const _map;
379 std::ostream &
operator<<( std::ostream &
str,
const DumpValues<TMap> & obj )
384 DumpValues<TMap> dumpValues(
const TMap & map_r )
385 {
return DumpValues<TMap>( map_r ); }
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' :
'_' );
439 Dump(
const Tp & obj_r ) :
_obj( obj_r ) {}
444 std::ostream &
operator<<( std::ostream &
str,
const Dump<Tp> & obj )
449 detail::Dump<Tp>
dump(
const Tp & obj_r )
450 {
return detail::Dump<Tp>(obj_r); }
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 ); }
MapEntry(const TPair &pair_r)
const TPair & pair() const
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &os, const SolutionActionList &actionlist)
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & dumpRangeLine(std::ostream &str, TIterator begin, TIterator end)
Print range defined by iterators (single line style).
MapKVIteratorTraits< TMap >::Key_const_iterator make_map_key_begin(const TMap &map_r)
Convenience to create the key iterator from container::begin()
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
iomanip::RangeLine< TIterator > rangeLine(TIterator begin, TIterator end)
Iomanip printing dumpRangeLine style.
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_begin(const TMap &map_r)
Convenience to create the value iterator from container::begin()
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
MapKVIteratorTraits< TMap >::Key_const_iterator make_map_key_end(const TMap &map_r)
Convenience to create the key iterator from container::end()
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_end(const TMap &map_r)
Convenience to create the value iterator from container::end()
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
std::ostream & hexdumpOn(std::ostream &outs, const unsigned char *ptr, size_t size)
hexdump data on stream
detail::Dump< Tp > dump(const Tp &obj_r)
transform_iterator< GetPairFirst< typename MapType::value_type >, typename MapType::const_iterator > Key_const_iterator
The key iterator type.
transform_iterator< GetPairSecond< typename MapType::value_type >, typename MapType::const_iterator > Value_const_iterator
The value iterator type.
RangeLine(TIterator begin, TIterator end)