1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/PoolQuery.cc
17 #include "zypp/base/Logger.h"
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/base/DefaultIntegral.h"
20 #include "zypp/PoolQuery.h"
21 #include "zypp/base/UserRequestException.h"
23 #include "zypp/sat/Pool.h"
24 #include "zypp/sat/Solvable.h"
28 #include "satsolver/repo.h"
33 ///////////////////////////////////////////////////////////////////
35 { /////////////////////////////////////////////////////////////////
37 struct PoolQuery::Impl
41 : _flags( 0 | SEARCH_NOCASE | SEARCH_SUBSTRING )
52 static int repo_search_cb(void *cbdata, ::Solvable *s, ::Repodata *data, ::Repokey *key, ::KeyValue *kv)
54 //int SEARCH_NEXT_KEY = 1;
55 //int SEARCH_NEXT_SOLVABLE = 2;
58 PoolQuery *me = (PoolQuery*) cbdata;
62 sat::Solvable solvable(s - sat::Pool::instance().get()->solvables);
64 // now filter by kind here (we cant do it before)
65 if ( ! me->_pimpl->_kinds.empty() )
67 // the user wants to filter by kind.
68 if ( find( me->_pimpl->_kinds.begin(),
69 me->_pimpl->_kinds.end(),
71 == me->_pimpl->_kinds.end() )
73 // we did not find the kind in the list
74 // so this is not a result.
75 return SEARCH_NEXT_SOLVABLE;
80 r = me->_pimpl->_fnc( makeResObject(solvable) );
84 return SEARCH_NEXT_SOLVABLE;
87 vector<string> _repos;
88 vector<string> _names;
89 vector<Resolvable::Kind> _kinds;
92 mutable PoolQuery::ProcessResolvable _fnc;
94 friend Impl * rwcowClone<Impl>( const Impl * rhs );
95 /** clone for RWCOW_pointer */
97 { return new Impl( *this ); }
99 ///////////////////////////////////////////////////////////////////
101 /** \relates PoolQuery::Impl Stream output */
102 inline std::ostream & operator<<( std::ostream & str, const PoolQuery::Impl & obj )
104 return str << "PoolQuery::Impl";
107 ///////////////////////////////////////////////////////////////////
109 // CLASS NAME : PoolQuery
111 ///////////////////////////////////////////////////////////////////
113 PoolQuery::PoolQuery()
117 PoolQuery::~PoolQuery()
120 void PoolQuery::addKind(const Resolvable::Kind &kind)
121 { _pimpl->_kinds.push_back(kind); }
123 void PoolQuery::setCaseSensitive(const bool value)
126 _pimpl->_flags = (_pimpl->_flags & ~SEARCH_NOCASE);
128 _pimpl->_flags = (_pimpl->_flags | SEARCH_NOCASE);
131 void PoolQuery::setMatchExact(const bool value)
135 _pimpl->_flags = (_pimpl->_flags | SEARCH_STRING);
136 _pimpl->_flags = (_pimpl->_flags & ~SEARCH_REGEX);
137 _pimpl->_flags = (_pimpl->_flags & ~SEARCH_SUBSTRING);
138 _pimpl->_flags = (_pimpl->_flags & ~SEARCH_GLOB);
142 _pimpl->_flags = (_pimpl->_flags & ~SEARCH_STRING);
146 void PoolQuery::setFlags(int flags)
147 { _pimpl->_flags = flags; }
149 void PoolQuery::setInstalledOnly()
151 _pimpl->_status_flags = (_pimpl->_status_flags | INSTALLED_ONLY);
154 void PoolQuery::setUninstalledOnly()
156 _pimpl->_status_flags = (_pimpl->_status_flags | UNINSTALLED_ONLY);
159 void PoolQuery::setStatusFilterFlags( int flags )
161 _pimpl->_status_flags = (_pimpl->_status_flags | flags);
164 void PoolQuery::execute(const string &term, ProcessResolvable fnc) const
168 sat::Pool pool(sat::Pool::instance());
169 for ( sat::Pool::RepoIterator itr = pool.reposBegin();
170 itr != pool.reposEnd();
173 // filter by installed uninstalled
174 if ( ( _pimpl->_status_flags & INSTALLED_ONLY ) && (itr->name() != sat::Pool::instance().systemRepoName()) )
177 if ( ( _pimpl->_status_flags & UNINSTALLED_ONLY ) && (itr->name() == sat::Pool::instance().systemRepoName()) )
180 // is this repo in users repos?
181 bool included = ( find(_pimpl->_repos.begin(), _pimpl->_repos.end(), itr->name()) != _pimpl->_repos.end() );
183 // only look in user repos filter if the filter is not empty
184 // in this case we search in all
185 if ( _pimpl->_repos.empty() || included )
187 repo_search( itr->get(), 0, 0, term.c_str(), _pimpl->_flags, Impl::repo_search_cb, (void*) (this));
193 /******************************************************************
195 ** FUNCTION NAME : operator<<
196 ** FUNCTION TYPE : ostream &
198 ostream & operator<<( ostream & str, const PoolQuery & obj )
203 /////////////////////////////////////////////////////////////////
205 ///////////////////////////////////////////////////////////////////