Author: jkupec
Date: Thu Apr 10 02:36:45 2008
New Revision: 9499
URL: http://svn.opensuse.org/viewcvs/zypp?rev=9499&view=rev
Log:
- derive from SolvIterMixin
- some cleanup
Modified:
trunk/libzypp/tests/zypp/PoolQuery_test.cc
trunk/libzypp/zypp/PoolQuery.cc
trunk/libzypp/zypp/PoolQuery.h
Modified: trunk/libzypp/tests/zypp/PoolQuery_test.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/PoolQuery_test.cc?rev=9499&r1=9498&r2=9499&view=diff
==============================================================================
--- trunk/libzypp/tests/zypp/PoolQuery_test.cc (original)
+++ trunk/libzypp/tests/zypp/PoolQuery_test.cc Thu Apr 10 02:36:45 2008
@@ -48,6 +48,25 @@
init_pool();
}
+BOOST_AUTO_TEST_CASE(pool_query_exp)
+{
+ cout << "****exp****" << endl;
+
+ PoolQuery q;
+ q.addString("zypper");
+ q.addAttribute(sat::SolvAttr::name);
+
+ // should list 2 selectables
+ for (PoolQuery::Selectable_iterator it = q.selectableBegin();
+ it != q.selectableEnd(); ++it)
+ {
+ ui::Selectable::Ptr s = *it;
+ cout << s->kind() << ":" << s->name() << " hasinstalled: " << s->installedEmpty() << endl;
+ }
+
+ std::for_each(q.begin(), q.end(), &result_cb);
+}
+
/////////////////////////////////////////////////////////////////////////////
// 0xx basic queries
/////////////////////////////////////////////////////////////////////////////
Modified: trunk/libzypp/zypp/PoolQuery.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PoolQuery.cc?rev=9499&r1=9498&r2=9499&view=diff
==============================================================================
--- trunk/libzypp/zypp/PoolQuery.cc (original)
+++ trunk/libzypp/zypp/PoolQuery.cc Thu Apr 10 02:36:45 2008
@@ -11,32 +11,23 @@
*/
#include <iostream>
#include <sstream>
-#include <list>
-#include <vector>
-#include <algorithm>
-#include
#include "zypp/base/Gettext.h"
#include "zypp/base/Logger.h"
-#include "zypp/base/PtrTypes.h"
-#include "zypp/base/DefaultIntegral.h"
#include "zypp/base/Regex.h"
#include "zypp/base/Algorithm.h"
-#include "zypp/base/UserRequestException.h"
#include "zypp/repo/RepoException.h"
#include "zypp/sat/Pool.h"
#include "zypp/sat/Solvable.h"
-#include "zypp/sat/SolvAttr.h"
-#include "zypp/sat/detail/PoolImpl.h"
+
+#include "zypp/PoolQuery.h"
extern "C"
{
#include "satsolver/repo.h"
}
-#include "zypp/PoolQuery.h"
-
using namespace std;
using namespace zypp::sat;
@@ -63,40 +54,8 @@
{}
public:
-/*
- static int repo_search_cb(void *cbdata, ::Solvable *s, ::Repodata *data, ::Repokey *key, ::KeyValue *kv)
- {
- PoolQuery *me = (PoolQuery*) cbdata;
-
- bool r = false;
-
- sat::Solvable solvable(s - sat::Pool::instance().get()->solvables);
-
- // now filter by kind here (we cant do it before)
- if ( ! me->_pimpl->_kinds.empty() )
- {
- // the user wants to filter by kind.
- if ( find( me->_pimpl->_kinds.begin(),
- me->_pimpl->_kinds.end(),
- solvable.kind() )
- == me->_pimpl->_kinds.end() )
- {
- // we did not find the kind in the list
- // so this is not a result.
- return SEARCH_NEXT_SOLVABLE;
- }
- }
-
- if (me->_pimpl->_fnc)
- r = me->_pimpl->_fnc( solvable );//makeResObject(solvable) );
-
- if (!r)
- return SEARCH_STOP;
- return SEARCH_NEXT_SOLVABLE;
- }
- */
- ResultIterator begin() const;
- ResultIterator end() const;
+ const_iterator begin() const;
+ const_iterator end() const;
string asString() const;
@@ -369,7 +328,7 @@
}
- PoolQuery::ResultIterator PoolQuery::Impl::begin() const
+ PoolQuery::const_iterator PoolQuery::Impl::begin() const
{
compile();
@@ -422,15 +381,15 @@
ZYPP_THROW(Exception(
str::form(_("Invalid regular expression '%s'"), _rcstrings.c_str())));
- PoolQuery::ResultIterator it(this);
+ PoolQuery::const_iterator it(this);
it.increment();
return it;
}
- PoolQuery::ResultIterator PoolQuery::Impl::end() const
+ PoolQuery::const_iterator PoolQuery::Impl::end() const
{
INT << "end" << endl;
- return PoolQuery::ResultIterator();
+ return PoolQuery::const_iterator();
}
@@ -495,13 +454,17 @@
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
+ namespace detail
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
//
// CLASS NAME : PoolQuery::ResultIterator
//
///////////////////////////////////////////////////////////////////
- PoolQuery::ResultIterator::ResultIterator(const Impl * pqimpl)
- : PoolQuery::ResultIterator::iterator_adaptor_(pqimpl ? &pqimpl->_rdit : 0)
+ PoolQueryIterator::PoolQueryIterator(const PoolQuery::Impl * pqimpl)
+ : PoolQueryIterator::iterator_adaptor_(pqimpl ? &pqimpl->_rdit : 0)
, _rdit(pqimpl ? &pqimpl->_rdit : 0)
, _pqimpl(pqimpl)
, _sid(0)
@@ -514,7 +477,7 @@
_do_matching = true;
}
- void PoolQuery::ResultIterator::increment()
+ void PoolQueryIterator::increment()
{
if (!_rdit)
return;
@@ -536,7 +499,7 @@
DBG << "next: " << _sid << endl;
}
- bool PoolQuery::ResultIterator::matchSolvable()
+ bool PoolQueryIterator::matchSolvable()
{
_sid = _rdit->solvid;
@@ -565,7 +528,7 @@
drop_by_kind_status = false;
// whether to drop an uninstalled (repo) solvable
- if ( (_pqimpl->_status_flags & INSTALLED_ONLY) &&
+ if ( (_pqimpl->_status_flags & PoolQuery::INSTALLED_ONLY) &&
_rdit->repo->name != _pool.systemRepoName() )
{
drop_by_kind_status = true;
@@ -573,7 +536,7 @@
}
// whether to drop an installed (target) solvable
- if ((_pqimpl->_status_flags & UNINSTALLED_ONLY) &&
+ if ((_pqimpl->_status_flags & PoolQuery::UNINSTALLED_ONLY) &&
_rdit->repo->name == _pool.systemRepoName())
{
drop_by_kind_status = true;
@@ -600,7 +563,7 @@
if (!matches && in_repo)
{
SolvAttr attr(_rdit->key->name);
- CompiledAttrMap::const_iterator ai = _attrs.find(attr);
+ PoolQuery::CompiledAttrMap::const_iterator ai = _attrs.find(attr);
if (ai != _attrs.end())
{
const string & sstr =
@@ -662,6 +625,10 @@
}
///////////////////////////////////////////////////////////////////
+ } //namespace detail
+ ///////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
//
// CLASS NAME : PoolQuery
//
@@ -772,11 +739,11 @@
- PoolQuery::ResultIterator PoolQuery::begin() const
+ PoolQuery::const_iterator PoolQuery::begin() const
{ return _pimpl->begin(); }
- PoolQuery::ResultIterator PoolQuery::end() const
+ PoolQuery::const_iterator PoolQuery::end() const
{ return _pimpl->end(); }
@@ -787,49 +754,18 @@
PoolQuery::size_type PoolQuery::size()
{
size_type count = 0;
- for(ResultIterator it = _pimpl->begin(); it != _pimpl->end(); ++it, ++count);
+ for(const_iterator it = _pimpl->begin(); it != _pimpl->end(); ++it, ++count);
return count;
}
void PoolQuery::execute(ProcessResolvable fnc)
- {
- invokeOnEach(_pimpl->begin(), _pimpl->end(), fnc);
- /*
- _pimpl->_fnc = fnc;
- string term;
- if (!_pimpl->_strings.empty())
- term = *_pimpl->_strings.begin();
+ { invokeOnEach(_pimpl->begin(), _pimpl->end(), fnc); }
- sat::Pool pool(sat::Pool::instance());
- for ( sat::Pool::RepositoryIterator itr = pool.reposBegin();
- itr != pool.reposEnd();
- ++itr )
- {
- // filter by installed uninstalled
- if ( ( _pimpl->_status_flags & INSTALLED_ONLY ) && (itr->name() != sat::Pool::instance().systemRepoName()) )
- continue;
-
- if ( ( _pimpl->_status_flags & UNINSTALLED_ONLY ) && (itr->name() == sat::Pool::instance().systemRepoName()) )
- continue;
-
- // is this repo in users repos?
- bool included = ( find(_pimpl->_repos.begin(), _pimpl->_repos.end(), itr->name()) != _pimpl->_repos.end() );
-
- // only look in user repos filter if the filter is not empty
- // in this case we search in all
- if ( _pimpl->_repos.empty() || included )
- {
- repo_search( itr->get(), 0, 0, term.c_str(), _pimpl->_flags, Impl::repo_search_cb, (void*) (this));
- }
-
- }
- */
- }
///////////////////////////////////////////////////////////////////
//
- // CLASS NAME : PoolQuery::Impl
+ // CLASS NAME : PoolQuery::Attr
//
/**
* represents all atributes in PoolQuery except SolvAtributes, which are
Modified: trunk/libzypp/zypp/PoolQuery.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PoolQuery.h?rev=9499&r1=9498&r2=9499&view=diff
==============================================================================
--- trunk/libzypp/zypp/PoolQuery.h (original)
+++ trunk/libzypp/zypp/PoolQuery.h Thu Apr 10 02:36:45 2008
@@ -12,8 +12,9 @@
#ifndef ZYPP_POOLQUERY_H
#define ZYPP_POOLQUERY_H
-#include "zypp/ui/Selectable.h"
+#include "zypp/Resolvable.h"
#include "zypp/sat/SolvAttr.h"
+#include "zypp/sat/SolvIterMixin.h"
#include "zypp/base/Function.h"
@@ -26,6 +27,11 @@
namespace zypp
{ /////////////////////////////////////////////////////////////////
+ namespace detail
+ {
+ class PoolQueryIterator;
+ }
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : PoolQuery
@@ -36,13 +42,14 @@
*
* TODO: details, examples.
*/
- class PoolQuery
+ class PoolQuery : public sat::SolvIterMixin
{
public:
typedef std::setstd::string StrContainer;
typedef std::setResolvable::Kind Kinds;
typedef std::map AttrMap;
typedef std::map CompiledAttrMap;
+ typedef detail::PoolQueryIterator const_iterator;
typedef unsigned int size_type;
public:
@@ -53,12 +60,12 @@
/** Query result accessers. */
//@{
- class ResultIterator;
+ class PoolQueryIterator;
/** */
- ResultIterator begin() const;
+ const_iterator begin() const;
/** */
- ResultIterator end() const;
+ const_iterator end() const;
/** */
bool empty();
/** */
@@ -272,34 +279,40 @@
bool equal(const PoolQuery& a, const PoolQuery& b);
bool operator==(const PoolQuery& a, const PoolQuery& b);
+
+ ///////////////////////////////////////////////////////////////////
+ namespace detail
+ { /////////////////////////////////////////////////////////////////
+
+
///////////////////////////////////////////////////////////////////
//
- // CLASS NAME : PoolQuery::ResultIterator
+ // CLASS NAME : PoolQuery::PoolQueryIterator
//
/**
*
*/
- class PoolQuery::ResultIterator : public boost::iterator_adaptor<
- ResultIterator // Derived
+ class PoolQueryIterator : public boost::iterator_adaptor<
+ PoolQueryIterator // Derived
, ::_Dataiterator * // Base
- , sat::Solvable // Value
+ , const sat::Solvable // Value
, boost::forward_traversal_tag // CategoryOrTraversal
- , sat::Solvable // Reference
+ , const sat::Solvable // Reference
{
public:
- ResultIterator()
- : ResultIterator::iterator_adaptor_(0), _has_next(true),
- _attrs(CompiledAttrMap()), _do_matching(false), _pool((sat::Pool::instance()))
+ PoolQueryIterator()
+ : PoolQueryIterator::iterator_adaptor_(0), _has_next(true),
+ _attrs(PoolQuery::CompiledAttrMap()), _do_matching(false), _pool((sat::Pool::instance()))
{ _rdit = 0; _sid = 0; }
private:
friend class boost::iterator_core_access;
- friend class PoolQuery;
+ friend class PoolQuery::Impl;
- ResultIterator(const Impl * pqimpl);
+ PoolQueryIterator(const PoolQuery::Impl * pqimpl);
- sat::Solvable dereference() const
+ const sat::Solvable dereference() const
{
return _sid ? sat::Solvable(_sid) : sat::Solvable::noSolvable;
}
@@ -326,12 +339,15 @@
const PoolQuery::Impl * _pqimpl;
/*SolvableId*/ int _sid;
bool _has_next;
- const CompiledAttrMap & _attrs;
+ const PoolQuery::CompiledAttrMap & _attrs;
bool _do_matching;
sat::Pool _pool;
};
///////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ } //namespace detail
+ ///////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
} // namespace zypp
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org