libzypp  11.13.5
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/Tr1hash.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::tr1::unordered_set<sat::Solvable>::const_iterator>
76  {
77  public:
78  typedef std::tr1::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 _QueryResultIter>
101  PoolQueryResult( _QueryResultIter begin_r, _QueryResultIter 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