12#ifndef ZYPP_BASE_LOGTOOLS_H
13#define ZYPP_BASE_LOGTOOLS_H
50 template <
typename T>
class RefStore;
100 template <
typename T>
102 {
return str << obj.
get(); }
139 template <
typename Intro,
typename Pfx,
typename Sep,
typename Sfx,
typename Extro,
typename Pel,
typename Sel>
195 template <
typename Intro,
typename Pfx,
typename Sep,
typename Sfx,
typename Extro,
typename Pel=NoPr
int,
typename Sel=NoPr
int>
196 constexpr auto makeJoinFormat(
Intro && intro,
Pfx && pfx,
Sep && sep,
Sfx && sfx,
Extro && extro,
Pel && pel =
Pel(),
Sel && sel =
Sel() ) ->
detail::JoinFormat<Intro,Pfx,Sep,Sfx,Extro,Pel,Sel>
197 {
return detail::JoinFormat<Intro,Pfx,Sep,Sfx,Extro,Pel,Sel>( std::forward<Intro>(intro), std::forward<Pfx>(pfx), std::forward<Sep>(sep), std::forward<Sfx>(sfx), std::forward<Extro>(extro), std::forward<Pel>(pel), std::forward<Sel>(sel) ); }
214 = makeJoinFormat(
"{",
"\n ",
"\n ",
"\n",
"}" );
218 template <
typename Ostream,
typename Format>
222 template <
typename Ostream,
typename Format,
typename First>
224 {
str << fmt._pel << std::forward<First>(first) << fmt._sel; }
226 template <
typename Ostream,
typename Format,
typename First,
typename... Args>
228 {
_joinSF(
str << fmt._pel << std::forward<First>(first) << fmt._sel << fmt._sep, fmt, std::forward<Args>(args)... ); }
233 template <
typename Ostream,
typename Format,
typename... Args>
237 if (
sizeof...(Args) ) {
249 template <
typename Ostream,
typename Format,
typename... Args>
251 {
return detail::joinSF(
str, std::forward<Format>(fmt), std::forward<Args>(args)... ); }
254 template <
typename Format,
typename... Args>
260 template <
typename Ostream,
typename... Args>
265 template <
typename... Args>
270 template <
typename Ostream,
typename... Args>
275 template <
typename... Args>
286 template <
typename Ostream,
typename Format>
293 template <
typename... Args>
303 #define pXXX zypp::str::detail::PrintFmt(XXX,zypp::str::FormatLine)
304 #define pDBG zypp::str::detail::PrintFmt(DBG,zypp::str::FormatLine)
305 #define pMIL zypp::str::detail::PrintFmt(MIL,zypp::str::FormatLine)
306 #define pWAR zypp::str::detail::PrintFmt(WAR,zypp::str::FormatLine)
307 #define pERR zypp::str::detail::PrintFmt(ERR,zypp::str::FormatLine)
308 #define pSEC zypp::str::detail::PrintFmt(SEC,zypp::str::FormatLine)
309 #define pINT zypp::str::detail::PrintFmt(INT,zypp::str::FormatLine)
310 #define pUSR zypp::str::detail::PrintFmt(USR,zypp::str::FormatLine)
312 #define wXXX zypp::str::detail::PrintFmt(XXX,zypp::str::FormatWords)
313 #define wDBG zypp::str::detail::PrintFmt(DBG,zypp::str::FormatWords)
314 #define wMIL zypp::str::detail::PrintFmt(MIL,zypp::str::FormatWords)
315 #define wWAR zypp::str::detail::PrintFmt(WAR,zypp::str::FormatWords)
316 #define wERR zypp::str::detail::PrintFmt(ERR,zypp::str::FormatWords)
317 #define wSEC zypp::str::detail::PrintFmt(SEC,zypp::str::FormatWords)
318 #define wINT zypp::str::detail::PrintFmt(INT,zypp::str::FormatWords)
319 #define wUSR zypp::str::detail::PrintFmt(USR,zypp::str::FormatWords)
403 template<
class TIterator>
405 TIterator begin, TIterator end,
406 const std::string & intro =
"{",
407 const std::string & pfx =
"\n ",
408 const std::string & sep =
"\n ",
409 const std::string & sfx =
"\n",
410 const std::string & extro =
"}" )
415 str << pfx << *begin;
416 for ( ++begin; begin != end; ++begin )
417 str << sep << *begin;
426 template<
class TIterator>
428 TIterator begin, TIterator end )
429 {
return dumpRange(
str, begin, end,
"(",
"",
", ",
"",
")" ); }
431 template<
class TContainer>
443 template<
class TIterator>
455 template<
class TIterator>
469 template<
class TIterator>
473 template<
class TContainer>
475 {
return rangeLine( cont.begin(), cont.end() ); }
481 std::ostream &
operator<<( std::ostream &
str,
const std::vector<Tp> & obj )
484 template<
class Tp,
class TCmp,
class TAlloc>
485 std::ostream &
operator<<( std::ostream &
str,
const std::set<Tp,TCmp,TAlloc> & obj )
489 std::ostream &
operator<<( std::ostream &
str,
const std::unordered_set<Tp> & obj )
493 std::ostream &
operator<<( std::ostream &
str,
const std::multiset<Tp> & obj )
520 template<
class TPair>
536 template<
class TPair>
539 return str <<
'[' << obj.
pair().first <<
"] = " << obj.
pair().second;
543 template<
class TPair>
702 template<
class TKey,
class Tp>
703 std::ostream &
operator<<( std::ostream &
str,
const std::map<TKey, Tp> & obj )
706 template<
class TKey,
class Tp>
707 std::ostream &
operator<<( std::ostream &
str,
const std::unordered_map<TKey, Tp> & obj )
710 template<
class TKey,
class Tp>
711 std::ostream &
operator<<( std::ostream &
str,
const std::multimap<TKey, Tp> & obj )
723 inline std::ostream &
operator<<( std::ostream &
str,
const std::basic_ios<char> & obj )
725 std::string ret(
"[" );
726 ret += ( obj.good() ?
'g' :
'_' );
727 ret += ( obj.eof() ?
'e' :
'_' );
728 ret += ( obj.fail() ?
'F' :
'_' );
729 ret += ( obj.bad() ?
'B' :
'_' );
768 inline std::ostream &
hexdumpOn( std::ostream & outs,
const unsigned char *ptr,
size_t size )
771 unsigned width = 0x10;
772 outs <<
str::form(
"hexdump %10.10ld bytes (0x%8.8lx):\n", (
long)size, (
long)size );
774 for ( i = 0; i < size; i += width ) {
775 outs <<
str::form(
"%4.4lx: ", (
long)i );
777 for ( c = 0; c < width; ++c ) {
784 for ( c = 0; (c < width) && (i+c < size); ++c ) {
785 char x = (ptr[i+c] >= 0x20 && ptr[i+c] < 0x7f) ? ptr[i+c] :
'.';
793 inline std::ostream &
hexdumpOn( std::ostream & outs,
const char *ptr,
size_t size )
794 {
return hexdumpOn( outs,
reinterpret_cast<const unsigned char*
>(ptr), size ); }
803 inline std::ostream &
operator<<( std::ostream &
str,
const std::type_info &info )
809 std::unique_ptr<char, void(*)(
void*)> res {
810 abi::__cxa_demangle(info.name(), NULL, NULL, &status),
813 return str << std::string((status==0) ? res.get() : info.name());
815 return str << info.name();
819#ifdef __cpp_lib_optional
821 inline std::ostream &
operator<<( std::ostream &
str,
const std::optional<Tp> & obj )
824 str <<
"opt(" << *obj <<
")";
Provides API related macros.
iterator_type begin() const
iterator_type end() const
std::pair wrapper for std::map output.
MapEntry(const TPair &pair_r)
const TPair & pair() const
std::ostream & operator<<(std::ostream &str, const MapEntry< TPair > &obj)
Stream output.
MapEntry< TPair > mapEntry(const TPair &pair_r)
Convenience function to create MapEntry from std::pair.
const PairType *const _pair
Helper to store a reference or move rvalues inside.
constexpr RefStore(RefStore &&rhs)
std::ostream & operator<<(std::ostream &str, const RefStore< T > &obj)
<T> Stream output
constexpr RefStore(T &&val_r)
constexpr auto makeRefStore(T &&t) -> RefStore< T >
<T> Create a RefStore for the argument.
RefStore(const RefStore &)=delete
std::ostream & operator<<(std::ostream &str, const std::vector< Tp > &obj)
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const Dump< Tp > &obj)
std::ostream & operator<<(std::ostream &str, const NoPrint &obj)
Ostream & joinSF(Ostream &str, Format &&fmt, Args &&... args)
Print args on ostreamlike str using JoinFormat fmt.
void _joinSF(Ostream &str, const Format &fmt)
constexpr auto FormatLine
' '-separated and NL-terminated!
std::string sprintf(Format &&fmt, Args &&... args)
Print Format fs string.
std::string sprint(Args &&... args)
Print words as string.
Ostream & printf(Ostream &str, Format &&fmt, Args &&... args)
Print Format on stream.
constexpr auto FormatList
One item per line NL-terminated!
constexpr auto FormatWords
' '-separated.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
constexpr auto FormatTuple
Tuple: (el, .., el).
Ostream & concat(Ostream &str, Args &&... args)
Concat words on stream.
Ostream & print(Ostream &str, Args &&... args)
Print words on stream.
std::string sconcat(Args &&... args)
Concat words as string.
constexpr auto FormatDumpRangeDefault
dumpRange default format: {}-enclosed and indented one item per line.
constexpr auto FormatConcat
Concatenated.
constexpr NoPrint noPrint
std::ostream & operator<<(std::ostream &str, const Exception &obj)
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().
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 & hexdumpOn(std::ostream &outs, const unsigned char *ptr, size_t size)
hexdump data on stream
detail::Dump< Tp > dump(const Tp &obj_r)
DumpMap< TMap > dumpMap(const TMap &map_r)
Convenience function to create DumpMap from std::map.
std::ostream & dumpOn(std::ostream &str, const OnMediaLocation &obj)
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.
transform_iterator< GetPairSecond< typename MapType::value_type >, typename MapType::const_iterator > Value_const_iterator
The value iterator type.
std::ostream & operator<<(std::ostream &str, const RangeLine< TIterator > &obj)
<TIterator>
RangeLine(TIterator begin, TIterator end)
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Store nothing print nothing.
PrintFmt(Ostream &str, const Format &fmt)
Ostream & operator()(Args &&... args)
RefStore(const RefStore &)=delete
constexpr RefStore(RefStore &&rhs)