ref: refs/heads/ma-misc
commit 00b70d9d9a92477e0b0a0d2c52be519dd2e8b6cb
Author: Michael Andres
Date: Wed Jul 1 18:21:52 2009 +0200
Support PoolQuery for sub-structures attributes. (fate #305503)
---
tests/sat/LookupAttr_test.cc | 6 +++---
zypp/sat/LookupAttr.cc | 23 +++++++++++++++++++----
zypp/sat/LookupAttr.h | 4 +++-
zypp/sat/SolvAttr.cc | 24 ++++++++++++++++++++++++
zypp/sat/SolvAttr.h | 34 +++++++++++++++++++++++-----------
5 files changed, 72 insertions(+), 19 deletions(-)
diff --git a/tests/sat/LookupAttr_test.cc b/tests/sat/LookupAttr_test.cc
index 6ee003d..8b7ce75 100644
--- a/tests/sat/LookupAttr_test.cc
+++ b/tests/sat/LookupAttr_test.cc
@@ -190,9 +190,9 @@ BOOST_AUTO_TEST_CASE(LookupAttr_solvable_attribute_substructure)
// BOOST_CHECK_EQUAL( res.subFind( sat::SolvAttr::updateReferenceType ).subBegin(), res.subBegin() );
}
- // search substructure id without parent-structure won't work:
- q = sat::LookupAttr( sat::SolvAttr::updateReferenceId );
- BOOST_CHECK_EQUAL( q.size(), 0 );
+ // search substructure id without parent-structure works for wellknown structures:
+ // q = sat::LookupAttr( sat::SolvAttr::updateReferenceId );
+ BOOST_CHECK_EQUAL( q.size(), 303 );
// search id in parent-structure:
q = sat::LookupAttr( sat::SolvAttr::updateReferenceId, sat::SolvAttr::updateReference );
diff --git a/zypp/sat/LookupAttr.cc b/zypp/sat/LookupAttr.cc
index 71acfab..6f4cf80 100644
--- a/zypp/sat/LookupAttr.cc
+++ b/zypp/sat/LookupAttr.cc
@@ -56,15 +56,16 @@ namespace zypp
{
public:
Impl()
+ : _parent( SolvAttr::noAttr )
{}
Impl( SolvAttr attr_r, Location loc_r )
- : _attr( attr_r ), _parent( SolvAttr::noAttr ), _solv( loc_r == REPO_ATTR ? SOLVID_META : noSolvableId )
+ : _attr( attr_r ), _parent( attr_r.parent() ), _solv( loc_r == REPO_ATTR ? SOLVID_META : noSolvableId )
{}
Impl( SolvAttr attr_r, Repository repo_r, Location loc_r )
- : _attr( attr_r ), _parent( SolvAttr::noAttr ), _repo( repo_r ), _solv( loc_r == REPO_ATTR ? SOLVID_META : noSolvableId )
+ : _attr( attr_r ), _parent( attr_r.parent() ), _repo( repo_r ), _solv( loc_r == REPO_ATTR ? SOLVID_META : noSolvableId )
{}
Impl( SolvAttr attr_r, Solvable solv_r )
- : _attr( attr_r ), _parent( SolvAttr::noAttr ), _solv( solv_r )
+ : _attr( attr_r ), _parent( attr_r.parent() ), _solv( solv_r )
{}
public:
@@ -72,7 +73,12 @@ namespace zypp
{ return _attr; }
void setAttr( SolvAttr attr_r )
- { _attr = attr_r; }
+ {
+ _attr = attr_r;
+ SolvAttr p( _attr.parent() );
+ if ( p != SolvAttr::noAttr )
+ _parent = p;
+ }
const AttrMatcher & attrMatcher() const
{ return _attrMatcher; }
@@ -132,6 +138,7 @@ namespace zypp
detail::DIWrap dip( whichRepo, _solv.id(), _attr.id(), _attrMatcher.searchstring(), _attrMatcher.flags().get() );
if ( _parent != SolvAttr::noAttr )
::dataiterator_prepend_keyname( dip.get(), _parent.id() );
+
return iterator( dip ); // iterator takes over ownership!
}
@@ -314,6 +321,14 @@ namespace zypp
{
_dip = new ::Dataiterator;
*_dip = *rhs._dip;
+ if ( _dip->nparents )
+ {
+ for ( int i = 1; i < _dip->nparents; ++i )
+ {
+ _dip->parents[i].kv.parent = &_dip->parents[i-1].kv;
+ }
+ _dip->kv.parent = &_dip->parents[_dip->nparents-1].kv;
+ }
// now we have to manually clone any allocated regex data matcher.
::Datamatcher & matcher( _dip->matcher );
if ( matcher.match && ( matcher.flags & SEARCH_STRINGMASK ) == SEARCH_REGEX )
diff --git a/zypp/sat/LookupAttr.h b/zypp/sat/LookupAttr.h
index 5af9688..9b2ed28 100644
--- a/zypp/sat/LookupAttr.h
+++ b/zypp/sat/LookupAttr.h
@@ -63,7 +63,9 @@ namespace zypp
* To search for attributes located in a sub-structure (flexarray)
* you also have to pass the sub-structures attribute as parent.
* Passing \ref SolvAttr::allAttr a parent will lookup the attribute
- * in \c any sub-structure.
+ * in \c any sub-structure. Few attributes are known to have a parent
+ * (\see \ref SolvAttr::parent). Setting those attributes will automatically
+ * initialize their parent value.
*
* \code
* // Lookup all 'name' attributes:
diff --git a/zypp/sat/SolvAttr.cc b/zypp/sat/SolvAttr.cc
index 83a98d3..f43e4fb 100644
--- a/zypp/sat/SolvAttr.cc
+++ b/zypp/sat/SolvAttr.cc
@@ -136,6 +136,30 @@ namespace sat
const SolvAttr SolvAttr::repositoryRpmDbCookie ( REPOSITORY_RPMDBCOOKIE );
const SolvAttr SolvAttr::repositoryDeltaInfo ( REPOSITORY_DELTAINFO );
+ /////////////////////////////////////////////////////////////////
+
+ SolvAttr SolvAttr::parent() const
+ {
+ switch( id() )
+ {
+ case UPDATE_COLLECTION_NAME:
+ case UPDATE_COLLECTION_EVR:
+ case UPDATE_COLLECTION_ARCH:
+ case UPDATE_COLLECTION_FILENAME:
+ case UPDATE_COLLECTION_FLAGS:
+ return updateCollection;
+ break;
+
+ case UPDATE_REFERENCE_TYPE:
+ case UPDATE_REFERENCE_HREF:
+ case UPDATE_REFERENCE_ID:
+ case UPDATE_REFERENCE_TITLE:
+ return updateReference;
+ break;
+ }
+ return noAttr;
+ }
+
} // namespace sat
/////////////////////////////////////////////////////////////////
} // namespace zypp
diff --git a/zypp/sat/SolvAttr.h b/zypp/sat/SolvAttr.h
index a8d59f9..4e51594 100644
--- a/zypp/sat/SolvAttr.h
+++ b/zypp/sat/SolvAttr.h
@@ -33,6 +33,8 @@ namespace sat
* Attributes associated with individual solvables,
* or with the repository as a whole.
*
+ * \note If you add well known subsructure attributes, update \ref parent.
+ *
* \see \ref LookupAttr
*/
class SolvAttr : public IdStringType<SolvAttr>
@@ -109,17 +111,17 @@ namespace sat
static const SolvAttr restartSuggested;
static const SolvAttr reloginSuggested;
static const SolvAttr message;
- static const SolvAttr updateCollection;
- static const SolvAttr updateCollectionName;
- static const SolvAttr updateCollectionEvr;
- static const SolvAttr updateCollectionArch;
- static const SolvAttr updateCollectionFilename;
- static const SolvAttr updateCollectionFlags;
- static const SolvAttr updateReference;
- static const SolvAttr updateReferenceType;
- static const SolvAttr updateReferenceHref;
- static const SolvAttr updateReferenceId;
- static const SolvAttr updateReferenceTitle;
+ static const SolvAttr updateCollection; // SUB-STRUCTURE:
+ static const SolvAttr updateCollectionName; // name
+ static const SolvAttr updateCollectionEvr; // evr
+ static const SolvAttr updateCollectionArch; // arch
+ static const SolvAttr updateCollectionFilename; // filename
+ static const SolvAttr updateCollectionFlags; // flags
+ static const SolvAttr updateReference; // SUB-STRUCTURE:
+ static const SolvAttr updateReferenceType; // type
+ static const SolvAttr updateReferenceHref; // href
+ static const SolvAttr updateReferenceId; // id
+ static const SolvAttr updateReferenceTitle; // title
//@}
/** \name pattern */
@@ -176,6 +178,16 @@ namespace sat
explicit SolvAttr( const std::string & str_r ) : _str( str_r ) {}
explicit SolvAttr( const char * cstr_r ) : _str( cstr_r ) {}
+ /** Return the parent of well know sub-structure attributes (\ref SolvAttr::noAttr if none).
+ * \li \ref updateCollection
+ * \li \ref updateReference
+ */
+ SolvAttr parent() const;
+
+ /** Whether this is a well know sub-structure attribute. */
+ bool hasParent() const
+ { return parent() != noAttr; }
+
private:
friend class IdStringType<SolvAttr>;
IdString _str;
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org