- move the callback from constructor to query()
[platform/upstream/libzypp.git] / zypp / PoolQuery.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ui/PoolQuery.h
10  *
11 */
12 #ifndef QUERY_H_
13 #define QUERY_H_
14
15 #include "zypp/ui/Selectable.h"
16 #include "zypp/sat/SolvAttr.h"
17
18 #include "zypp/base/Function.h"
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23   ///////////////////////////////////////////////////////////////////
24
25   /**
26    * Meta-data query API for user interfaces.
27    * 
28    * TODO: details, examples.
29    */
30   class PoolQuery
31   {
32   public:
33     
34     //typedef SelectableSet::iterator      ResultIterator;
35     //typedef constSelectableSet::iterator constResultIterator;
36
37     typedef function<bool( const ResObject::Ptr & )> ProcessResolvable;
38
39     PoolQuery();
40     ~PoolQuery();
41
42   public:
43
44     /**
45      * executes the query with the current settings
46      * results are yielded on the callback passed on
47      * construction
48      */
49     void execute(const std::string &term, PoolQuery::ProcessResolvable fnc) const;
50
51     /**
52      * Filter by selectable kind.
53      * 
54      * By default, all kinds will be returned. If addKind() is used,
55      * only the specified kinds will be returned (multiple kinds will be ORed).
56      * 
57      * Pass ResTraits<T>::kind to this method, where T is one of the
58      * \ref Resolvable child classes (e.g. ResTraits<Pattern>::kind).
59      */
60     void addKind(const Resolvable::Kind &kind);
61
62     /**
63      * Filter by selectable name.
64      * 
65      * \param name   what to search for
66      * \param isRegex is the value a regex?
67      */
68     //void addName(const std::string & name, bool isRegex = false);
69
70     /**
71      * Filter by status (installed uninstalled)
72      */
73     enum StatusFilter {
74       ALL = 1,
75       INSTALLED_ONLY = 2,
76       UNINSTALLED_ONLY = 4
77     };
78     void setInstalledOnly();
79     void setUninstalledOnly();
80     void setStatusFilterFlags( int flags );
81
82     /**
83      * Filter by the \a value of any available attribute of selectables.
84      * 
85      * \note Selectables of a kind not supporting the specified attribute will
86      * <b>not</b> be returned.
87      * 
88      * \param attrid  attribute identfier (sat::SolvAttr or cache::Attribute
89      *                or something implementation independent)
90      * \param value   what to search for
91      * \param isRegex is the value a regex?
92      */
93     //void addAttribute(const solv::SolvAttr & attrid,
94     //                  const std::string & value,
95     //                  bool isRegex = false);
96
97     /**
98      * Filter by Selectable status.
99      * 
100      * This should cover also plain 'is installed' and 'not installed' statuses.
101      *
102      * \param status Selectable status (zypp::ui::Status enum)
103      */
104     //void addStatus(const Status status);
105     
106
107     /**
108      * Add dependency filter.
109      *
110      * \param dtype   depenedcy type
111      * \param name    depenency name
112      * \param edition edition for a versioned dependency
113      * \param rel     operand for a versioned dependency
114      *
115      * \todo maybe a isRegexp bool as in addName() for the name parameter would
116      *       be handy here as well.
117      * \todo add more addDependecy() variants
118      */
119     //void addDependency(const Dep & dtype,
120     //                   const std::string & name,
121     //                   const Edition & edition = Edition(),
122     //                   const Rel & rel = Rel::EQ);
123
124     /** \name Text Attributes Matching Options */
125     //@{
126     /**
127      * Set case sentitive on
128      * ( disables \ref SEARCH_NOCASE flag )
129      */
130     void setCaseSensitive(const bool value = true);
131
132     /**
133      * Set match exact string
134      */
135     void setMatchExact(const bool value = true);
136
137     /**
138      * Free function to set the satsolver repo search
139        flags.
140
141        \see SEARCH_STRINGMASK
142        \see SEARCH_STRING
143        \see SEARCH_SUBSTRING
144        \see SEARCH_GLOB
145        \see SEARCH_REGEX
146        \see SEARCH_NOCASE
147        \see SEARCH_NO_STORAGE_SOLVABLE
148     */
149     void setFlags(int flags);
150     //void setLocale(const Locale & locale);
151     //@}
152
153     //void setRequireAll(const bool require_all = true);
154
155     /** selectable iterator over the result */
156     //ResultIterator resultBegin() const;
157     //ResultIterator resultEnd() const; 
158
159     /** Returns the size of the query result. */
160     //size_t resultSize() const;
161
162     /** Low-cost empty query result checker */
163     //bool resultEmpty() const;
164     
165     // a forEach method consuming a functor can be added here, too
166
167   public:
168     class Impl;
169   private:
170     /** Pointer to implementation */
171     RW_pointer<Impl> _pimpl;
172   };
173
174
175 /////////////////////////////////////////////////////////////////
176 } // namespace zypp
177 ///////////////////////////////////////////////////////////////////
178
179 #endif /*QUERY_H_*/