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