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>
134 RangeLine( TIterator begin, TIterator end )
143 template<
class TIterator>
144 std::ostream &
operator<<( std::ostream &
str,
const RangeLine<TIterator> & obj )
157 template<
class TIterator>
158 iomanip::RangeLine<TIterator>
rangeLine( TIterator begin, TIterator end )
159 {
return iomanip::RangeLine<TIterator>( begin, end ); }
161 template<
class TContainer>
162 auto rangeLine(
const TContainer & cont ) ->
decltype(
rangeLine( cont.begin(), cont.end() ) )
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>
210 const TPair &
pair()
const
214 const TPair *
const _pair;
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>
226 MapEntry<TPair> mapEntry(
const TPair & pair_r )
227 {
return MapEntry<TPair>( pair_r ); }
242 typedef typename TMap::value_type
PairType;
248 {
return mapEntry( pair_r ); }
259 const TMap &
map()
const
263 {
return make_transform_iterator(
map().
begin(), Transformer() ); }
266 {
return make_transform_iterator(
map().
end(), Transformer() );}
269 const TMap *
const _map;
274 std::ostream &
operator<<( std::ostream &
str,
const DumpMap<TMap> & obj )
279 DumpMap<TMap> dumpMap(
const TMap & map_r )
280 {
return DumpMap<TMap>( map_r ); }
304 const TMap &
map()
const
314 const TMap *
const _map;
319 std::ostream &
operator<<( std::ostream &
str,
const DumpKeys<TMap> & obj )
324 DumpKeys<TMap> dumpKeys(
const TMap & map_r )
325 {
return DumpKeys<TMap>( map_r ); }
349 const TMap &
map()
const
359 const TMap *
const _map;
364 std::ostream &
operator<<( std::ostream &
str,
const DumpValues<TMap> & obj )
369 DumpValues<TMap> dumpValues(
const TMap & map_r )
370 {
return DumpValues<TMap>( map_r ); }
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' :
'_' );
424 Dump(
const Tp & obj_r ) :
_obj( obj_r ) {}
429 std::ostream &
operator<<( std::ostream &
str,
const Dump<Tp> & obj )
434 detail::Dump<Tp>
dump(
const Tp & obj_r )
435 {
return detail::Dump<Tp>(obj_r); }
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 ); }
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)