1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/Queue.h
11 #ifndef ZYPP_SAT_QUEUE_H
12 #define ZYPP_SAT_QUEUE_H
16 #include "zypp/base/PtrTypes.h"
17 #include "zypp/sat/detail/PoolMember.h"
19 ///////////////////////////////////////////////////////////////////
22 ///////////////////////////////////////////////////////////////////
26 typedef Queue SolvableQueue; ///< Queue with Solvable ids
27 typedef Queue StringQueue; ///< Queue with String ids
29 ///////////////////////////////////////////////////////////////////
31 /// \brief Libsolv Id queue wrapper.
32 /// \todo template value_type to work with IString and other Id based types
33 ///////////////////////////////////////////////////////////////////
37 typedef unsigned size_type;
38 typedef detail::IdType value_type;
39 typedef const value_type* const_iterator;
42 /** Default ctor: empty Queue. */
49 size_type size() const;
50 const_iterator begin() const;
51 const_iterator end() const;
53 /** Return iterator to the 1st occurance of \a val_r or \ref end. */
54 const_iterator find( value_type val_r ) const;
56 /** Return whether the Queue contais at lest one element with value \a val_r. */
57 bool contains( value_type val_r ) const
58 { return( find( val_r ) != end() ); }
60 /** Return the 1st Id in the queue or \c 0 if empty. */
61 value_type first() const;
63 /** Return the last Id in the queue or \c 0 if empty. */
64 value_type last() const;
66 /** Return the Id at \a idx_r in the queue
67 * \throws std::out_of_range if \a idx_r is out of range
69 const value_type & at( size_type idx_r ) const;
71 /** Return the Id at \a idx_r in the queue
72 * \throws std::out_of_range if \a idx_r is out of range
74 value_type & at( size_type idx_r );
76 /** Return the Id at \a idx_r in the queue (no range check) */
77 const value_type & operator[]( size_type idx_r ) const;
79 /** Return the Id at \a idx_r in the queue (no range check) */
80 value_type & operator[]( size_type idx_r );
82 /** Clear the queue. */
85 /** Remove all occurances of \a val_r from the queue. */
86 void remove( value_type val_r );
88 /** Push a value to the end off the Queue. */
89 void push( value_type val_r );
91 void push_back( value_type val_r )
94 /** Push a value if it's not yet in the Queue. */
95 void pushUnique( value_type val_r );
97 /** Pop and return the last Id from the queue or \c 0 if empty. */
100 value_type pop_back()
103 /** Push a value to the beginning off the Queue. */
104 void push_front( value_type val_r );
106 /** Pop and return the 1st Id from the queue or \c 0 if empty. */
107 value_type pop_front();
110 operator detail::CQueue *(); ///< libsolv backdoor
111 operator const detail::CQueue *() const ///< libsolv backdoor
112 { return _pimpl.get(); }
114 RWCOW_pointer<detail::CQueue> _pimpl; ///< Pointer to implementation
117 /** \relates Queue Stream output */
118 std::ostream & operator<<( std::ostream & str, const Queue & obj );
120 /** \relates Queue Stream output assuming a Solvable queue. */
121 std::ostream & dumpOn( std::ostream & str, const Queue & obj );
123 /** \relates Queue */
124 bool operator==( const Queue & lhs, const Queue & rhs );
126 /** \relates Queue */
127 inline bool operator!=( const Queue & lhs, const Queue & rhs )
128 { return !( lhs == rhs ); }
131 ///////////////////////////////////////////////////////////////////
133 /** \relates Queue Clone function for RWCOW_pointer */
134 template<> sat::detail::CQueue * rwcowClone<sat::detail::CQueue>( const sat::detail::CQueue * rhs );
137 ///////////////////////////////////////////////////////////////////
138 #endif // ZYPP_SAT_QUEUE_H