1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/PoolQuery.h
12 #ifndef ZYPP_POOLQUERY_H
13 #define ZYPP_POOLQUERY_H
15 #include "zypp/ui/Selectable.h"
16 #include "zypp/sat/SolvAttr.h"
18 #include "zypp/base/Function.h"
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
31 // CLASS NAME : PoolQuery
34 * Meta-data query API. Returns solvables of specified kinds from specified
35 * repositories with attributes matching the specified search strings.
37 * TODO: details, examples.
42 typedef std::vector<std::string> StrContainer;
43 typedef std::set<Resolvable::Kind> Kinds;
44 typedef std::map<sat::SolvAttr, StrContainer> AttrMap;
45 typedef std::map<sat::SolvAttr, std::string> CompiledAttrMap;
46 typedef unsigned int size_type;
49 typedef function<bool( const sat::Solvable & )> ProcessResolvable;
54 /** Query result accessers. */
60 ResultIterator begin();
70 * executes the query with the current settings
71 * results are yielded on the callback passed on
74 void execute(ProcessResolvable fnc);
77 * Filter by selectable kind.
79 * By default, all kinds will be returned. If addKind() is used,
80 * only the specified kinds will be returned (multiple kinds will be ORed).
82 * Pass ResTraits<T>::kind to this method, where T is one of the
83 * \ref Resolvable child classes (e.g. ResTraits<Pattern>::kind).
85 void addKind(const Resolvable::Kind &kind);
90 * By default, all repos will be returned. If addRepo() is used,
91 * only the specified repo will be returned (multiple repos will be ORed).
93 void addRepo(const std::string &repoalias);
95 /** Installed status filter setters. */
99 * Filter by status (installed uninstalled)
102 ALL = 0, // both install filter and uninstall filter bits are 0
106 void setInstalledOnly();
107 void setUninstalledOnly();
108 void setStatusFilterFlags( int flags );
115 void addString(const std::string & value);
118 * Filter by the \a value of any available solvable attribute.
120 * \note Solvables of a kind not supporting the specified attribute will
121 * <b>not</b> be returned.
122 * \todo check the above
124 * \param attr Attribute identfier. Use sat::Solvattr::* constants
125 * \param value What to search for.
127 void addAttribute(const sat::SolvAttr & attr, const std::string & value = "");
130 * Filter by Selectable status.
132 * This should cover also plain 'is installed' and 'not installed' statuses.
134 * \param status Selectable status (zypp::ui::Status enum)
136 //void addStatus(const Status status);
139 * Add dependency filter.
141 * \param dtype depenedcy type
142 * \param name depenency name
143 * \param edition edition for a versioned dependency
144 * \param rel operand for a versioned dependency
146 * \todo maybe a isRegexp bool as in addName() for the name parameter would
147 * be handy here as well.
148 * \todo add more addDependecy() variants
150 void addDependency(const Dep & dtype,
151 const std::string & name,
152 const Edition & edition = Edition(),
153 const Rel & rel = Rel::EQ);
157 /** \name Text Matching Options */
160 * Turn case sentitivity on or off (unsets or sets \ref SEARCH_NOCASE flag).
161 * PoolQuery defaults to case insensitive search unless this method
164 * \param value Whether to turn the case sensitivity on (default) or off.
166 void setCaseSensitive(const bool value = true);
168 /** Set to match exact string instead of substring.*/
169 void setMatchExact();
170 /** Set to substring (the default). */
171 void setMatchSubstring();
172 /** Set to match globs. */
174 /** Set to use the query strings as regexes */
175 void setMatchRegex();
176 /** Set to match words (uses regex) */
178 //void setLocale(const Locale & locale);
183 * Require that all of the values set by addString, addAttribute, addDep
184 * match the values of respective attributes.
186 void setRequireAll(const bool require_all = true);
191 /** Search strings added via addString() */
192 const StrContainer & strings() const;
194 * Map (map<SolvAttr, StrContainer>) of attribute values added via
195 * addAttribute(), addDep in string form */
196 const AttrMap & attributes() const;
198 const Kinds & kinds() const;
200 const StrContainer & repos() const;
202 bool caseSensitive() const;
204 bool matchExact() const;
205 bool matchSubstring() const;
206 bool matchGlob() const;
207 bool matchRegex() const;
209 * Returns currently used string matching type.
210 * \see satsolver/repo.h
212 int matchType() const;
214 bool matchWord() const;
216 bool requireAll() const;
221 * Reads from stream query. Attributes is sepated by delim. Query is
222 * separated by two delim.
224 * \param str input stream which contains query
225 * \param delim delimeter for attributes
226 * \return true if non-empty query is recovered
228 * \see readPoolQueriesFromFile
230 bool recover( std::istream &str, char delim = '\n' );
233 * Writes a machine-readable string representation of the query to stream.
234 * Use \a delim as attribute delimiter.
236 * \param str output stream to write to
237 * \param delim delimiter for attributes
239 * \see writePoolQueriesToFile
241 void serialize( std::ostream &str, char delim = '\n' ) const;
243 /** Return a human-readable description of the query */
244 std::string asString() const;
250 * Free function to set the satsolver repo search
253 * \see SEARCH_STRINGMASK
255 * \see SEARCH_SUBSTRING
259 * \see SEARCH_NO_STORAGE_SOLVABLE
261 void setFlags(int flags);
265 /** Pointer to implementation */
266 RW_pointer<Impl> _pimpl;
268 ///////////////////////////////////////////////////////////////////
270 /** \relates PoolQuery Stream output. */
271 std::ostream & operator<<( std::ostream & str, const PoolQuery & obj );
273 bool equal(const PoolQuery& a, const PoolQuery& b);
274 bool operator==(const PoolQuery& a, const PoolQuery& b);
276 ///////////////////////////////////////////////////////////////////
278 // CLASS NAME : PoolQuery::ResultIterator
283 class PoolQuery::ResultIterator : public boost::iterator_adaptor<
284 ResultIterator // Derived
285 , ::_Dataiterator * // Base
286 , sat::Solvable // Value
287 , boost::forward_traversal_tag // CategoryOrTraversal
288 , sat::Solvable // Reference
293 : ResultIterator::iterator_adaptor_(0), _has_next(true),
294 _attrs(CompiledAttrMap()), _do_matching(false), _pool((sat::Pool::instance()))
295 { _rdit = 0; _sid = 0; }
298 friend class boost::iterator_core_access;
299 friend class PoolQuery;
301 ResultIterator(Impl * pqimpl);
303 sat::Solvable dereference() const
305 return _sid ? sat::Solvable(_sid) : sat::Solvable::noSolvable;
310 bool matchSolvable();
312 template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
313 bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
315 if (!rhs.base() && !base())
317 if (!rhs.base() || !base())
319 /*if (rhs.base()->solvid == base()->solvid)
325 //! \todo clean up this mess
326 ::_Dataiterator * _rdit;
327 PoolQuery::Impl * _pqimpl;
328 /*SolvableId*/ int _sid;
330 const CompiledAttrMap & _attrs;
334 ///////////////////////////////////////////////////////////////////
337 /////////////////////////////////////////////////////////////////
339 ///////////////////////////////////////////////////////////////////
341 #endif // ZYPP_POOLQUERY_H