libzypp  17.16.0
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
PoolQueryResult operator-(sat::Solvable result_r) const
A Solvable object within the sat Pool.
Definition: Solvable.h:53
void clear()
Clear the result.
PoolQueryResult & operator+=(const PoolQuery &query_r)
std::unordered_set< sat::Solvable > ResultSet
PoolQueryResult & operator-=(const PoolQuery &query_r)
String related utilities and Regular expression matching.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
PoolQueryResult(TQueryResultIter begin_r, TQueryResultIter end_r)
Ctor adding a range of items for which operator+= is defined.
PoolQueryResult & operator+=(const PoolQueryResult &query_r)
Add items to the result.
bool empty() const
Whether the result is empty.
PoolQueryResult & operator-=(sat::Solvable result_r)
const_iterator end() const
Base class providing common iterator types based on a Solvable iterator.
PoolQueryResult operator+(const PoolQuery &query_r) const
size_type size() const
The number of sat::Solvables.
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
PoolQueryResult operator-(const PoolQueryResult &query_r) const
Intersect results.
PoolQueryResult()
Default ctor (empty result)
const_iterator begin() const
Query result accessers.
Definition: PoolQuery.cc:1826
PoolQueryResult & operator+=(sat::Solvable result_r)
PoolQueryResult & operator+=(const PoolItem &result_r)
ResultSet::size_type size_type
PoolQueryResult operator-(const PoolQuery &query_r) const
const_iterator end() const
An iterator pointing to the end of the query result.
Definition: PoolQuery.h:614
SolvableIdType size_type
Definition: PoolMember.h:126
bool contains(sat::Solvable result_r) const
Test whether some item is in the result set.
bool contains(const PoolItem &result_r) const
const_iterator begin() const
PoolQueryResult operator+(sat::Solvable result_r) const
PoolQueryResult(const PoolItem &result_r)
Ctor adding one PoolItem.
Meta-data query API.
Definition: PoolQuery.h:90
Base class for Exception.
Definition: Exception.h:145
ResultSet::const_iterator const_iterator
PoolQueryResult(sat::Solvable result_r)
Ctor adding one sat::Solvable.
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
Helper class to collect (not only) PoolQuery results.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
PoolQueryResult operator+(const PoolQueryResult &query_r) const
Combine results.
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
PoolQueryResult & operator-=(const PoolQueryResult &query_r)
Remove Items from the result.
PoolQueryResult(const PoolQuery &query_r)
Ctor adding one PoolQuery result.
PoolQueryResult & operator-=(const PoolItem &result_r)