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 { /////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////
31 * Meta-data query API. Returns solvables of specified kinds from specified
32 * repositories with attributes matching the specified search strings.
34 * TODO: details, examples.
39 typedef std::map<sat::SolvAttr, std::vector<std::string> > AttrMap;
40 typedef std::map<sat::SolvAttr, std::string > CompiledAttrMap;
41 typedef unsigned int size_type;
45 class ResultIterator : public boost::iterator_adaptor<
46 ResultIterator // Derived
47 , ::_Dataiterator * // Base
48 , sat::Solvable // Value
49 , boost::forward_traversal_tag // CategoryOrTraversal
50 , sat::Solvable // Reference
55 : ResultIterator::iterator_adaptor_(0), _has_next(true),
56 _attrs(CompiledAttrMap()), _do_matching(false), _pool((sat::Pool::instance()))
57 { _rdit = 0; _sid = 0; }
60 friend class boost::iterator_core_access;
61 friend class PoolQuery;
63 ResultIterator(Impl * pqimpl);
65 sat::Solvable dereference() const
67 return _sid ? sat::Solvable(_sid) : sat::Solvable::noSolvable;
74 template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
75 bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
77 if (!rhs.base() && !base())
79 if (!rhs.base() || !base())
81 /*if (rhs.base()->solvid == base()->solvid)
87 ::_Dataiterator * _rdit;
89 /*SolvableId*/ int _sid;
91 const CompiledAttrMap & _attrs;
97 typedef function<bool( const sat::Solvable & )> ProcessResolvable;
102 /** Query result accessers. */
106 ResultIterator begin();
108 ResultIterator end();
116 * executes the query with the current settings
117 * results are yielded on the callback passed on
120 void execute(ProcessResolvable fnc);
123 * Filter by selectable kind.
125 * By default, all kinds will be returned. If addKind() is used,
126 * only the specified kinds will be returned (multiple kinds will be ORed).
128 * Pass ResTraits<T>::kind to this method, where T is one of the
129 * \ref Resolvable child classes (e.g. ResTraits<Pattern>::kind).
131 void addKind(const Resolvable::Kind &kind);
136 * By default, all repos will be returned. If addRepo() is used,
137 * only the specified repo will be returned (multiple repos will be ORed).
139 void addRepo(const std::string &repoalias);
141 /** Installed status filter setters. */
145 * Filter by status (installed uninstalled)
148 ALL = 0, // both install filter and uninstall filter bits are 0
152 void setInstalledOnly();
153 void setUninstalledOnly();
154 void setStatusFilterFlags( int flags );
161 void addString(const std::string & value);
164 * Filter by the \a value of any available solvable attribute.
166 * \note Solvables of a kind not supporting the specified attribute will
167 * <b>not</b> be returned.
168 * \todo check the above
170 * \param attr Attribute identfier. Use sat::Solvattr::* constants
171 * \param value What to search for.
173 void addAttribute(const sat::SolvAttr & attr, const std::string & value = "");
176 * Filter by Selectable status.
178 * This should cover also plain 'is installed' and 'not installed' statuses.
180 * \param status Selectable status (zypp::ui::Status enum)
182 //void addStatus(const Status status);
185 * Add dependency filter.
187 * \param dtype depenedcy type
188 * \param name depenency name
189 * \param edition edition for a versioned dependency
190 * \param rel operand for a versioned dependency
192 * \todo maybe a isRegexp bool as in addName() for the name parameter would
193 * be handy here as well.
194 * \todo add more addDependecy() variants
196 void addDependency(const Dep & dtype,
197 const std::string & name,
198 const Edition & edition = Edition(),
199 const Rel & rel = Rel::EQ);
203 /** \name Text Matching Options */
206 * Turn case sentitivity on or off (unsets or sets \ref SEARCH_NOCASE flag).
207 * PoolQuery defaults to case insensitive search unless this method
210 * \param value Whether to turn the case sensitivity on (default) or off.
212 void setCaseSensitive(const bool value = true);
214 /** Set to match exact string instead of substring.*/
215 void setMatchExact();
216 /** Set to substring (the default). */
217 void setMatchSubstring();
218 /** Set to match globs. */
220 /** Set to use the query strings as regexes */
221 void setMatchRegex();
222 /** Set to match words (uses regex) */
224 //void setLocale(const Locale & locale);
229 * Require that all of the query conditions set by
230 * addAttribute, addString, addDep are satisfied.
232 void requireAll(const bool require_all = true);
235 * Reads from stream query. Attributes is sepated by delim. Query is
236 * separated by two delim.
238 * \param str input stream which contains query
239 * \param delim delimeter for attributes
240 * \return true if non-empty query is recovered
242 * \see readPoolQueriesFromFile
244 bool recover( std::istream &str, char delim = '\n' );
247 * Writes a machine-readable string representation of the query to stream.
248 * Use \a delim as attribute delimiter.
250 * \param str output stream to write to
251 * \param delim delimiter for attributes
253 * \see writePoolQueriesToFile
255 void serialize( std::ostream &str, char delim = '\n' ) const;
257 /** Return a human-readable description of the query */
258 std::string asString() const;
264 * Free function to set the satsolver repo search
267 * \see SEARCH_STRINGMASK
269 * \see SEARCH_SUBSTRING
273 * \see SEARCH_NO_STORAGE_SOLVABLE
275 void setFlags(int flags);
278 /** Pointer to implementation */
279 RW_pointer<Impl> _pimpl;
283 /** \relates PoolQuery Stream output. */
284 std::ostream & operator<<( std::ostream & str, const PoolQuery & obj );
287 /////////////////////////////////////////////////////////////////
289 ///////////////////////////////////////////////////////////////////
291 #endif // ZYPP_POOLQUERY_H