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>
14 #include <zypp/PathInfo.h>
15 #include <zypp/SourceFactory.h>
16 #include <zypp/source/Builtin.h>
17 #include <zypp/source/susetags/SuseTagsImpl.h>
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>
28 #include <zypp/ResFilters.h>
29 #include <zypp/ResStatus.h>
30 #include <zypp/ResPool.h>
32 #include <zypp/ZYppFactory.h>
36 using namespace zypp::functor;
38 ///////////////////////////////////////////////////////////////////
43 ///////////////////////////////////////////////////////////////////
52 Counter( _IntT value_r )
53 : _value( _IntT( value_r ) )
59 operator const _IntT &() const
66 ///////////////////////////////////////////////////////////////////
68 template <class _Impl>
69 typename _Impl::ResType::Ptr fakeResKind( Resolvable::Ptr from_r )
71 // fake different kind based on NVRAD
72 NVRAD nvrad( from_r );
73 shared_ptr<_Impl> impl;
74 return detail::makeResolvableAndImpl( nvrad, impl );
77 ///////////////////////////////////////////////////////////////////
79 struct Rstats : public std::unary_function<ResObject::constPtr, void>
81 void operator()( ResObject::constPtr ptr )
84 ++_perKind[ptr->kind()];
87 typedef std::map<ResolvableTraits::KindType,Counter<unsigned> > KindMap;
88 Counter<unsigned> _total;
92 std::ostream & operator<<( std::ostream & str, const Rstats & obj )
94 str << "Total: " << obj._total;
95 for( Rstats::KindMap::const_iterator it = obj._perKind.begin(); it != obj._perKind.end(); ++it )
97 str << endl << " " << it->first << ":\t" << it->second;
102 ///////////////////////////////////////////////////////////////////
104 struct FakeConv : public std::unary_function<Resolvable::Ptr, void>
106 typedef pool::PoolItem ValueT;
107 typedef std::set<ValueT> ContainerT;
109 void operator()( Resolvable::Ptr ptr )
111 if ( ptr->name()[0] == 's' )
113 ptr = fakeResKind<detail::SelectionImpl>( ptr );
115 else if ( ptr->name()[0] == 'p' )
117 ptr = fakeResKind<detail::PatchImpl>( ptr );
119 _store.insert( ValueT(asKind<ResObject>(ptr)) );
124 typedef ContainerT::iterator IteratorT;
125 typedef ContainerT::const_iterator ConstIteratorT;
127 ConstIteratorT begin() const
128 { return _store.begin(); }
130 ConstIteratorT end() const
131 { return _store.end(); }
133 template<class _Filter>
134 filter_iterator<_Filter, ConstIteratorT> begin() const
135 { return make_filter_iterator( _Filter(), begin(), end() ); }
137 template<class _Filter>
138 filter_iterator<_Filter, ConstIteratorT> begin( _Filter f ) const
139 { return make_filter_iterator( f, begin(), end() ); }
141 template<class _Filter>
142 filter_iterator<_Filter, ConstIteratorT> end() const
143 { return make_filter_iterator( _Filter(), end(), end() ); }
145 template<class _Filter>
146 filter_iterator<_Filter, ConstIteratorT> end( _Filter f ) const
147 { return make_filter_iterator( f, end(), end() ); }
152 ///////////////////////////////////////////////////////////////////
156 /******************************************************************
158 ** FUNCTION NAME : main
159 ** FUNCTION TYPE : int
161 int main( int argc, char * argv[] )
163 INT << "===[START]==========================================" << endl;
164 string infile( "p" );
168 Source src( SourceFactory().createFrom( new source::susetags::SuseTagsImpl(infile) ) );
169 MIL << src.resolvables().size() << endl;
172 pool.insert( src.resolvables().begin(), src.resolvables().end() );
178 std::copy( src.resolvables().begin(), src.resolvables().end(),
179 make_function_output_iterator( functorRef(fakeconv) ) );
181 //for_each( src.resolvables().begin(), src.resolvables().end(),
182 // functorRef(fakeconv) );
184 Rstats rstats = Rstats();
185 for_each( fakeconv.begin( byKind<Package>() ),
186 fakeconv.end( byKind<Package>() ),
187 functorRef(rstats) );
189 MIL << rstats << endl;
191 FakeConv::ValueT it( *fakeconv.begin() );
192 SEC << it->kind() << it->name() << endl;
193 SEC << it.status() << endl;
196 ZYpp::Ptr appl( ZYppFactory().letsTest() );
200 INT << "===[END]============================================" << endl;