backup
[platform/upstream/libzypp.git] / devel / devel.ma / Main.cc
1 #include <ctime>
2
3 #include <iostream>
4 #include <list>
5 #include <map>
6 #include <set>
7
8 #include <zypp/base/Logger.h>
9 #include <zypp/base/String.h>
10 #include <zypp/base/Exception.h>
11 #include <zypp/base/PtrTypes.h>
12 #include <zypp/base/Iterator.h>
13
14 #include <zypp/PathInfo.h>
15 #include <zypp/SourceFactory.h>
16 #include <zypp/source/Builtin.h>
17 #include <zypp/source/susetags/SuseTagsImpl.h>
18
19 #include <zypp/Resolvable.h>
20 #include <zypp/Package.h>
21 #include <zypp/detail/PackageImpl.h>
22 #include <zypp/Selection.h>
23 #include <zypp/detail/SelectionImpl.h>
24 #include <zypp/Patch.h>
25 #include <zypp/detail/PatchImpl.h>
26
27
28 #include <zypp/ResFilters.h>
29 #include <zypp/ResStatus.h>
30 #include <zypp/ResPool.h>
31
32 #include <zypp/ZYppFactory.h>
33
34 using namespace std;
35 using namespace zypp;
36 using namespace zypp::functor;
37
38 ///////////////////////////////////////////////////////////////////
39 namespace zypp
40 {
41
42 }
43 ///////////////////////////////////////////////////////////////////
44
45 template<class _IntT>
46   struct Counter
47   {
48     Counter()
49     : _value( _IntT(0) )
50     {}
51
52     Counter( _IntT value_r )
53     : _value( _IntT( value_r ) )
54     {}
55
56     operator _IntT &()
57     { return _value; }
58
59     operator const _IntT &() const
60     { return _value; }
61
62     _IntT _value;
63   };
64
65
66 ///////////////////////////////////////////////////////////////////
67
68 template <class _Impl>
69   typename _Impl::ResType::Ptr fakeResKind( Resolvable::Ptr from_r )
70   {
71     // fake different kind based on NVRAD
72     NVRAD nvrad( from_r );
73     shared_ptr<_Impl> impl;
74     return detail::makeResolvableAndImpl( nvrad, impl );
75   }
76
77 ///////////////////////////////////////////////////////////////////
78
79 struct Rstats : public std::unary_function<ResObject::constPtr, void>
80 {
81   void operator()( ResObject::constPtr ptr )
82   {
83     ++_total;
84     ++_perKind[ptr->kind()];
85   }
86
87   typedef std::map<ResolvableTraits::KindType,Counter<unsigned> > KindMap;
88   Counter<unsigned> _total;
89   KindMap           _perKind;
90 };
91
92 std::ostream & operator<<( std::ostream & str, const Rstats & obj )
93 {
94   str << "Total: " << obj._total;
95   for( Rstats::KindMap::const_iterator it = obj._perKind.begin(); it != obj._perKind.end(); ++it )
96     {
97       str << endl << "  " << it->first << ":\t" << it->second;
98     }
99   return str;
100 }
101
102 ///////////////////////////////////////////////////////////////////
103
104 struct FakeConv : public std::unary_function<Resolvable::Ptr, void>
105 {
106   typedef pool::PoolItem    ValueT;
107   typedef std::set<ValueT>  ContainerT;
108
109   void operator()( Resolvable::Ptr ptr )
110   {
111     if ( ptr->name()[0] == 's' )
112       {
113         ptr = fakeResKind<detail::SelectionImpl>( ptr );
114       }
115     else if ( ptr->name()[0] == 'p' )
116       {
117         ptr = fakeResKind<detail::PatchImpl>( ptr );
118       }
119     _store.insert( ValueT(asKind<ResObject>(ptr)) );
120   }
121
122   ContainerT _store;
123
124   typedef ContainerT::iterator       IteratorT;
125   typedef ContainerT::const_iterator ConstIteratorT;
126
127   ConstIteratorT begin() const
128   { return _store.begin(); }
129
130   ConstIteratorT end() const
131   { return _store.end(); }
132
133   template<class _Filter>
134     filter_iterator<_Filter, ConstIteratorT> begin() const
135     { return make_filter_iterator( _Filter(), begin(), end() ); }
136
137   template<class _Filter>
138     filter_iterator<_Filter, ConstIteratorT> begin( _Filter f ) const
139     { return make_filter_iterator( f, begin(), end() ); }
140
141   template<class _Filter>
142     filter_iterator<_Filter, ConstIteratorT> end() const
143     { return make_filter_iterator( _Filter(), end(), end() ); }
144
145   template<class _Filter>
146     filter_iterator<_Filter, ConstIteratorT> end( _Filter f ) const
147     { return make_filter_iterator( f, end(), end() ); }
148
149
150 };
151
152 ///////////////////////////////////////////////////////////////////
153
154
155
156 /******************************************************************
157 **
158 **      FUNCTION NAME : main
159 **      FUNCTION TYPE : int
160 */
161 int main( int argc, char * argv[] )
162 {
163   INT << "===[START]==========================================" << endl;
164   string infile( "p" );
165   if (argc >= 2 )
166     infile = argv[1];
167
168   Source src( SourceFactory().createFrom( new source::susetags::SuseTagsImpl(infile) ) );
169   MIL << src.resolvables().size() << endl;
170
171   ResPool pool;
172   pool.insert( src.resolvables().begin(), src.resolvables().end() );
173   MIL << pool << endl;
174
175 #if 0
176   FakeConv fakeconv;
177
178   std::copy( src.resolvables().begin(), src.resolvables().end(),
179              make_function_output_iterator( functorRef(fakeconv) ) );
180
181   //for_each( src.resolvables().begin(), src.resolvables().end(),
182   //          functorRef(fakeconv) );
183
184   Rstats rstats = Rstats();
185   for_each( fakeconv.begin( byKind<Package>() ),
186             fakeconv.end( byKind<Package>() ),
187             functorRef(rstats) );
188
189   MIL << rstats << endl;
190
191   FakeConv::ValueT it( *fakeconv.begin() );
192   SEC << it->kind() << it->name() << endl;
193   SEC << it.status() << endl;
194 #endif
195
196   ZYpp::Ptr appl( ZYppFactory().letsTest() );
197   MIL << *appl;
198
199
200   INT << "===[END]============================================" << endl;
201   return 0;
202 }
203