00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_BASE_LOGTOOLS_H
00013 #define ZYPP_BASE_LOGTOOLS_H
00014
00015 #include <iostream>
00016 #include <string>
00017 #include <vector>
00018 #include <list>
00019 #include <set>
00020 #include "zypp/base/Logger.h"
00021
00023 namespace zypp
00024 {
00025
00044 template<class _Iterator>
00045 std::ostream & dumpRange( std::ostream & str,
00046 _Iterator begin, _Iterator end,
00047 const std::string & intro = "{",
00048 const std::string & pfx = "\n ",
00049 const std::string & sep = "\n ",
00050 const std::string & sfx = "\n",
00051 const std::string & extro = "}" )
00052 {
00053 str << intro;
00054 if ( begin != end )
00055 {
00056 str << pfx << *begin;
00057 for ( ++begin; begin != end; ++begin )
00058 str << sep << *begin;
00059 str << sfx;
00060 }
00061 return str << extro;
00062 }
00063
00064 template<class _Iterator>
00065 std::ostream & dumpRangeLine( std::ostream & str,
00066 _Iterator begin, _Iterator end )
00067 { return dumpRange( str, begin, end, "(", "", ", ", "", ")" ); }
00068
00069 template<class _Tp>
00070 std::ostream & operator<<( std::ostream & str, const std::vector<_Tp> & obj )
00071 { return dumpRange( str, obj.begin(), obj.end() ); }
00072
00073 template<class _Tp>
00074 std::ostream & operator<<( std::ostream & str, const std::set<_Tp> & obj )
00075 { return dumpRange( str, obj.begin(), obj.end() ); }
00076
00077 template<class _Tp>
00078 std::ostream & operator<<( std::ostream & str, const std::list<_Tp> & obj )
00079 { return dumpRange( str, obj.begin(), obj.end() ); }
00080
00090 inline std::ostream & operator<<( std::ostream & str, const std::basic_ios<char> & obj )
00091 {
00092 std::string ret( "[" );
00093 ret += ( obj.good() ? 'g' : '_' );
00094 ret += ( obj.eof() ? 'e' : '_' );
00095 ret += ( obj.fail() ? 'F' : '_' );
00096 ret += ( obj.bad() ? 'B' : '_' );
00097 ret += "]";
00098 return str << ret;
00099 }
00100
00102 }
00104 #endif // ZYPP_BASE_LOGTOOLS_H