libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef ZYPP_SAT_SOLVITERMIXIN_H 00013 #define ZYPP_SAT_SOLVITERMIXIN_H 00014 00015 #include <iosfwd> 00016 00017 #include "zypp/base/PtrTypes.h" 00018 #include "zypp/base/Iterator.h" 00019 #include "zypp/base/Tr1hash.h" 00020 00021 #include "zypp/sat/Solvable.h" 00022 00024 namespace zypp 00025 { 00026 00027 class PoolItem; 00028 class asPoolItem; // transform functor 00029 00030 namespace ui 00031 { 00032 class asSelectable; // transform functor 00033 } 00034 00036 namespace sat 00037 { 00038 00039 class Solvable; 00040 class asSolvable; // transform functor 00041 00042 namespace solvitermixin_detail 00043 { 00049 struct UnifyByIdent 00050 { 00051 bool operator()( const Solvable & solv_r ) const; 00052 00053 typedef std::tr1::unordered_set<unsigned> Uset; 00054 UnifyByIdent() 00055 : _uset( new Uset ) 00056 {} 00057 shared_ptr<Uset> _uset; 00058 }; 00059 00060 00061 } // namespace solvitermixin_detail 00062 00063 00065 // 00066 // CLASS NAME : SolvIterMixin<Derived,DerivedSolvable_iterator> 00067 // 00121 template <class Derived,class DerivedSolvable_iterator> 00122 class SolvIterMixin 00123 { 00124 public: 00125 typedef size_t size_type; 00126 00127 public: 00134 bool empty() const 00135 { return( self().begin() == self().end() ); } 00136 00138 size_type size() const 00139 { size_type s = 0; for_( it, self().begin(), self().end() ) ++s; return s;} 00140 00142 template<class _Solv> 00143 bool contains( const _Solv & solv_r ) const 00144 { 00145 Solvable solv( asSolvable()( solv_r ) ); 00146 for_( it, self().begin(), self().end() ) 00147 if ( *it == solv ) 00148 return true; 00149 return false; 00150 } 00152 00153 public: 00156 typedef DerivedSolvable_iterator Solvable_iterator; 00157 Solvable_iterator solvableBegin() const 00158 { return self().begin(); } 00159 Solvable_iterator solvableEnd() const 00160 { return self().end(); } 00162 00165 typedef transform_iterator<asPoolItem,Solvable_iterator> PoolItem_iterator; 00166 PoolItem_iterator poolItemBegin() const 00167 { return make_transform_iterator( solvableBegin(), asPoolItem() ); } 00168 PoolItem_iterator poolItemEnd() const 00169 { return make_transform_iterator( solvableEnd(), asPoolItem() ); } 00171 00172 private: 00173 typedef filter_iterator<solvitermixin_detail::UnifyByIdent,Solvable_iterator> UnifiedSolvable_iterator; 00174 public: 00177 typedef transform_iterator<ui::asSelectable,UnifiedSolvable_iterator> Selectable_iterator; 00178 Selectable_iterator selectableBegin() const 00179 { return make_transform_iterator( unifiedSolvableBegin(), ui::asSelectable() ); } 00180 Selectable_iterator selectableEnd() const 00181 { return make_transform_iterator( unifiedSolvableEnd(), ui::asSelectable() ); } 00183 00184 private: 00187 UnifiedSolvable_iterator unifiedSolvableBegin() const 00188 { return make_filter_iterator( solvitermixin_detail::UnifyByIdent(), solvableBegin(), solvableEnd() ); } 00189 UnifiedSolvable_iterator unifiedSolvableEnd() const 00190 { return make_filter_iterator( solvitermixin_detail::UnifyByIdent(), solvableEnd(), solvableEnd() );; } 00192 private: 00193 const Derived & self() const 00194 { return *static_cast<const Derived*>( this ); } 00195 protected: 00196 SolvIterMixin() {} 00197 ~SolvIterMixin() {} 00198 SolvIterMixin(const SolvIterMixin &) {} 00199 void operator=(const SolvIterMixin &) {} 00200 }; 00202 00204 } // namespace sat 00207 } // namespace zypp 00209 #endif // ZYPP_SAT_SOLVITERMIXIN_H