- backup
[platform/upstream/libzypp.git] / devel / devel.ma / Printing.h
1 #ifndef MA_PRINTING_H
2 #define MA_PRINTING_H
3
4 #include <iostream>
5 #include <string>
6
7 #include "zypp/base/Logger.h"
8 #include "zypp/base/PtrTypes.h"
9 #include <zypp/base/String.h>
10 #include <zypp/base/Iterator.h>
11 #include <zypp/base/Algorithm.h>
12 #include <zypp/base/Functional.h>
13
14 ///////////////////////////////////////////////////////////////////
15
16 template<class _Tp>
17   struct Print : public std::unary_function<_Tp, bool>
18   {
19     bool operator()( const _Tp & obj )
20     {
21       USR << obj << std::endl;
22       return true;
23     }
24   };
25
26 template<class _Tp>
27   struct PrintPtr : public std::unary_function<_Tp, bool>
28   {
29     bool operator()( const _Tp & obj )
30     {
31       if ( obj )
32         USR << *obj << std::endl;
33       else
34         USR << "(NULL)" << std::endl;
35       return true;
36     }
37   };
38
39 template<class _Container>
40   void print( const _Container & c )
41   {
42     INT << c.size() << " " << __PRETTY_FUNCTION__ << std::endl;
43     std::for_each( c.begin(), c.end(),
44                    Print<typename _Container::value_type>() );
45   }
46
47 template<class _Container>
48   void printPtr( const _Container & c )
49   {
50     INT << c.size() << " " << __PRETTY_FUNCTION__ << std::endl;
51     std::for_each( c.begin(), c.end(),
52                    PrintPtr<typename _Container::value_type>() );
53   }
54
55 template<class _Container>
56   void printMK( const _Container & c )
57   {
58     for ( typename _Container::const_iterator it = c.begin(); it != c.end(); ++it )
59       {
60         USR << it->first << std::endl;
61       }
62   }
63 template<class _Container>
64   void printMV( const _Container & c )
65   {
66     for ( typename _Container::const_iterator it = c.begin(); it != c.end(); ++it )
67       {
68         USR << it->second << std::endl;
69       }
70   }
71
72 template<class _Container>
73   void printMKV( const _Container & c )
74   {
75     for ( typename _Container::const_iterator it = c.begin(); it != c.end(); ++it )
76       {
77         USR << it->first << '\t' << it->second << std::endl;
78       }
79   }
80
81 ///////////////////////////////////////////////////////////////////
82 #endif // MA_PRINTING_H