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>
34 using namespace zypp::functor;
36 ///////////////////////////////////////////////////////////////////
41 ///////////////////////////////////////////////////////////////////
50 Counter( _IntT value_r )
51 : _value( _IntT( value_r ) )
57 operator const _IntT &() const
64 ///////////////////////////////////////////////////////////////////
66 template <class _Impl>
67 typename _Impl::ResType::Ptr fakeResKind( Resolvable::Ptr from_r )
69 // fake different kind based on NVRAD
70 NVRAD nvrad( from_r );
71 shared_ptr<_Impl> impl;
72 return detail::makeResolvableAndImpl( nvrad, impl );
75 ///////////////////////////////////////////////////////////////////
77 struct Rstats : public std::unary_function<ResObject::constPtr, void>
79 void operator()( ResObject::constPtr ptr )
82 ++_perKind[ptr->kind()];
85 typedef std::map<ResolvableTraits::KindType,Counter<unsigned> > KindMap;
86 Counter<unsigned> _total;
90 std::ostream & operator<<( std::ostream & str, const Rstats & obj )
92 str << "Total: " << obj._total;
93 for( Rstats::KindMap::const_iterator it = obj._perKind.begin(); it != obj._perKind.end(); ++it )
95 str << endl << " " << it->first << ":\t" << it->second;
100 ///////////////////////////////////////////////////////////////////
104 SelItem( ResObject::Ptr ptr_r )
112 operator ResObject::Ptr()
115 operator ResObject::constPtr() const
118 ResObject::Ptr operator->()
121 ResObject::constPtr operator->() const
124 bool operator<( const SelItem & rhs ) const
125 { return _ptr < rhs._ptr; }
129 struct FakeConv : public std::unary_function<Resolvable::Ptr, void>
131 void operator()( Resolvable::Ptr ptr )
133 if ( ptr->name()[0] == 's' )
135 ptr = fakeResKind<detail::SelectionImpl>( ptr );
137 else if ( ptr->name()[0] == 'p' )
139 ptr = fakeResKind<detail::PatchImpl>( ptr );
141 _store.insert( SelItem(asKind<ResObject>(ptr)) );
145 typedef SelItem ValueT;
146 typedef std::set<ValueT> ContainerT;
150 typedef ContainerT::iterator IteratorT;
151 typedef ContainerT::const_iterator ConstIteratorT;
153 ConstIteratorT begin() const
154 { return _store.begin(); }
156 ConstIteratorT end() const
157 { return _store.end(); }
159 template<class _Filter>
160 filter_iterator<_Filter, ConstIteratorT> begin() const
161 { return make_filter_iterator( _Filter(), begin(), end() ); }
163 template<class _Filter>
164 filter_iterator<_Filter, ConstIteratorT> begin( _Filter f ) const
165 { return make_filter_iterator( f, begin(), end() ); }
167 template<class _Filter>
168 filter_iterator<_Filter, ConstIteratorT> end() const
169 { return make_filter_iterator( _Filter(), end(), end() ); }
171 template<class _Filter>
172 filter_iterator<_Filter, ConstIteratorT> end( _Filter f ) const
173 { return make_filter_iterator( f, end(), end() ); }
178 ///////////////////////////////////////////////////////////////////
180 /******************************************************************
182 ** FUNCTION NAME : main
183 ** FUNCTION TYPE : int
185 int main( int argc, char * argv[] )
187 INT << "===[START]==========================================" << endl;
188 string infile( "p" );
192 Source src( SourceFactory().createFrom( new source::susetags::SuseTagsImpl(infile) ) );
193 MIL << src.resolvables().size() << endl;
196 for_each( src.resolvables().begin(), src.resolvables().end(), functorRef(fakeconv) );
198 Rstats rstats = Rstats();
199 for_each( fakeconv.begin( byKind<Package>() ),
200 fakeconv.end( byKind<Package>() ),
201 functorRef(rstats) );
202 MIL << rstats << endl;
204 SelItem it( *fakeconv.begin() );
205 SEC << it->kind() << it->name() << endl;
208 INT << "===[END]============================================" << endl;