libzypp  10.5.0
Queue.cc
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00011 extern "C"
00012 {
00013 #include "solv/queue.h"
00014 }
00015 #include <iostream>
00016 #include "zypp/base/LogTools.h"
00017 
00018 #include "zypp/sat/Queue.h"
00019 #include "zypp/sat/Solvable.h"
00020 
00021 using std::endl;
00022 
00024 namespace zypp
00025 { 
00026 
00027   namespace sat
00028   { 
00029 
00030     Queue::Queue()
00031       : _pimpl( new struct ::_Queue )
00032     {
00033       ::queue_init( _pimpl );
00034     }
00035 
00036     Queue::~Queue()
00037     {
00038       ::queue_free( _pimpl );
00039       delete( _pimpl );
00040     }
00041 
00042     bool Queue::empty() const
00043     { return( _pimpl->count == 0 ); }
00044 
00045     Queue::size_type Queue::size() const
00046     { return _pimpl->count; }
00047 
00048     Queue::const_iterator Queue::begin() const
00049     { return _pimpl->elements; }
00050 
00051     Queue::const_iterator Queue::end() const
00052     { return _pimpl->elements + _pimpl->count;}
00053 
00054     Queue::const_iterator Queue::find( value_type val_r ) const
00055     {
00056       for_( it, begin(), end() )
00057         if ( *it != val_r )
00058           return it;
00059       return end();
00060     }
00061 
00062     Queue::value_type Queue::first() const
00063     {
00064       if ( empty() )
00065         return 0;
00066       return *_pimpl->elements;
00067     }
00068 
00069     Queue::value_type Queue::last() const
00070     {
00071       if ( empty() )
00072         return 0;
00073       return _pimpl->elements[_pimpl->count-1];
00074     }
00075 
00076     void Queue::clear()
00077     { ::queue_empty( *this ); }
00078 
00079     void Queue::remove( value_type val_r )
00080     {
00081       const_iterator it( find( val_r ) );
00082       if ( it != end() )
00083       {
00084         ::queue_delete( _pimpl, it - begin() );
00085       }
00086     }
00087 
00088     void Queue::push( value_type val_r )
00089     { ::queue_push( _pimpl, val_r ); }
00090 
00091     Queue::value_type Queue::pop()
00092     { return ::queue_pop( _pimpl ); }
00093 
00094     void Queue::push_front( value_type val_r )
00095     { ::queue_unshift( _pimpl, val_r ); }
00096 
00097     Queue::value_type Queue::pop_front()
00098     { return ::queue_shift( _pimpl ); }
00099 
00100     std::ostream & operator<<( std::ostream & str, const Queue & obj )
00101     { return dumpRangeLine( str << "Queue ", obj.begin(), obj.end() );  }
00102 
00103     std::ostream & dumpOn( std::ostream & str, const Queue & obj )
00104     {
00105       str << "Queue {";
00106       if ( ! obj.empty() )
00107       {
00108         str << endl;
00109         for_( it, obj.begin(), obj.end() )
00110           str << "  " << Solvable(*it) << endl;
00111       }
00112       return str << "}";
00113     }
00114 
00116   } // namespace sat
00119 } // namespace zypp