libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef ZYPP_POOLQUERYRESULT_H 00013 #define ZYPP_POOLQUERYRESULT_H 00014 00015 #include <iosfwd> 00016 00017 #include "zypp/base/Tr1hash.h" 00018 #include "zypp/base/Exception.h" 00019 #include "zypp/sat/SolvIterMixin.h" 00020 00021 #include "zypp/PoolItem.h" 00022 #include "zypp/PoolQuery.h" 00023 00025 namespace zypp 00026 { 00027 00029 // 00030 // CLASS NAME : PoolQueryResult 00031 // 00075 class PoolQueryResult : public sat::SolvIterMixin<PoolQueryResult,std::tr1::unordered_set<sat::Solvable>::const_iterator> 00076 { 00077 public: 00078 typedef std::tr1::unordered_set<sat::Solvable> ResultSet; 00079 typedef ResultSet::size_type size_type; 00080 typedef ResultSet::const_iterator const_iterator; 00081 00082 public: 00084 PoolQueryResult() 00085 {} 00086 00088 explicit PoolQueryResult( sat::Solvable result_r ) 00089 { operator+=( result_r ); } 00090 00092 explicit PoolQueryResult( const PoolItem & result_r ) 00093 { operator+=( result_r ); } 00094 00096 explicit PoolQueryResult( const PoolQuery & query_r ) 00097 { operator+=( query_r ); } 00098 00100 template<class _QueryResultIter> 00101 PoolQueryResult( _QueryResultIter begin_r, _QueryResultIter end_r ) 00102 { 00103 for_( it, begin_r, end_r ) 00104 { 00105 operator+=( *it ); 00106 } 00107 } 00108 00109 public: 00111 bool empty() const 00112 { return _result.empty(); } 00114 size_type size() const 00115 { return _result.size(); } 00117 const_iterator begin() const 00118 { return _result.begin(); } 00120 const_iterator end() const 00121 { return _result.end(); } 00122 00124 bool contains(sat::Solvable result_r ) const 00125 { return( _result.find( result_r ) != _result.end() ); } 00127 bool contains( const PoolItem & result_r ) const 00128 { return contains( result_r.satSolvable() ); } 00129 00130 public: 00132 void clear() 00133 { _result.clear(); } 00134 00136 PoolQueryResult & operator+=( const PoolQueryResult & query_r ) 00137 { 00138 if ( ! query_r.empty() ) 00139 _result.insert( query_r.begin(), query_r.end() ); 00140 return *this; 00141 } 00143 PoolQueryResult & operator+=( const PoolQuery & query_r ) 00144 { 00145 try 00146 { 00147 for_( it, query_r.begin(), query_r.end() ) 00148 _result.insert( *it ); 00149 } 00150 catch ( const Exception & ) 00151 {} 00152 return *this; 00153 } 00155 PoolQueryResult & operator+=( sat::Solvable result_r ) 00156 { 00157 _result.insert( result_r ); 00158 return *this; 00159 } 00161 PoolQueryResult & operator+=( const PoolItem & result_r ) 00162 { 00163 _result.insert( result_r.satSolvable() ); 00164 return *this; 00165 } 00166 00168 PoolQueryResult & operator-=( const PoolQueryResult & query_r ) 00169 { 00170 if ( &query_r == this ) // catch self removal! 00171 clear(); 00172 else 00173 for_( it, query_r.begin(), query_r.end() ) 00174 _result.erase( *it ); 00175 return *this; 00176 } 00178 PoolQueryResult & operator-=( const PoolQuery & query_r ) 00179 { 00180 try 00181 { 00182 for_( it, query_r.begin(), query_r.end() ) 00183 _result.erase( *it ); 00184 } 00185 catch ( const Exception & ) 00186 {} 00187 return *this; 00188 } 00190 PoolQueryResult & operator-=( sat::Solvable result_r ) 00191 { 00192 _result.erase( result_r ); 00193 return *this; 00194 } 00196 PoolQueryResult & operator-=( const PoolItem & result_r ) 00197 { 00198 _result.erase( result_r.satSolvable() ); 00199 return *this; 00200 } 00201 00202 public: 00204 PoolQueryResult operator+( const PoolQueryResult & query_r ) const 00205 { return PoolQueryResult(*this) += query_r; } 00207 PoolQueryResult operator+( const PoolQuery & query_r ) const 00208 { return PoolQueryResult(*this) += query_r; } 00210 PoolQueryResult operator+( sat::Solvable result_r ) const 00211 { return PoolQueryResult(*this) += result_r; } 00212 00214 PoolQueryResult operator-( const PoolQueryResult & query_r ) const 00215 { return PoolQueryResult(*this) -= query_r; } 00217 PoolQueryResult operator-( const PoolQuery & query_r ) const 00218 { return PoolQueryResult(*this) -= query_r; } 00220 PoolQueryResult operator-( sat::Solvable result_r ) const 00221 { return PoolQueryResult(*this) -= result_r; } 00222 00223 private: 00224 ResultSet _result; 00225 }; 00227 00229 std::ostream & operator<<( std::ostream & str, const PoolQueryResult & obj ); 00230 00232 } // namespace zypp 00234 #endif // ZYPP_POOLQUERYRESULT_H