libzypp  17.30.2
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/base/Hash.h>
18 #include <zypp/base/Exception.h>
19 #include <zypp/sat/SolvIterMixin.h>
20 
21 #include <zypp/PoolItem.h>
22 #include <zypp/PoolQuery.h>
23 
25 namespace 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  typedef std::unordered_set<sat::Solvable> ResultSet;
80  typedef ResultSet::const_iterator const_iterator;
81 
82  public:
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(); }
114  size_type size() const
115  { return _result.size(); }
118  { return _result.begin(); }
121  { return _result.end(); }
122 
124  bool contains(sat::Solvable result_r ) const
125  { return( _result.find( result_r ) != _result.end() ); }
127  bool contains( const PoolItem & result_r ) const
128  { return contains( result_r.satSolvable() ); }
129 
130  public:
132  void clear()
133  { _result.clear(); }
134 
137  {
138  if ( ! query_r.empty() )
139  _result.insert( query_r.begin(), query_r.end() );
140  return *this;
141  }
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  }
156  {
157  _result.insert( result_r );
158  return *this;
159  }
161  PoolQueryResult & operator+=( const PoolItem & result_r )
162  {
163  _result.insert( result_r.satSolvable() );
164  return *this;
165  }
166 
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  }
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  }
191  {
192  _result.erase( result_r );
193  return *this;
194  }
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; }
207  PoolQueryResult operator+( const PoolQuery & query_r ) const
208  { return PoolQueryResult(*this) += query_r; }
211  { return PoolQueryResult(*this) += result_r; }
212 
214  PoolQueryResult operator-( const PoolQueryResult & query_r ) const
215  { return PoolQueryResult(*this) -= query_r; }
217  PoolQueryResult operator-( const PoolQuery & query_r ) const
218  { return PoolQueryResult(*this) -= query_r; }
221  { return PoolQueryResult(*this) -= result_r; }
222 
223  private:
225  };
227 
229  std::ostream & operator<<( std::ostream & str, const PoolQueryResult & obj );
230 
232 } // namespace zypp
234 #endif // ZYPP_POOLQUERYRESULT_H
Base class for Exception.
Definition: Exception.h:146
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:51
Helper class to collect (not only) PoolQuery results.
size_type size() const
The number of sat::Solvables.
PoolQueryResult(const PoolItem &result_r)
Ctor adding one PoolItem.
ResultSet::const_iterator const_iterator
PoolQueryResult & operator+=(const PoolQuery &query_r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
PoolQueryResult(const PoolQuery &query_r)
Ctor adding one PoolQuery result.
ResultSet::size_type size_type
bool contains(sat::Solvable result_r) const
Test whether some item is in the result set.
const_iterator end() const
PoolQueryResult operator-(const PoolQuery &query_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool empty() const
Whether the result is empty.
PoolQueryResult()
Default ctor (empty result)
PoolQueryResult & operator+=(sat::Solvable result_r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
PoolQueryResult & operator-=(const PoolQueryResult &query_r)
Remove Items from the result.
const_iterator begin() const
PoolQueryResult operator-(sat::Solvable result_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
PoolQueryResult & operator+=(const PoolItem &result_r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
PoolQueryResult(sat::Solvable result_r)
Ctor adding one sat::Solvable.
void clear()
Clear the result.
PoolQueryResult operator+(sat::Solvable result_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
PoolQueryResult operator-(const PoolQueryResult &query_r) const
Intersect results.
PoolQueryResult operator+(const PoolQuery &query_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
PoolQueryResult operator+(const PoolQueryResult &query_r) const
Combine results.
bool contains(const PoolItem &result_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::unordered_set< sat::Solvable > ResultSet
PoolQueryResult & operator-=(const PoolQuery &query_r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
PoolQueryResult & operator-=(const PoolItem &result_r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
PoolQueryResult & operator+=(const PoolQueryResult &query_r)
Add items to the result.
PoolQueryResult(TQueryResultIter begin_r, TQueryResultIter end_r)
Ctor adding a range of items for which operator+= is defined.
PoolQueryResult & operator-=(sat::Solvable result_r)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Meta-data query API.
Definition: PoolQuery.h:91
const_iterator end() const
An iterator pointing to the end of the query result.
Definition: PoolQuery.h:624
const_iterator begin() const
Query result accessers.
Definition: PoolQuery.cc:1849
Base class providing common iterator types based on a Solvable iterator.
A Solvable object within the sat Pool.
Definition: Solvable.h:54
String related utilities and Regular expression matching.
SolvableIdType size_type
Definition: PoolMember.h:126
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28