ref: refs/heads/ma-tmp-pqt
commit 984e3b1f22be251384dbeec1ec89e4736cb7cfd0
Author: Michael Andres
Date: Fri Apr 17 18:27:39 2009 +0200
Add Match Flags and excetion.
---
devel/devel.ma/Test.cc | 26 +++++++++-
zypp/PoolQuery.cc | 34 ++++++++----
zypp/PoolQuery.h | 10 ++++
zypp/sat/AttrMatcher.cc | 51 ++++++++++++++++++
zypp/sat/AttrMatcher.h | 132 ++++++++++++++++++++++++++++++++++++++++++++++-
zypp/sat/LookupAttr.h | 4 +-
6 files changed, 241 insertions(+), 16 deletions(-)
diff --git a/devel/devel.ma/Test.cc b/devel/devel.ma/Test.cc
index 646fb69..5255ee4 100644
--- a/devel/devel.ma/Test.cc
+++ b/devel/devel.ma/Test.cc
@@ -3,6 +3,7 @@
#include
#include
+#include
static TestSetup test( Arch_x86_64 ); // use x86_64 as system arch
@@ -16,13 +17,36 @@ int main( int argc, char * argv[] )
INT << "===[START]==========================================" << endl;
test.loadRepo( "/Local/ROOT/cache/solv/@System/solv" );
+ Match t( Match::REGEX );
+
+ MIL << (t|Match::STRING) << endl;
+ MIL << (t|Match::NOCASE) << endl;
+ MIL << (Match::STRING|t) << endl;
+ MIL << (Match::STRING|Match::NOCASE) << endl;
+
+
+ Match m = Match::STRING | Match::NOCASE | Match::GLOB ;
+ m = Match::NOCASE | Match::STRING;
+ MIL << m << endl;
+ MIL << m-Match::NOCASE << endl;
+
+ MIL << Match(8765) << endl;
+ MIL << Match() << endl;
+
+
+ INT << "===[END]============================================" << endl << endl;
+ return 0;
+
+
+
PoolQuery q;
q.addString("foo*|k?");
q.setMatchRegex();
for_( it, q.nbegin(), q.nend() )
{
- ;
+ zypp::PoolItem pi( zypp::ResPool::instance().find( *it ) );
+ MIL << pi.resolvable() << endl;
}
INT << "===[END]============================================" << endl << endl;
diff --git a/zypp/PoolQuery.cc b/zypp/PoolQuery.cc
index dc3f126..15941da 100644
--- a/zypp/PoolQuery.cc
+++ b/zypp/PoolQuery.cc
@@ -40,8 +40,6 @@ using namespace zypp::sat;
namespace zypp
{ /////////////////////////////////////////////////////////////////
-#warning CHECK FOR MEMLEAK DUE TO MISSING dataiterator_free
-
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : PoolQuery::Impl
@@ -61,9 +59,10 @@ namespace zypp
{}
public:
+#if USE_OLD_ITERATOR
const_iterator begin() const;
const_iterator end() const;
-
+#endif
string asString() const;
void compile() const;
@@ -407,7 +406,7 @@ attremptycheckend:
return rstr;
}
-
+#if USE_OLD_ITERATOR
PoolQuery::const_iterator PoolQuery::Impl::begin() const
{
compile();
@@ -463,7 +462,7 @@ attremptycheckend:
{
return PoolQuery::const_iterator();
}
-
+#endif
string PoolQuery::Impl::asString() const
{
@@ -913,16 +912,26 @@ attremptycheckend:
{ return _pimpl->_status_flags; }
PoolQuery::const_iterator PoolQuery::begin() const
- { return _pimpl->begin(); }
-
+ {
+#if USE_OLD_ITERATOR
+ return _pimpl->begin();
+#else
+ return nbegin();
+#endif
+ }
PoolQuery::const_iterator PoolQuery::end() const
- { return _pimpl->end(); }
-
+ {
+#if USE_OLD_ITERATOR
+ return _pimpl->end();
+#else
+ return nend();
+#endif
+ }
bool PoolQuery::empty() const
{
- try { return _pimpl->begin() == _pimpl->end(); }
+ try { return begin() == end(); }
catch (const Exception & ex) {}
return true;
}
@@ -933,7 +942,8 @@ attremptycheckend:
size_type count = 0;
try
{
- for(const_iterator it = _pimpl->begin(); it != _pimpl->end(); ++it, ++count);
+ for_( it, begin(), end() )
+ ++count;
}
catch (const Exception & ex) {}
@@ -942,7 +952,7 @@ attremptycheckend:
void PoolQuery::execute(ProcessResolvable fnc)
- { invokeOnEach(_pimpl->begin(), _pimpl->end(), fnc); }
+ { invokeOnEach( begin(), end(), fnc); }
///////////////////////////////////////////////////////////////////
diff --git a/zypp/PoolQuery.h b/zypp/PoolQuery.h
index 93ac803..d86b8af 100644
--- a/zypp/PoolQuery.h
+++ b/zypp/PoolQuery.h
@@ -34,6 +34,8 @@ namespace zypp
class NewPoolQueryIterator;
}
+#define USE_OLD_ITERATOR 0
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : PoolQuery
@@ -80,7 +82,11 @@ namespace zypp
* \see tests/zypp/PoolQuery_test.cc for more examples
* \see sat::SolvIterMixin
*/
+#if USE_OLD_ITERATOR
class PoolQuery : public sat::SolvIterMixin
+#else
+ class PoolQuery : public sat::SolvIterMixin
+#endif
{
public:
typedef std::setstd::string StrContainer;
@@ -89,7 +95,11 @@ namespace zypp
typedef std::map AttrCompiledStrMap;
typedef std::map AttrRegexMap;
+#if USE_OLD_ITERATOR
typedef detail::PoolQueryIterator const_iterator;
+#else
+ typedef detail::NewPoolQueryIterator const_iterator;
+#endif
typedef unsigned int size_type;
public:
diff --git a/zypp/sat/AttrMatcher.cc b/zypp/sat/AttrMatcher.cc
index 8aca558..f35ae08 100644
--- a/zypp/sat/AttrMatcher.cc
+++ b/zypp/sat/AttrMatcher.cc
@@ -16,6 +16,7 @@ extern "C"
#include <iostream>
#include "zypp/base/LogTools.h"
+#include "zypp/base/String.h"
#include "zypp/sat/AttrMatcher.h"
@@ -24,6 +25,56 @@ using std::endl;
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : Match
+ //
+ ///////////////////////////////////////////////////////////////////
+
+ const int Match::_modemask = SEARCH_STRINGMASK;
+
+ const Match Match::NOHTING ( 0 );
+
+ const Match Match::STRING (SEARCH_STRING);
+ const Match Match::SUBSTRING (SEARCH_SUBSTRING);
+ const Match Match::GLOB (SEARCH_GLOB);
+ const Match Match::REGEX (SEARCH_REGEX);
+
+ const Match Match::NOCASE (SEARCH_NOCASE);
+ const Match Match::NO_STORAGE_SOLVABLE(SEARCH_NO_STORAGE_SOLVABLE);
+ const Match Match::SUB (SEARCH_SUB);
+ const Match Match::ARRAYSENTINEL (SEARCH_ARRAYSENTINEL);
+ const Match Match::SKIP_KIND (SEARCH_SKIP_KIND);
+ const Match Match::FILES (SEARCH_FILES);
+
+ std::ostream & operator<<( std::ostream & str, const Match & obj )
+ {
+ if ( ! obj )
+ return str << "NOHTING";
+
+ int val = obj.get();
+ const char * sep = 0;
+#define OUTS(V) if ( val & Match::V.get() ) { val &= ~Match::V.get(); if ( sep ) str << sep; else sep = "|"; str << #V; }
+ OUTS( STRING );
+ OUTS( SUBSTRING );
+ OUTS( GLOB );
+ OUTS( REGEX );
+ OUTS( NOCASE );
+ OUTS( NO_STORAGE_SOLVABLE );
+ OUTS( SUB );
+ OUTS( ARRAYSENTINEL );
+ OUTS( SKIP_KIND );
+ OUTS( FILES );
+#undef OUTS
+ if ( val )
+ {
+ if ( sep ) str << sep;
+ str << zypp::str::hexstring( val );
+ }
+ return str;
+ }
+
///////////////////////////////////////////////////////////////////
namespace sat
{ /////////////////////////////////////////////////////////////////
diff --git a/zypp/sat/AttrMatcher.h b/zypp/sat/AttrMatcher.h
index 4e324fd..38607cb 100644
--- a/zypp/sat/AttrMatcher.h
+++ b/zypp/sat/AttrMatcher.h
@@ -26,6 +26,127 @@ struct _Datamatcher;
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : Match
+ //
+ /** String matching option flags as used e.g. by \ref sat::AttrMatcher.
+ * \code
+ * Match mode( Match::GLOB | Match::NOCASE );
+ * \endcode
+ */
+ struct Match : private base::SafeBool<Match>
+ {
+ /** \name Mode flags (mutual exclusive) */
+ //@{
+ static const Match STRING;
+ static const Match SUBSTRING;
+ static const Match GLOB;
+ static const Match REGEX;
+ //@}
+ /** \name Option flags
+ * Some flags are actually \ref sat::LookupAttr specific, as they tell
+ * how to retrieve the attribute values. The plain \ref sat::AttrMatcher
+ * will ignore those flags and use the ones related to string matching only
+ * (like \ref NOCASE).
+ */
+ //@{
+ static const Match NOCASE;
+ static const Match NO_STORAGE_SOLVABLE;
+ static const Match SUB;
+ static const Match ARRAYSENTINEL;
+ static const Match SKIP_KIND;
+ static const Match FILES;
+ //@}
+
+ public:
+ /** \c 0 */
+ static const Match NOHTING;
+
+ /** Default ctor \c 0 or \ref NOHTING. */
+ Match()
+ : _val( 0 )
+ {}
+
+ /** Just in case one needs it. */
+ explicit Match( int val_r )
+ : _val( val_r )
+ {}
+
+#ifndef SWIG // Swig treats it as syntax error
+ /** Evaluate in a boolean context <tt>( != 0 )</tt>. */
+ using base::SafeBool<Match>::operator bool_type;
+#endif
+
+ public:
+ /** Add flags (switching the mode, if mode is set in \c rhs). */
+ Match & operator|=( const Match & rhs )
+ {
+ if ( rhs._val & _modemask )
+ _val = rhs._val | ( _val & ~_modemask );
+ else
+ _val |= rhs._val;
+ return *this;
+ }
+
+ /** Remove option flags (Not changing the mode part).*/
+ Match & operator-=( const Match & rhs )
+ {
+ _val &= _modemask | ~rhs._val;
+ return *this;
+ }
+
+ public:
+ /** Whether at least one of the \a rhs bits is set. */
+ bool anyOf( const Match & rhs ) const
+ { return _val & rhs._val; }
+
+ /** Whether all of the \a rhs bits are set. */
+ bool allOf( const Match & rhs ) const
+ { return (_val & rhs._val) == rhs._val; }
+
+ /** Return the \c mode part. */
+ Match mode() const
+ { return Match( _val & _modemask ); }
+
+ /** Return the \c flags part. */
+ Match flags() const
+ { return Match( _val & ~_modemask ); }
+
+ /** Return the integer representation. */
+ int get() const
+ { return _val; }
+
+ private:
+ friend base::SafeBool<Match>::operator bool_type() const;
+ bool boolTest() const
+ { return _val; }
+
+ private:
+ int _val;
+ static const int _modemask;
+ };
+
+ /** \relates Match */
+ inline bool operator==( const Match & lhs, const Match & rhs )
+ { return lhs.get() == rhs.get(); }
+ /** \relates Match */
+ inline bool operator!=( const Match & lhs, const Match & rhs )
+ { return lhs.get() != rhs.get(); }
+
+ /** \relates Match */
+ inline Match operator|( const Match & lhs, const Match & rhs )
+ { return Match(lhs) |= rhs; }
+ /** \relates Match */
+ inline Match operator-( const Match & lhs, const Match & rhs )
+ { return Match(lhs) -= rhs; }
+
+ /** \relates Match Stream output */
+ std::ostream & operator<<( std::ostream & str, const Match & obj );
+
+ ///////////////////////////////////////////////////////////////////
+
///////////////////////////////////////////////////////////////////
namespace sat
{ /////////////////////////////////////////////////////////////////
@@ -105,9 +226,16 @@ namespace zypp
/** Set new search flags. */
void setFlags( int flags_r );
- private:
- /** Return whether string matches.
+ public:
+ /** Compile the pattern e.g. in case of \c REGEX.
+ * \throws MatchInvalidRegexException If \ref Match::REGEX is set
+ * and \ref searchstring is not a valid regular expression.
*/
+ void compile() const;
+ /
+ bool isCompiled() const;
+ private:
+ /** Return whether string matches. */
bool doMatch( const char * string_r ) const;
private:
diff --git a/zypp/sat/LookupAttr.h b/zypp/sat/LookupAttr.h
index eff1ce2..ea5f7ce 100644
--- a/zypp/sat/LookupAttr.h
+++ b/zypp/sat/LookupAttr.h
@@ -162,7 +162,9 @@ namespace zypp
*/
const AttrMatcher & attrMatcher() const;
- /** Set the pattern to match. */
+ /** Set the pattern to match.
+ * \throws MatchException Any of the exceptions thrown by \ref AttrMatcher::compile.
+ */
void setAttrMatcher( const AttrMatcher & matcher_r );
/** Reset the pattern to match. */
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org