8ae48cb02c20737a60e6b34279e9560845d1d00d
[platform/upstream/libzypp.git] / devel / devel.ma / Printing.h
1 #ifndef MA_PRINTING_H
2 #define MA_PRINTING_H
3
4 #include <iostream>
5
6 #include "zypp/base/LogControl.h"
7 #include "zypp/base/LogTools.h"
8 #include <zypp/base/Logger.h>
9
10 #include <zypp/base/String.h>
11 #include <zypp/base/Iterator.h>
12 #include <zypp/base/Algorithm.h>
13 #include <zypp/base/Functional.h>
14
15 ///////////////////////////////////////////////////////////////////
16 #if 0
17 ///////////////////////////////////////////////////////////////////
18 struct FormatStream
19 {
20   explicit
21   FormatStream( std::ostream & stream_r )
22   : _stream( stream_r )
23   {}
24
25   FormatStream & operator<<( std::ostream & (*fnc)( std::ostream & ) )
26   { _stream << fnc; return *this; }
27
28   template<class _Tp>
29     FormatStream & operator<<( const _Tp & obj )
30     { _stream << "@(" << obj << ")@"; return *this; }
31
32   std::ostream & _stream;
33 };
34 ///////////////////////////////////////////////////////////////////
35 #undef XXX
36 #undef DBG
37 #undef MIL
38 #undef WAR
39 #undef ERR
40 #undef SEC
41 #undef INT
42 #undef USR
43
44 #define XXX FormatStream(_XXX( ZYPP_BASE_LOGGER_LOGGROUP ))
45 #define DBG FormatStream(_DBG( ZYPP_BASE_LOGGER_LOGGROUP ))
46 #define MIL FormatStream(_MIL( ZYPP_BASE_LOGGER_LOGGROUP ))
47 #define WAR FormatStream(_WAR( ZYPP_BASE_LOGGER_LOGGROUP ))
48 #define ERR FormatStream(_ERR( ZYPP_BASE_LOGGER_LOGGROUP ))
49 #define SEC FormatStream(_SEC( ZYPP_BASE_LOGGER_LOGGROUP ))
50 #define INT FormatStream(_INT( ZYPP_BASE_LOGGER_LOGGROUP ))
51 #define USR FormatStream(_USR( ZYPP_BASE_LOGGER_LOGGROUP ))
52 ///////////////////////////////////////////////////////////////////
53 #endif
54 ///////////////////////////////////////////////////////////////////
55
56
57 template<class _Tp>
58   struct PrintOn : public std::unary_function<_Tp, bool>
59   {
60     bool operator()( const _Tp & obj ) const
61     {
62       if ( _leadNL )
63         _str << std::endl << _prfx << obj;
64       else
65         _str << _prfx << obj << std::endl;
66       return true;
67     }
68
69     PrintOn( std::ostream & str, const std::string & prfx = std::string(), bool leadNL = false )
70     : _str( str )
71     , _prfx( prfx )
72     , _leadNL( leadNL )
73     {}
74
75     std::ostream & _str;
76     std::string _prfx;
77     bool _leadNL;
78   };
79
80 ///////////////////////////////////////////////////////////////////
81 #endif // MA_PRINTING_H