ref: refs/heads/ma-tmp-pqt
commit 05fae1cc433b527b7d4bcf2e7d6f8c6d24afc741
Author: Michael Andres
Date: Fri Apr 17 10:17:59 2009 +0200
use DIWrap
---
devel/devel.ma/NewPool.cc | 9 +++-
zypp/PoolQuery.cc | 34 ++++------------
zypp/PoolQuery.h | 2 +-
zypp/sat/LookupAttr.cc | 98 +++++++++++++++++++-------------------------
zypp/sat/LookupAttr.h | 22 ++++------
5 files changed, 66 insertions(+), 99 deletions(-)
diff --git a/devel/devel.ma/NewPool.cc b/devel/devel.ma/NewPool.cc
index 0bc829c..0b68a79 100644
--- a/devel/devel.ma/NewPool.cc
+++ b/devel/devel.ma/NewPool.cc
@@ -463,6 +463,7 @@ bool querycompare( const PoolQuery & q )
for_( it, q.nbegin(), q.nend() )
{
++nc;
+// DBG << it << endl;
}
MIL << nc << endl;
}
@@ -470,6 +471,10 @@ bool querycompare( const PoolQuery & q )
{
Measure x( "old query" );
oc = q.size();
+/* for_( it, q.begin(), q.end() )
+ {
+ DBG << *it << endl;
+ }*/
MIL << oc << endl;
}
@@ -608,14 +613,14 @@ try {
///////////////////////////////////////////////////////////////////
std::string search("devel");
- //search = "";
PoolQuery q;
//querycompare( q );
q.addString(search);
+ //q.addAttribute(sat::SolvAttr::name, "augeas" );
q.addAttribute(sat::SolvAttr::name, "foo" );
- //q.addAttribute(sat::SolvAttr::summary);
+ q.addAttribute(sat::SolvAttr::summary);
q.setMatchSubstring();
//q.setMatchExact();
q.setCaseSensitive( true );
diff --git a/zypp/PoolQuery.cc b/zypp/PoolQuery.cc
index c33ce96..dc3f126 100644
--- a/zypp/PoolQuery.cc
+++ b/zypp/PoolQuery.cc
@@ -432,46 +432,28 @@ attremptycheckend:
//DBG << "_cflags:" << _cflags << endl;
- scoped_ptr< ::_Dataiterator> _rdit( new ::Dataiterator );
+ sat::detail::DIWrap dip;
// initialize the Dataiterator for different cases
if (_rcattrs.empty())
{
- ::dataiterator_init(_rdit.get(),
- pool.get(),
- repo.get(), // either NULL or the repo to search
- 0, // search all solvables
- 0, // attribute id - only if 1 attr key specified
- _rcstrings.empty() ? 0 : _rcstrings.c_str(), // compiled search string
- _cflags);
+ sat::detail::DIWrap( repo.get(), 0, 0, _rcstrings, _cflags ).swap( dip );
}
else if (_rcattrs.size() == 1)
{
- ::dataiterator_init(_rdit.get(),
- pool.get(),
- repo.get(), // either NULL or the repo to search
- 0, // search all solvables
- _rcattrs.begin()->first.id(), // keyname - attribute id - only if 1 attr key specified
- _rcstrings.empty() ? 0 : _rcstrings.c_str(), // compiled search string
- _cflags);
+ sat::detail::DIWrap( repo.get(), 0, _rcattrs.begin()->first.id(), _rcstrings, _cflags ).swap( dip );
}
else
{
- ::dataiterator_init(_rdit.get(),
- pool.get(),
- repo.get(), // either NULL or the repo to search
- 0, /*search all resolvables */
- 0, /*keyname - if only 1 attr key specified, pass it here, otherwise do more magic */
- 0, //qs.empty() ? 0 : qs.c_str(), /* create regex, pass it here */
- _cflags);
+ sat::detail::DIWrap( repo.get(), 0, 0, "", _cflags ).swap( dip );
}
- if ((_cflags & SEARCH_STRINGMASK) == SEARCH_REGEX && _rdit->matcher.error != 0)
+ if ((_cflags & SEARCH_STRINGMASK) == SEARCH_REGEX && dip->matcher.error != 0)
ZYPP_THROW(Exception(str::form(
_("Invalid regular expression '%s': regcomp returned %d"),
- _rcstrings.c_str(), _rdit->matcher.error)));
+ _rcstrings.c_str(), dip->matcher.error)));
- PoolQuery::const_iterator it(_rdit, this);
+ PoolQuery::const_iterator it(dip, this);
it.increment();
return it;
}
@@ -560,7 +542,7 @@ attremptycheckend:
PoolQueryIterator::PoolQueryIterator(
- scoped_ptr< ::_Dataiterator> & dip_r,
+ sat::detail::DIWrap & dip_r,
const PoolQuery::Impl * pqimpl)
: _sid(0)
, _has_next(true)
diff --git a/zypp/PoolQuery.h b/zypp/PoolQuery.h
index 6eb82d2..93ac803 100644
--- a/zypp/PoolQuery.h
+++ b/zypp/PoolQuery.h
@@ -477,7 +477,7 @@ namespace zypp
friend class PoolQuery::Impl;
PoolQueryIterator(
- scoped_ptr< ::_Dataiterator> & dip_r,
+ sat::detail::DIWrap & dip_r,
const PoolQuery::Impl * pqimpl);
const sat::Solvable dereference() const
diff --git a/zypp/sat/LookupAttr.cc b/zypp/sat/LookupAttr.cc
index aa2a710..8b850ac 100644
--- a/zypp/sat/LookupAttr.cc
+++ b/zypp/sat/LookupAttr.cc
@@ -110,35 +110,16 @@ namespace zypp
LookupAttr::iterator begin() const
{
- if ( _attr == SolvAttr::noAttr )
+ if ( _attr == SolvAttr::noAttr || sat::Pool::instance().reposEmpty() )
return end();
-#warning Need to call dataiterator_free, use Autodispose instead of scoped_ptr
- scoped_ptr< ::_Dataiterator> dip( new ::Dataiterator );
-
- const char * m = 0;
- int f = 0;
- if ( _attrMatcher )
- {
- m = _attrMatcher.searchstring().c_str();
- f = _attrMatcher.flags();
- }
-
+ detail::RepoIdType whichRepo = detail::noRepoId; // all repos
if ( _solv )
- {
- ::dataiterator_init( dip.get(), sat::Pool::instance().get(), _solv.repository().id(), _solv.id(), _attr.id(), m, f );
- }
+ whichRepo = _solv.repository().id();
else if ( _repo )
- {
- ::dataiterator_init( dip.get(), sat::Pool::instance().get(), _repo.id(), _solv.id(), _attr.id(), m, f );
- }
- else if ( ! sat::Pool::instance().reposEmpty() )
- {
- ::dataiterator_init( dip.get(), sat::Pool::instance().get(), 0, _solv.id(), _attr.id(), m, f );
- }
- else
- return end();
+ whichRepo = _repo.id();
+ detail::DIWrap dip( whichRepo, _solv.id(), _attr.id(), _attrMatcher.searchstring(), _attrMatcher.flags() );
return iterator( dip ); // iterator takes over ownership!
}
@@ -278,6 +259,15 @@ namespace zypp
namespace detail
{
+ DIWrap::DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
+ const std::string & mstring_r, int flags_r )
+ : _dip( new ::Dataiterator )
+ , _mstring( mstring_r )
+ {
+ ::dataiterator_init( _dip, sat::Pool::instance().get(), repoId_r, solvId_r, attrId_r,
+ _mstring.empty() ? 0 : _mstring.c_str(), flags_r );
+ }
+
DIWrap::DIWrap( const DIWrap & rhs )
: _dip( 0 )
, _mstring( rhs._mstring )
@@ -293,7 +283,17 @@ namespace zypp
::datamatcher_init( &matcher, _mstring.c_str(), matcher.flags );
}
else if ( matcher.match && matcher.match != _mstring.c_str() )
+ {
+ //SEC << "**" << rhs._dip << endl;
+ SEC << "r " << rhs._dip->matcher.match << endl;
+ SEC << "r " << rhs._dip->matcher.flags << endl;
+ SEC << "r " << (const void*)rhs._mstring.c_str() << "'" << rhs._mstring << "'" << endl;
+
+ SEC << "t " << matcher.match << endl;
+ SEC << "t " << matcher.flags << endl;
+ SEC << "t " << (const void*)_mstring.c_str() << "'" << _mstring << "'" << endl;
throw( "this cant be!" );
+ }
}
}
@@ -427,11 +427,8 @@ namespace zypp
// remember this position
::dataiterator_setpos( _dip.get() );
- // setup the new sub iterator
- scoped_ptr< ::_Dataiterator> dip( new ::Dataiterator );
-
- ::dataiterator_init( dip.get(), sat::Pool::instance().get(), 0, SOLVID_POS, 0, 0, 0 );
-
+ // setup the new sub iterator with the remembered position
+ detail::DIWrap dip( 0, SOLVID_POS, 0, 0, 0 );
return iterator( dip ); // iterator takes over ownership!
}
@@ -606,48 +603,40 @@ namespace zypp
// internal stuff below
///////////////////////////////////////////////////////////////////
- LookupAttr::iterator::~iterator()
- {
-
- }
-
LookupAttr::iterator::iterator()
: iterator_adaptor_( 0 )
{}
LookupAttr::iterator::iterator( const iterator & rhs )
- : iterator_adaptor_( cloneFrom( rhs.base() ) )
- , _dip( base() )
+ : iterator_adaptor_( 0 )
+ , _dip( rhs._dip )
+ {
+ base_reference() = _dip.get();
+ }
+
+ LookupAttr::iterator::iterator( detail::DIWrap & dip_r )
+ : iterator_adaptor_( 0 )
+ {
+ _dip.swap( dip_r ); // take ownership!
+ base_reference() = _dip.get();
+ increment();
+ }
+
+ LookupAttr::iterator::~iterator()
{}
LookupAttr::iterator & LookupAttr::iterator::operator=( const iterator & rhs )
{
if ( &rhs != this )
{
- _dip.reset( cloneFrom( rhs.base() ) );
+ _dip = rhs._dip;
base_reference() = _dip.get();
}
return *this;
}
- LookupAttr::iterator::iterator( scoped_ptr< ::_Dataiterator> & dip_r )
- : iterator_adaptor_( dip_r.get() )
- {
- _dip.swap( dip_r ); // take ownership!
- increment();
- }
-
///////////////////////////////////////////////////////////////////
- ::_Dataiterator * LookupAttr::iterator::cloneFrom( const ::_Dataiterator * rhs )
- {
- if ( ! rhs )
- return 0;
- ::_Dataiterator * ret( new ::_Dataiterator );
- *ret = *rhs;
- return ret;
- }
-
bool LookupAttr::iterator::dip_equal( const ::_Dataiterator & lhs, const ::_Dataiterator & rhs ) const
{
// Iterator equal is same position in same container.
@@ -665,9 +654,6 @@ namespace zypp
{
if ( _dip && ! ::dataiterator_step( _dip.get() ) )
{
-#warning MEMLEAK - DATAITERATOR FREE NEEDS TO BE EXTENDED - DTOR ASSIGN
- if ( 0 && _dip )
- ::dataiterator_free( _dip.get() );
_dip.reset();
base_reference() = 0;
}
diff --git a/zypp/sat/LookupAttr.h b/zypp/sat/LookupAttr.h
index f7def2d..9886609 100644
--- a/zypp/sat/LookupAttr.h
+++ b/zypp/sat/LookupAttr.h
@@ -251,7 +251,7 @@ namespace zypp
namespace detail
{
- /** Wrapper around sat dataiterator.
+ /** Wrapper around sat \c ::_Dataiterator.
*
* Manages copy and assign, and release of allocated
* resources like datamatcher inside the dataiterator.
@@ -261,17 +261,13 @@ namespace zypp
class DIWrap : private base::SafeBool<DIWrap>
{
public:
+ /** \c NULL \c ::_Dataiterator */
DIWrap()
: _dip( 0 )
{}
- /** Ctor takes over ownership of \b allocated dataiterator. */
- explicit DIWrap( ::_Dataiterator * allocated_r )
- : _dip( allocated_r )
- {}
- /** Ctor takes over ownership of \b allocated dataiterator. */
- DIWrap( ::_Dataiterator * allocated_r, const std::string & mstring_r )
- : _dip( allocated_r ), _mstring( mstring_r )
- {}
+ /** Initializes */
+ DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
+ const std::string & mstring_r = std::string(), int flags_r = 0 );
DIWrap( const DIWrap & rhs );
~DIWrap();
public:
@@ -490,16 +486,14 @@ namespace zypp
public:
/**
- * C-tor taking over ownership of the passed scoped _Dataiterator*
+ * C-tor taking over ownership of the passed \c ::_Dataiterator
* and doing it's first iteration (::dataiterator_step)
*/
- iterator( scoped_ptr< ::_Dataiterator> & dip_r );
+ iterator( detail::DIWrap & dip_r );
private:
friend class boost::iterator_core_access;
- ::_Dataiterator * cloneFrom( const ::_Dataiterator * rhs );
-
template
bool equal( const boost::iterator_adaptor & rhs ) const
{
@@ -518,7 +512,7 @@ namespace zypp
::_Dataiterator * get() const
{ return _dip.get(); }
private:
- scoped_ptr< ::_Dataiterator> _dip;
+ detail::DIWrap _dip;
};
///////////////////////////////////////////////////////////////////
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org