Imported Upstream version 14.45.0
[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 using std::endl;
16
17 ///////////////////////////////////////////////////////////////////
18
19 struct Print
20 {
21   template<class _Tp>
22     bool operator()( const _Tp & val_r ) const
23     { USR << val_r << endl; return true; }
24 };
25
26 ///////////////////////////////////////////////////////////////////
27
28 template<class _Tp>
29   struct PrintOn : public std::unary_function<_Tp, bool>
30   {
31     bool operator()( const _Tp & obj ) const
32     {
33       if ( _leadNL )
34         _str << std::endl << _prfx << obj;
35       else
36         _str << _prfx << obj << std::endl;
37       return true;
38     }
39
40     PrintOn( std::ostream & str, const std::string & prfx = std::string(), bool leadNL = false )
41     : _str( str )
42     , _prfx( prfx )
43     , _leadNL( leadNL )
44     {}
45
46     std::ostream & _str;
47     std::string _prfx;
48     bool _leadNL;
49   };
50
51 ///////////////////////////////////////////////////////////////////
52 #endif // MA_PRINTING_H