Add class sat::Queue
authorMichael Andres <ma@suse.de>
Tue, 31 May 2011 15:19:52 +0000 (17:19 +0200)
committerMichael Andres <ma@suse.de>
Tue, 31 May 2011 15:23:47 +0000 (17:23 +0200)
zypp/CMakeLists.txt
zypp/sat/Queue.cc [new file with mode: 0644]
zypp/sat/Queue.h [new file with mode: 0644]

index 9a98046..61383b7 100644 (file)
@@ -530,6 +530,7 @@ SET( zypp_sat_SRCS
   sat/Solvable.cc
   sat/SolvableSet.cc
   sat/SolvIterMixin.cc
+  sat/Queue.cc
   sat/Transaction.cc
   sat/WhatProvides.cc
   sat/WhatObsoletes.cc
@@ -544,6 +545,7 @@ SET( zypp_sat_HEADERS
   sat/Solvable.h
   sat/SolvableSet.h
   sat/SolvIterMixin.h
+  sat/Queue.cc
   sat/Transaction.h
   sat/WhatProvides.h
   sat/WhatObsoletes.h
diff --git a/zypp/sat/Queue.cc b/zypp/sat/Queue.cc
new file mode 100644 (file)
index 0000000..af5ddfb
--- /dev/null
@@ -0,0 +1,90 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/sat/Queue.cc
+ */
+extern "C"
+{
+#include "satsolver/queue.h"
+}
+#include <iostream>
+#include "zypp/base/LogTools.h"
+
+#include "zypp/sat/Queue.h"
+#include "zypp/sat/Solvable.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace sat
+  { /////////////////////////////////////////////////////////////////
+
+    Queue::Queue()
+      : _pimpl( new struct ::_Queue )
+    {
+      ::queue_init( _pimpl );
+    }
+
+    Queue::~Queue()
+    {
+      ::queue_free( _pimpl );
+      delete( _pimpl );
+    }
+
+    bool Queue::empty() const
+    { return( _pimpl->count == 0 ); }
+
+    Queue::size_type Queue::size() const
+    { return _pimpl->count; }
+
+    Queue::const_iterator Queue::begin() const
+    { return _pimpl->elements; }
+
+    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()
+    { ::queue_pop( _pimpl ); }
+
+    Queue::value_type Queue::first() const
+    {
+      if ( empty() )
+       return 0;
+      return *_pimpl->elements;
+    }
+
+    void Queue::clear()
+    { ::queue_empty( *this ); }
+
+    std::ostream & operator<<( std::ostream & str, const Queue & obj )
+    { return dumpRangeLine( str << "Queue ", obj.begin(), obj.end() );  }
+
+    std::ostream & dumpOn( std::ostream & str, const Queue & obj )
+    {
+      str << "Queue {";
+      if ( ! obj.empty() )
+      {
+       str << endl;
+       for_( it, obj.begin(), obj.end() )
+         str << "  " << Solvable(*it) << endl;
+      }
+      return str << "}";
+    }
+
+    /////////////////////////////////////////////////////////////////
+  } // namespace sat
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
diff --git a/zypp/sat/Queue.h b/zypp/sat/Queue.h
new file mode 100644 (file)
index 0000000..152a93c
--- /dev/null
@@ -0,0 +1,88 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/sat/Queue.h
+ */
+#ifndef ZYPP_SAT_QUEUE_H
+#define ZYPP_SAT_QUEUE_H
+
+extern "C"
+{
+  struct _Queue;
+}
+#include <iosfwd>
+
+#include "zypp/base/NonCopyable.h"
+#include "zypp/sat/detail/PoolMember.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace sat
+  { /////////////////////////////////////////////////////////////////
+
+    /** Satsolver Id queue wrapper.
+     */
+    class Queue : private base::NonCopyable
+    {
+      public:
+       typedef unsigned size_type;
+       typedef detail::IdType value_type;
+       typedef const value_type* const_iterator;
+
+      public:
+        /** Default ctor: empty Queue. */
+        Queue();
+
+        /** Dtor */
+        ~Queue();
+
+       bool empty() const;
+       size_type size() const;
+       const_iterator begin() const;
+       const_iterator end() const;
+
+       /** Clear the queue. */
+       void clear();
+
+       /** Push a value to the end off the Queue. */
+       void push( value_type val_r );
+
+       /** Return the 1st Id in the queue or \c 0 if empty. */
+       value_type pop();
+
+       /** Remove and return the 1st Id from the queue or \c 0 if empty. */
+       value_type first() const;
+
+      public:
+       /** Backdoor */
+       operator struct ::_Queue *()
+       { return _pimpl; }
+       /** Backdoor */
+       operator const struct ::_Queue *() const
+       { return _pimpl; }
+
+      private:
+        /** Pointer to implementation */
+       struct ::_Queue * _pimpl;
+    };
+
+    /** \relates Queue Stream output */
+    std::ostream & operator<<( std::ostream & str, const Queue & obj );
+
+    /** \relates Queue Verbose stream output */
+    std::ostream & dumpOn( std::ostream & str, const Queue & obj );
+
+    /////////////////////////////////////////////////////////////////
+  } // namespace sat
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SAT_QUEUE_H