LookupAttrTools.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_SAT_LOOKUPATTRTOOLS_H
00013 #define ZYPP_SAT_LOOKUPATTRTOOLS_H
00014
00015 #include "zypp/sat/LookupAttr.h"
00016 #include "zypp/Repository.h"
00017
00019 namespace zypp
00020 {
00021
00022 namespace sat
00023 {
00024
00026
00027
00028
00055 template<class _ResultT, class _AttrT>
00056 class LookupAttr::transformIterator : public boost::iterator_adaptor<
00057 transformIterator<_ResultT,_AttrT>
00058 , LookupAttr::iterator
00059 , _ResultT
00060 , boost::forward_traversal_tag
00061 , _ResultT
00062 >
00063 {
00064 public:
00065 transformIterator()
00066 {}
00067
00068 explicit
00069 transformIterator( const LookupAttr::iterator & val_r )
00070 { this->base_reference() = val_r; }
00071
00072 public:
00073
00077 void nextSkipSolvAttr()
00078 { this->base_reference().nextSkipSolvAttr(); }
00079
00081 void nextSkipSolvable()
00082 { this->base_reference().nextSkipSolvable(); }
00083
00085 void nextSkipRepo()
00086 { this->base_reference().nextSkipRepo(); }
00087
00089 void skipSolvAttr()
00090 { this->base_reference().skipSolvAttr(); }
00091
00093 void skipSolvable()
00094 { this->base_reference().skipSolvable(); }
00095
00097 void skipRepo()
00098 { this->base_reference().skipRepo(); }
00100
00104 Repository inRepo() const
00105 { return this->base_reference().inRepo(); }
00106
00108 Solvable inSolvable() const
00109 { return this->base_reference().inSolvable(); }
00110
00112 SolvAttr inSolvAttr() const
00113 { return this->base_reference().inSolvAttr(); }
00115
00116 private:
00117 friend class boost::iterator_core_access;
00118
00119 _ResultT dereference() const
00120 {
00121 const LookupAttr::iterator lit( this->base_reference() );
00122 return _ResultT( lit.asType<_AttrT>() );
00123 }
00124 };
00126
00127 template<class _ResultT, class _AttrT>
00128 class ArrayAttr;
00129
00130 template<class _ResultT, class _AttrT>
00131 std::ostream & operator<<( std::ostream & str, const ArrayAttr<_ResultT,_AttrT> & obj );
00132
00134
00135
00136
00153 template<class _ResultT, class _AttrT>
00154 class ArrayAttr
00155 {
00156 friend std::ostream & operator<< <_ResultT,_AttrT>( std::ostream & str, const ArrayAttr<_ResultT,_AttrT> & obj );
00157
00158 public:
00159 ArrayAttr()
00160 {}
00161
00162 ArrayAttr( SolvAttr attr_r, LookupAttr::Location loc_r = LookupAttr::SOLV_ATTR )
00163 : _q( attr_r, loc_r )
00164 {}
00165
00166 ArrayAttr( SolvAttr attr_r, Repository repo_r, LookupAttr::Location loc_r = LookupAttr::SOLV_ATTR )
00167 : _q( attr_r, repo_r, loc_r )
00168 {}
00169
00170 ArrayAttr( SolvAttr attr_r, Solvable solv_r )
00171 : _q( attr_r, solv_r )
00172 {}
00173
00174 public:
00175 typedef LookupAttr::transformIterator<_ResultT,_AttrT> iterator;
00176 typedef LookupAttr::size_type size_type;
00177
00178 iterator begin() const
00179 { return iterator( _q.begin() ); }
00180
00181 iterator end() const
00182 { return iterator( _q.end() ); }
00183
00184 bool empty() const
00185 { return _q.empty(); }
00186
00187 size_type size() const
00188 {
00189 size_type count = 0;
00190 for_( it, begin(), end() )
00191 ++count;
00192 return count;
00193 }
00194
00195 public:
00196
00197 iterator find( const _ResultT & key_r ) const
00198 {
00199 for_( it, begin(), end() )
00200 {
00201 if ( *it == key_r )
00202 return it;
00203 }
00204 return end();
00205 }
00206
00207 private:
00208 LookupAttr _q;
00209 };
00211
00213 template<class _ResultT, class _AttrT>
00214 inline std::ostream & operator<<( std::ostream & str, const ArrayAttr<_ResultT,_AttrT> & obj )
00215 { return dumpOn( str, obj._q ); }
00216
00218 }
00221 }
00223 #endif // ZYPP_SAT_LOOKUPATTRTOOLS_H