libzypp: zypp/PoolQueryResult.h Source File

libzypp 17.38.14

PoolQueryResult.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_POOLQUERYRESULT_H
13#define ZYPP_POOLQUERYRESULT_H
14
15#include <iosfwd>
16
17#include <zypp-core/base/Hash.h>
18#include <zypp-core/base/Exception.h>
19#include <zypp/sat/SolvIterMixin.h>
20
21#include <zypp/PoolItem.h>
22#include <zypp/PoolQuery.h>
23
25namespace zypp
26{
27
29 //
30 // CLASS NAME : PoolQueryResult
31 //
75 class PoolQueryResult : public sat::SolvIterMixin<PoolQueryResult,std::unordered_set<sat::Solvable>::const_iterator>
76 {
77 public:
78 using ResultSet = std::unordered_set<sat::Solvable>;
79 using size_type = ResultSet::size_type;
80 using const_iterator = ResultSet::const_iterator;
81
82 public:
84 PoolQueryResult()
85 {}
86
88 explicit PoolQueryResult( sat::Solvable result_r )
89 { operator+=( result_r ); }
90
92 explicit PoolQueryResult( const PoolItem & result_r )
93 { operator+=( result_r ); }
94
96 explicit PoolQueryResult( const PoolQuery & query_r )
97 { operator+=( query_r ); }
98
100 template<class TQueryResultIter>
101 PoolQueryResult( TQueryResultIter begin_r, TQueryResultIter end_r )
102 {
103 for_( it, begin_r, end_r )
104 {
105 operator+=( *it );
106 }
107 }
108
109 public:
111 bool empty() const
112 { return _result.empty(); }
113
114 size_type size() const
115 { return _result.size(); }
116
117 const_iterator begin() const
118 { return _result.begin(); }
119
120 const_iterator end() const
121 { return _result.end(); }
122
124 bool contains(sat::Solvable result_r ) const
125 { return( _result.find( result_r ) != _result.end() ); }
126
127 bool contains( const PoolItem & result_r ) const
128 { return contains( result_r.satSolvable() ); }
129
130 public:
132 void clear()
133 { _result.clear(); }
134
136 PoolQueryResult & operator+=( const PoolQueryResult & query_r )
137 {
138 if ( ! query_r.empty() )
139 _result.insert( query_r.begin(), query_r.end() );
140 return *this;
141 }
142
143 PoolQueryResult & operator+=( const PoolQuery & query_r )
144 {
145 try
146 {
147 for_( it, query_r.begin(), query_r.end() )
148 _result.insert( *it );
149 }
150 catch ( const Exception & )
151 {}
152 return *this;
153 }
154
155 PoolQueryResult & operator+=( sat::Solvable result_r )
156 {
157 _result.insert( result_r );
158 return *this;
159 }
160
161 PoolQueryResult & operator+=( const PoolItem & result_r )
162 {
163 _result.insert( result_r.satSolvable() );
164 return *this;
165 }
166
168 PoolQueryResult & operator-=( const PoolQueryResult & query_r )
169 {
170 if ( &query_r == this ) // catch self removal!
171 clear();
172 else
173 for_( it, query_r.begin(), query_r.end() )
174 _result.erase( *it );
175 return *this;
176 }
177
178 PoolQueryResult & operator-=( const PoolQuery & query_r )
179 {
180 try
181 {
182 for_( it, query_r.begin(), query_r.end() )
183 _result.erase( *it );
184 }
185 catch ( const Exception & )
186 {}
187 return *this;
188 }
189
190 PoolQueryResult & operator-=( sat::Solvable result_r )
191 {
192 _result.erase( result_r );
193 return *this;
194 }
195
196 PoolQueryResult & operator-=( const PoolItem & result_r )
197 {
198 _result.erase( result_r.satSolvable() );
199 return *this;
200 }
201
202 public:
204 PoolQueryResult operator+( const PoolQueryResult & query_r ) const
205 { return PoolQueryResult(*this) += query_r; }
206
207 PoolQueryResult operator+( const PoolQuery & query_r ) const
208 { return PoolQueryResult(*this) += query_r; }
209
210 PoolQueryResult operator+( sat::Solvable result_r ) const
211 { return PoolQueryResult(*this) += result_r; }
212
214 PoolQueryResult operator-( const PoolQueryResult & query_r ) const
215 { return PoolQueryResult(*this) -= query_r; }
216
217 PoolQueryResult operator-( const PoolQuery & query_r ) const
218 { return PoolQueryResult(*this) -= query_r; }
219
220 PoolQueryResult operator-( sat::Solvable result_r ) const
221 { return PoolQueryResult(*this) -= result_r; }
222
223 private:
224 ResultSet _result;
225 };
226
227
229 std::ostream & operator<<( std::ostream & str, const PoolQueryResult & obj );
230
232} // namespace zypp
234#endif // ZYPP_POOLQUERYRESULT_H
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
Exception.h
Hash.h
PoolItem.h
PoolQuery.h
SolvIterMixin.h
zypp::Exception
Base class for Exception.
Definition Exception.h:153
zypp::PoolItem
Combining sat::Solvable and ResStatus.
Definition PoolItem.h:51
zypp::PoolQueryResult
Helper class to collect (not only) PoolQuery results.
Definition PoolQueryResult.h:76
zypp::PoolQueryResult::size
size_type size() const
The number of sat::Solvables.
Definition PoolQueryResult.h:114
zypp::PoolQueryResult::PoolQueryResult
PoolQueryResult(const PoolItem &result_r)
Ctor adding one PoolItem.
Definition PoolQueryResult.h:92
zypp::PoolQueryResult::PoolQueryResult
PoolQueryResult(const PoolQuery &query_r)
Ctor adding one PoolQuery result.
Definition PoolQueryResult.h:96
zypp::PoolQueryResult::operator+=
PoolQueryResult & operator+=(const PoolQueryResult &query_r)
Add items to the result.
Definition PoolQueryResult.h:136
zypp::PoolQueryResult::ResultSet
std::unordered_set< sat::Solvable > ResultSet
Definition PoolQueryResult.h:78
zypp::PoolQueryResult::operator-=
PoolQueryResult & operator-=(const PoolItem &result_r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition PoolQueryResult.h:196
zypp::PoolQueryResult::contains
bool contains(sat::Solvable result_r) const
Test whether some item is in the result set.
Definition PoolQueryResult.h:124
zypp::PoolQueryResult::end
const_iterator end() const
Definition PoolQueryResult.h:120
zypp::PoolQueryResult::_result
ResultSet _result
Definition PoolQueryResult.h:224
zypp::PoolQueryResult::const_iterator
ResultSet::const_iterator const_iterator
Definition PoolQueryResult.h:80
zypp::PoolQueryResult::operator+=
PoolQueryResult & operator+=(const PoolQuery &query_r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition PoolQueryResult.h:143
zypp::PoolQueryResult::operator-=
PoolQueryResult & operator-=(const PoolQuery &query_r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition PoolQueryResult.h:178
zypp::PoolQueryResult::operator-
PoolQueryResult operator-(const PoolQuery &query_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition PoolQueryResult.h:217
zypp::PoolQueryResult::empty
bool empty() const
Whether the result is empty.
Definition PoolQueryResult.h:111
zypp::PoolQueryResult::PoolQueryResult
PoolQueryResult()
Default ctor (empty result).
Definition PoolQueryResult.h:84
zypp::PoolQueryResult::operator+=
PoolQueryResult & operator+=(sat::Solvable result_r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition PoolQueryResult.h:155
zypp::PoolQueryResult::begin
const_iterator begin() const
Definition PoolQueryResult.h:117
zypp::PoolQueryResult::operator+=
PoolQueryResult & operator+=(const PoolItem &result_r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition PoolQueryResult.h:161
zypp::PoolQueryResult::operator-
PoolQueryResult operator-(sat::Solvable result_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition PoolQueryResult.h:220
zypp::PoolQueryResult::PoolQueryResult
PoolQueryResult(sat::Solvable result_r)
Ctor adding one sat::Solvable.
Definition PoolQueryResult.h:88
zypp::PoolQueryResult::clear
void clear()
Clear the result.
Definition PoolQueryResult.h:132
zypp::PoolQueryResult::operator+
PoolQueryResult operator+(sat::Solvable result_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition PoolQueryResult.h:210
zypp::PoolQueryResult::operator-=
PoolQueryResult & operator-=(sat::Solvable result_r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition PoolQueryResult.h:190
zypp::PoolQueryResult::operator-
PoolQueryResult operator-(const PoolQueryResult &query_r) const
Intersect results.
Definition PoolQueryResult.h:214
zypp::PoolQueryResult::size_type
ResultSet::size_type size_type
Definition PoolQueryResult.h:79
zypp::PoolQueryResult::operator+
PoolQueryResult operator+(const PoolQuery &query_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition PoolQueryResult.h:207
zypp::PoolQueryResult::operator+
PoolQueryResult operator+(const PoolQueryResult &query_r) const
Combine results.
Definition PoolQueryResult.h:204
zypp::PoolQueryResult::contains
bool contains(const PoolItem &result_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition PoolQueryResult.h:127
zypp::PoolQueryResult::operator-=
PoolQueryResult & operator-=(const PoolQueryResult &query_r)
Remove Items from the result.
Definition PoolQueryResult.h:168
zypp::PoolQueryResult::PoolQueryResult
PoolQueryResult(TQueryResultIter begin_r, TQueryResultIter end_r)
Ctor adding a range of items for which operator+= is defined.
Definition PoolQueryResult.h:101
zypp::PoolQuery
Meta-data query API.
Definition PoolQuery.h:91
zypp::PoolQuery::end
const_iterator end() const
An iterator pointing to the end of the query result.
Definition PoolQuery.h:621
zypp::PoolQuery::begin
const_iterator begin() const
Query result accessers.
Definition PoolQuery.cc:1855
zypp::sat::SolvIterMixin
Base class providing common iterator types based on a Solvable iterator.
Definition SolvIterMixin.h:131
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition Solvable.h:54
str
String related utilities and Regular expression matching.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65
zypp::sat::SolvableType::satSolvable
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition SolvableType.h:57