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
40 Impl(PoolQuery::ProcessResolvable fnc)
41 : _flags( 0 | SEARCH_NOCASE | SEARCH_SUBSTRING )
52 static int repo_search_cb(void *cbdata, ::Solvable *s, ::Repodata *data, ::Repokey *key, ::KeyValue *kv)
54 //#define SEARCH_NEXT_KEY 1
55 //#define SEARCH_NEXT_SOLVABLE 2
56 //#define SEACH_STOP 3
58 PoolQuery *me = (PoolQuery*) cbdata;
59 bool r = me->_pimpl->_fnc( makeResObject(sat::Solvable(s - sat::Pool::instance().get()->solvables)));
63 return SEARCH_NEXT_SOLVABLE;
66 vector<string> _repos;
67 vector<string> _names;
68 vector<Resolvable::Kind> _kinds;
70 PoolQuery::ProcessResolvable _fnc;
72 friend Impl * rwcowClone<Impl>( const Impl * rhs );
73 /** clone for RWCOW_pointer */
75 { return new Impl( *this ); }
77 ///////////////////////////////////////////////////////////////////
79 /** \relates PoolQuery::Impl Stream output */
80 inline std::ostream & operator<<( std::ostream & str, const PoolQuery::Impl & obj )
82 return str << "PoolQuery::Impl";
85 ///////////////////////////////////////////////////////////////////
87 // CLASS NAME : PoolQuery
89 ///////////////////////////////////////////////////////////////////
91 PoolQuery::PoolQuery( PoolQuery::ProcessResolvable fnc )
92 : _pimpl(new Impl(fnc))
95 PoolQuery::~PoolQuery()
98 void PoolQuery::addKind(const Resolvable::Kind &kind)
99 { _pimpl->_kinds.push_back(kind); }
101 void PoolQuery::setCaseSensitive(const bool value)
104 _pimpl->_flags = (_pimpl->_flags & ~SEARCH_NOCASE);
106 _pimpl->_flags = (_pimpl->_flags | SEARCH_NOCASE);
109 void PoolQuery::setFlags(int flags)
110 { _pimpl->_flags = flags; }
113 void PoolQuery::execute(const string &term) const
116 sat::Pool pool(sat::Pool::instance());
117 for ( sat::Pool::RepoIterator itr = pool.reposBegin();
118 itr != pool.reposEnd();
121 cout << "repo: " << itr->name() << endl;
122 // is this repo in users repos?
123 bool included = ( find(_pimpl->_repos.begin(), _pimpl->_repos.end(), itr->name()) != _pimpl->_repos.end() );
124 // only look in user repos filter if the filter is not empty
125 // in this case we search in all
126 if ( _pimpl->_repos.empty() || included )
128 // now search in all names
129 //for ( vector<string>::const_iterator itn = _pimpl->_names.begin();
130 // itn != _pimpl->_names.end();
133 repo_search( itr->get(), 0, 0, term.c_str(), _pimpl->_flags, Impl::repo_search_cb, (void*) (this));
140 /******************************************************************
142 ** FUNCTION NAME : operator<<
143 ** FUNCTION TYPE : ostream &
145 ostream & operator<<( ostream & str, const PoolQuery & obj )
150 /////////////////////////////////////////////////////////////////
152 ///////////////////////////////////////////////////////////////////