12 #ifndef ZYPP_BASE_LOGTOOLS_H 13 #define ZYPP_BASE_LOGTOOLS_H 119 template<
class TIterator>
121 TIterator begin, TIterator end,
122 const std::string & intro =
"{",
123 const std::string & pfx =
"\n ",
124 const std::string & sep =
"\n ",
125 const std::string & sfx =
"\n",
126 const std::string & extro =
"}" )
131 str << pfx << *begin;
132 for ( ++begin; begin != end; ++begin )
133 str << sep << *begin;
142 template<
class TIterator>
144 TIterator begin, TIterator end )
145 {
return dumpRange(
str, begin, end,
"(",
"",
", ",
"",
")" ); }
147 template<
class TContainer>
159 template<
class TIterator>
171 template<
class TIterator>
172 std::ostream & operator<<( std::ostream & str, const RangeLine<TIterator> & obj )
185 template<
class TIterator>
189 template<
class TContainer>
191 {
return rangeLine( cont.begin(), cont.end() ); }
194 std::ostream & operator<<( std::ostream & str, const std::vector<Tp> & obj )
197 template<
class Tp,
class TCmp,
class TAlloc>
198 std::ostream & operator<<( std::ostream & str, const std::set<Tp,TCmp,TAlloc> & obj )
202 std::ostream & operator<<( std::ostream & str, const std::unordered_set<Tp> & obj )
206 std::ostream & operator<<( std::ostream & str, const std::multiset<Tp> & obj )
210 std::ostream & operator<<( std::ostream & str, const std::list<Tp> & obj )
214 std::ostream & operator<<( std::ostream & str, const Iterable<Tp> & obj )
218 namespace _logtoolsdetail
230 template<
class TPair>
246 template<
class TPair>
247 std::ostream & operator<<( std::ostream & str, const MapEntry<TPair> & obj )
249 return str <<
'[' << obj.pair().first <<
"] = " << obj.pair().second;
253 template<
class TPair>
276 {
return mapEntry( pair_r ); }
301 std::ostream & operator<<( std::ostream & str, const DumpMap<TMap> & obj )
346 std::ostream & operator<<( std::ostream & str, const DumpKeys<TMap> & obj )
391 std::ostream & operator<<( std::ostream & str, const DumpValues<TMap> & obj )
404 using _logtoolsdetail::mapEntry;
405 using _logtoolsdetail::dumpMap;
406 using _logtoolsdetail::dumpKeys;
407 using _logtoolsdetail::dumpValues;
409 template<
class TKey,
class Tp>
410 std::ostream & operator<<( std::ostream & str, const std::map<TKey, Tp> & obj )
411 {
return str << dumpMap( obj ); }
413 template<
class TKey,
class Tp>
414 std::ostream & operator<<( std::ostream & str, const std::unordered_map<TKey, Tp> & obj )
415 {
return str << dumpMap( obj ); }
417 template<
class TKey,
class Tp>
418 std::ostream & operator<<( std::ostream & str, const std::multimap<TKey, Tp> & obj )
419 {
return str << dumpMap( obj ); }
430 inline std::ostream & operator<<( std::ostream & str, const std::basic_ios<char> & obj )
432 std::string ret(
"[" );
433 ret += ( obj.good() ?
'g' :
'_' );
434 ret += ( obj.eof() ?
'e' :
'_' );
435 ret += ( obj.fail() ?
'F' :
'_' );
436 ret += ( obj.bad() ?
'B' :
'_' );
456 std::ostream & operator<<( std::ostream & str, const Dump<Tp> & obj )
472 inline std::ostream &
hexdumpOn( std::ostream & outs,
const unsigned char *ptr,
size_t size )
475 unsigned width = 0x10;
476 outs <<
str::form(
"hexdump %10.10ld bytes (0x%8.8lx):\n", (
long)size, (
long)size );
478 for ( i = 0; i < size; i += width ) {
479 outs <<
str::form(
"%4.4lx: ", (
long)i );
481 for ( c = 0; c < width; ++c ) {
488 for ( c = 0; (c < width) && (i+c < size); ++c ) {
489 char x = (ptr[i+c] >= 0x20 && ptr[i+c] < 0x7f) ? ptr[i+c] :
'.';
497 inline std::ostream &
hexdumpOn( std::ostream & outs,
const char *ptr,
size_t size )
498 {
return hexdumpOn( outs, (
const unsigned char *)ptr, size ); }
504 inline std::ostream &
operator<<( std::ostream &
str,
const std::type_info &info )
510 std::unique_ptr<char, void(*)(void*)> res {
511 abi::__cxa_demangle(info.name(), NULL, NULL, &status),
514 return str << std::string((status==0) ? res.get() : info.name());
516 return str << info.name();
520 #ifdef __cpp_lib_optional // YAST/PK explicitly use c++11 until 15-SP3 522 inline std::ostream & operator<<( std::ostream & str, const std::optional<Tp> & obj )
525 str <<
"opt(" << *obj <<
")";
536 #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.
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)
Provides API related macros.
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()
transform_iterator< GetPairFirst< typename MapType::value_type >, typename MapType::const_iterator > Key_const_iterator
The key iterator type.
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< GetPairSecond< typename MapType::value_type >, typename MapType::const_iterator > Value_const_iterator
The value 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)