Enhance sat::Queue api
authorMichael Andres <ma@suse.de>
Tue, 7 Jun 2011 10:38:34 +0000 (12:38 +0200)
committerMichael Andres <ma@suse.de>
Tue, 7 Jun 2011 10:45:35 +0000 (12:45 +0200)
zypp/sat/Queue.cc
zypp/sat/Queue.h

index e4563bf..d029129 100644 (file)
@@ -51,11 +51,13 @@ namespace zypp
     Queue::const_iterator Queue::end() const
     { return _pimpl->elements + _pimpl->count;}
 
-    void Queue::push( value_type val_r )
-    { ::queue_push( _pimpl, val_r ); }
-
-    Queue::value_type Queue::pop()
-    { return ::queue_pop( _pimpl ); }
+    Queue::const_iterator Queue::find( value_type val_r ) const
+    {
+      for_( it, begin(), end() )
+       if ( *it != val_r )
+         return it;
+      return end();
+    }
 
     Queue::value_type Queue::first() const
     {
@@ -64,9 +66,37 @@ namespace zypp
       return *_pimpl->elements;
     }
 
+    Queue::value_type Queue::last() const
+    {
+      if ( empty() )
+       return 0;
+      return _pimpl->elements[_pimpl->count-1];
+    }
+
     void Queue::clear()
     { ::queue_empty( *this ); }
 
+    void Queue::remove( value_type val_r )
+    {
+      const_iterator it( find( val_r ) );
+      if ( it != end() )
+      {
+       ::queue_delete( _pimpl, it - begin() );
+      }
+    }
+
+    void Queue::push( value_type val_r )
+    { ::queue_push( _pimpl, val_r ); }
+
+    Queue::value_type Queue::pop()
+    { return ::queue_pop( _pimpl ); }
+
+    void Queue::push_front( value_type val_r )
+    { ::queue_unshift( _pimpl, val_r ); }
+
+    Queue::value_type Queue::pop_front()
+    { return ::queue_shift( _pimpl ); }
+
     std::ostream & operator<<( std::ostream & str, const Queue & obj )
     { return dumpRangeLine( str << "Queue ", obj.begin(), obj.end() );  }
 
index 152a93c..a28b337 100644 (file)
@@ -48,19 +48,44 @@ namespace zypp
        const_iterator begin() const;
        const_iterator end() const;
 
+       /** Return iterator to the 1st occurance of \a val_r or \ref end. */
+       const_iterator find( value_type val_r ) const;
+
+       /** Return whether the Queue contais at lest one element with value \a val_r. */
+       bool contains( value_type val_r ) const
+       { return( find( val_r ) != end() ); }
+
+       /** Return the 1st Id in the queue or \c 0 if empty. */
+       value_type first() const;
+
+       /** Return the last Id in the queue or \c 0 if empty. */
+       value_type last() const;
+
        /** Clear the queue. */
        void clear();
 
+       /** Remove all occurances of \a val_r from the queue. */
+       void remove( value_type val_r );
+
        /** Push a value to the end off the Queue. */
        void push( value_type val_r );
+       /** \overload */
+       void push_back( value_type val_r )
+       { push( val_r ); }
 
-       /** Return the 1st Id in the queue or \c 0 if empty. */
+       /** Pop and return the last Id from the queue or \c 0 if empty. */
        value_type pop();
+       /** \overload */
+       value_type pop_back()
+       { return pop(); }
 
-       /** Remove and return the 1st Id from the queue or \c 0 if empty. */
-       value_type first() const;
+       /** Push a value to the beginning off the Queue. */
+       void push_front( value_type val_r );
 
-      public:
+       /** Pop and return the 1st Id from the queue or \c 0 if empty. */
+       value_type pop_front();
+
+     public:
        /** Backdoor */
        operator struct ::_Queue *()
        { return _pimpl; }