1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/LookupAttrTools.h
12 #ifndef ZYPP_SAT_LOOKUPATTRTOOLS_H
13 #define ZYPP_SAT_LOOKUPATTRTOOLS_H
15 #include "zypp/sat/LookupAttr.h"
16 #include "zypp/Repository.h"
18 ///////////////////////////////////////////////////////////////////
20 { /////////////////////////////////////////////////////////////////
21 ///////////////////////////////////////////////////////////////////
23 { /////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
27 // CLASS NAME : LookupAttr::TransformIterator
29 /** TransformIterator returning an \ref iterator value of type \c TResult.
31 * The underlying LookupAttr::iterators value is retrieved \ref asType<TAttr>
32 * and the returned \ref ResultT is constructed fron that value.
38 * Keywords( sat::Solvable solv_r )
39 * : _q( sat::SolvAttr::keywords, solv_r )
43 * typedef sat::LookupAttr::TransformIterator<PackageKeyword,IdString> iterator;
45 * iterator begin() const { return iterator( _q.begin() ); }
46 * iterator end() const { return iterator( _q.end() ); }
53 * \see \ref ArrayAttr.
55 template<class TResult, class TAttr>
56 class LookupAttr::TransformIterator : public boost::iterator_adaptor<
57 TransformIterator<TResult,TAttr> // Derived
58 , LookupAttr::iterator // Base
60 , boost::forward_traversal_tag // CategoryOrTraversal
61 , TResult // Reference
69 TransformIterator( const LookupAttr::iterator & val_r )
70 { this->base_reference() = val_r; }
74 /** \name Moving fast forward. */
76 /** On the next call to \ref operator++ advance to the next \ref SolvAttr. */
77 void nextSkipSolvAttr()
78 { this->base_reference().nextSkipSolvAttr(); }
80 /** On the next call to \ref operator++ advance to the next \ref Solvable. */
81 void nextSkipSolvable()
82 { this->base_reference().nextSkipSolvable(); }
84 /** On the next call to \ref operator++ advance to the next \ref Repository. */
86 { this->base_reference().nextSkipRepo(); }
88 /** Immediately advance to the next \ref SolvAttr. */
90 { this->base_reference().skipSolvAttr(); }
92 /** Immediately advance to the next \ref Solvable. */
94 { this->base_reference().skipSolvable(); }
96 /** Immediately advance to the next \ref Repository. */
98 { this->base_reference().skipRepo(); }
101 /** \name Current position info. */
103 /** The current \ref Repository. */
104 Repository inRepo() const
105 { return this->base_reference().inRepo(); }
107 /** The current \ref Solvabele. */
108 Solvable inSolvable() const
109 { return this->base_reference().inSolvable(); }
111 /** The current \ref SolvAttr. */
112 SolvAttr inSolvAttr() const
113 { return this->base_reference().inSolvAttr(); }
117 friend class boost::iterator_core_access;
119 TResult dereference() const
121 const LookupAttr::iterator lit( this->base_reference() );
122 return TResult( lit.asType<TAttr>() );
125 ///////////////////////////////////////////////////////////////////
127 template<class TResult, class TAttr>
130 template<class TResult, class TAttr>
131 std::ostream & operator<<( std::ostream & str, const ArrayAttr<TResult,TAttr> & obj );
133 ///////////////////////////////////////////////////////////////////
135 // CLASS NAME : ArrayAttr
137 /** \ref LookupAttr::TransformIterator based container to retrieve list attributes.
139 * You may pass \ref LookupAttr::REPO_ATTR as \ref LookupAttr::Location argument,
140 * to lookup attributes associated with the \ref Repository as a whole
141 * (e.g. repository keywords).
143 * \see \ref LookupAttr for details.
146 * typedef ArrayAttr<PackageKeyword,IdString> Keywords;
147 * Keywords k( sat::SolvAttr::keywords );
148 * dumpRange( MIL << "All Keywords: ", k.begin(), k.end() ) << endl;
151 * \todo Maybe add some way to unify the result.
153 template<class TResult, class TAttr>
156 friend std::ostream & operator<< <TResult,TAttr>( std::ostream & str, const ArrayAttr<TResult,TAttr> & obj );
162 ArrayAttr( SolvAttr attr_r, LookupAttr::Location loc_r = LookupAttr::SOLV_ATTR )
163 : _q( attr_r, loc_r )
166 ArrayAttr( SolvAttr attr_r, Repository repo_r, LookupAttr::Location loc_r = LookupAttr::SOLV_ATTR )
167 : _q( attr_r, repo_r, loc_r )
170 ArrayAttr( SolvAttr attr_r, Solvable solv_r )
171 : _q( attr_r, solv_r )
175 typedef LookupAttr::TransformIterator<TResult,TAttr> iterator;
176 typedef LookupAttr::size_type size_type;
178 iterator begin() const
179 { return iterator( _q.begin() ); }
182 { return iterator( _q.end() ); }
185 { return _q.empty(); }
187 size_type size() const
190 for_( it, begin(), end() )
197 iterator find( const TResult & key_r ) const
199 for_( it, begin(), end() )
210 ///////////////////////////////////////////////////////////////////
212 /** \relates LookupAttr::iterator Stream output. */
213 template<class TResult, class TAttr>
214 inline std::ostream & operator<<( std::ostream & str, const ArrayAttr<TResult,TAttr> & obj )
215 { return dumpOn( str, obj._q ); }
217 /////////////////////////////////////////////////////////////////
219 ///////////////////////////////////////////////////////////////////
220 /////////////////////////////////////////////////////////////////
222 ///////////////////////////////////////////////////////////////////
223 #endif // ZYPP_SAT_LOOKUPATTRTOOLS_H