Add AttrMatcher == != and < (for std::container)
authorMichael Andres <ma@suse.de>
Wed, 2 Sep 2009 13:46:47 +0000 (15:46 +0200)
committerMichael Andres <ma@suse.de>
Thu, 3 Sep 2009 11:37:33 +0000 (13:37 +0200)
zypp/sat/AttrMatcher.cc
zypp/sat/AttrMatcher.h

index 6001110..1a522a7 100644 (file)
@@ -275,6 +275,10 @@ namespace zypp
     : _pimpl( new Impl( search_r, flags_r ) )
     {}
 
+    AttrMatcher::AttrMatcher( const std::string & search_r, const Match::Mode & flags_r )
+    : _pimpl( new Impl( search_r, flags_r ) )
+    {}
+
     AttrMatcher::AttrMatcher( const std::string & search_r, int flags_r )
     : _pimpl( new Impl( search_r, Match(flags_r) ) )
     {}
@@ -316,6 +320,20 @@ namespace zypp
       return str << *obj._pimpl;
     }
 
+    bool operator==( const AttrMatcher & lhs, const AttrMatcher & rhs )
+    {
+      return ( lhs.flags() == rhs.flags()
+               && lhs.searchstring() == rhs.searchstring() );
+    }
+
+    bool operator<( const AttrMatcher & lhs, const AttrMatcher & rhs )
+    {
+      if ( lhs.flags().get() != rhs.flags().get() )
+        return ( lhs.flags().get() < rhs.flags().get() );
+
+      return ( lhs.searchstring() < rhs.searchstring() );
+    }
+
     /////////////////////////////////////////////////////////////////
   } // namespace sat
   ///////////////////////////////////////////////////////////////////
index 39dbc2d..e557b07 100644 (file)
@@ -330,6 +330,12 @@ namespace zypp
         /** Ctor taking string and \ref Match flags. */
         AttrMatcher( const std::string & search_r, const Match & flags_r );
 
+        /** Ctor taking string and \ref Match::Mode.
+         * Needed because we want them to be treated as \ref Match,
+         * and not as \ref int as the compiler woud do.
+        */
+        AttrMatcher( const std::string & search_r, const Match::Mode & flags_r );
+
         /** Low level interface wraps \a flags into \ref Match. */
         AttrMatcher( const std::string & search_r, int flags_r );
 
@@ -399,6 +405,16 @@ namespace zypp
     /** \relates AttrMatcher Stream output */
     std::ostream & operator<<( std::ostream & str, const AttrMatcher & obj );
 
+    /** \relates AttrMatcher */
+    bool operator==( const AttrMatcher & lhs, const AttrMatcher & rhs );
+
+    /** \relates AttrMatcher */
+    inline bool operator!=( const AttrMatcher & lhs, const AttrMatcher & rhs )
+    { return !( lhs == rhs ); }
+
+    /** \relates AttrMatcher Arbitrary order for std::container. */
+    bool operator<( const AttrMatcher & lhs, const AttrMatcher & rhs );
+
     /////////////////////////////////////////////////////////////////
   } // namespace sat
   ///////////////////////////////////////////////////////////////////