From: Michael Andres Date: Thu, 28 May 2009 11:01:41 +0000 (+0200) Subject: Prepare support for additional (non string) predicates in PoolQueryMatcher. X-Git-Tag: 6.7.0~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=84578a55ce28dfdbd885d1904f9543b55c5367ea;p=platform%2Fupstream%2Flibzypp.git Prepare support for additional (non string) predicates in PoolQueryMatcher. --- diff --git a/zypp/PoolQuery.cc b/zypp/PoolQuery.cc index f7cdc8588..b14d5784c 100644 --- a/zypp/PoolQuery.cc +++ b/zypp/PoolQuery.cc @@ -25,11 +25,6 @@ #include "zypp/PoolQuery.h" -extern "C" -{ -//#include "satsolver/repo.h" -} - #undef ZYPP_BASE_LOGGER_LOGGROUP #define ZYPP_BASE_LOGGER_LOGGROUP "PoolQuery" @@ -40,6 +35,54 @@ using namespace zypp::sat; namespace zypp { ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace + { ///////////////////////////////////////////////////////////////// + + /** Match data per attribtue. + * + * This includes the attribute itself, an optional \ref sat::AttrMatcher + * to restrict the query to certain string values, and an optional + * boolean \ref Predicate that may apply further restrictions that can + * not be expressed by the \ref attrMatcher. + * + * Example for such a \ref predicate would be an additional edition range + * check whan looking for dependencies. The \ref attrMatcher would + * find potential matches by looking at the dependencies name, the + * predicate will then check the edition ranges. + * + * As the \ref predicate takes an iterator pointing to the current + * match, it's also suitable for sub-structure (flexarray) inspection + * (\see \ref sat::LookupAttr::iterator::solvAttrSubEntry). + */ + struct AttrMatchData + { + typedef function Predicate; + + static bool always( sat::LookupAttr::iterator ) { return true; } + static bool never( sat::LookupAttr::iterator ) { return false; } + + AttrMatchData( sat::SolvAttr attr_r, const sat::AttrMatcher & attrMatcher_r ) + : attr( attr_r ) + , attrMatcher( attrMatcher_r ) + { /*predicate = always;*/ } + + sat::SolvAttr attr; + sat::AttrMatcher attrMatcher; + Predicate predicate; + }; + + std::ostream & operator<<( std::ostream & str, const AttrMatchData & obj ) + { + return str << obj.attr << ": " << obj.attrMatcher << ( obj.predicate ? " (+predicate)" : "" ); + } + + typedef std::list AttrMatchList; + + } ///////////////////////////////////////////////////////////////// + // namespace + /////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// // // CLASS NAME : PoolQuery::Impl @@ -97,8 +140,7 @@ namespace zypp void compile() const; /** AttrMatcher per attribtue. */ - typedef std::pair AttrMatchData; - mutable std::vector _attrMatchList; + mutable AttrMatchList _attrMatchList; private: /** Pass flags from \ref compile, as they may have been changed. */ @@ -266,7 +308,7 @@ attremptycheckend: // Check here, whether all involved regex compile. for_( it, _attrMatchList.begin(), _attrMatchList.end() ) { - it->second.compile(); // throws on error + it->attrMatcher.compile(); // throws on error } //DBG << asString() << endl; } @@ -428,7 +470,7 @@ attremptycheckend: { for_( it, _attrMatchList.begin(), _attrMatchList.end() ) { - o << "* " << it->first << ": " << it->second << endl; + o << "* " << *it << endl; } } return o.str(); @@ -990,7 +1032,6 @@ attremptycheckend: { public: typedef sat::LookupAttr::iterator base_iterator; - typedef std::pair AttrMatchData; public: const base_iterator & end() const @@ -1063,10 +1104,10 @@ attremptycheckend: // Attribute restriction: if ( _attrMatchList.size() == 1 ) // all (SolvAttr::allAttr) or 1 attr { - const AttrMatchData & matchData( _attrMatchList[0] ); - q.setAttr( matchData.first ); - if ( matchData.second ) // empty searchstring matches always - q.setAttrMatcher( matchData.second ); + const AttrMatchData & matchData( _attrMatchList.front() ); + q.setAttr( matchData.attr ); + if ( matchData.attrMatcher ) // empty searchstring matches always + q.setAttrMatcher( matchData.attrMatcher ); } else // more than 1 attr (but not all) { @@ -1131,9 +1172,9 @@ attremptycheckend: for_( mi, _attrMatchList.begin(), _attrMatchList.end() ) { const AttrMatchData & matchData( *mi ); - sat::LookupAttr q( matchData.first, inSolvable ); - if ( matchData.second ) // empty searchstring matches always - q.setAttrMatcher( matchData.second ); + sat::LookupAttr q( matchData.attr, inSolvable ); + if ( matchData.attrMatcher ) // empty searchstring matches always + q.setAttrMatcher( matchData.attrMatcher ); if ( ! q.empty() ) return true; } @@ -1152,7 +1193,7 @@ attremptycheckend: /** Installed status filter flags. \see PoolQuery::StatusFilter */ int _status_flags; /** AttrMatcher per attribtue. */ - std::vector _attrMatchList; + AttrMatchList _attrMatchList; }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/PoolQuery.h b/zypp/PoolQuery.h index 49af6ae48..0bf38caad 100644 --- a/zypp/PoolQuery.h +++ b/zypp/PoolQuery.h @@ -193,6 +193,13 @@ namespace zypp * This can be changed by (not yet implemented) \ref setRequireAll() * method. * + * \note Though it is possible to use dependency attributes like + * \ref Solv::Attr::provides here, note that the query string is + * matched against a dependencies \c "name" part only. Any + * "op edition" part of a \ref Capability is \b not + * considered at all. \see \ref addDependency on how to query for + * capabilities including edition ranges. + * * \note Solvables of a kind not supporting the specified attribute will * not be returned. * \todo check the above @@ -204,6 +211,14 @@ namespace zypp */ void addAttribute(const sat::SolvAttr & attr, const std::string & value = ""); + /* + * Query for matching dependency attributes. + * + * \throws Exception if \a attr is not a dependency attribute + */ + //void addDependency( const sat::SolvAttr & attr, Capability cap_r ); + //void addDependency( const sat::SolvAttr & attr, const std::string & name = ""); + /** * Set version condition. This will filter out solvables not matching * solvableEdition \a op \a edition.