1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/Queue.h
11 #ifndef ZYPP_SAT_QUEUE_H
12 #define ZYPP_SAT_QUEUE_H
20 #include "zypp/base/PtrTypes.h"
21 #include "zypp/sat/detail/PoolMember.h"
23 ///////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
30 typedef Queue SolvableQueue; ///< Queue with Solvable ids
31 typedef Queue StringQueue; ///< Queue with String ids
33 ///////////////////////////////////////////////////////////////////
35 /// \brief Libsolv Id queue wrapper.
36 /// \todo template value_type to work with IString and other Id based types
37 ///////////////////////////////////////////////////////////////////
41 typedef unsigned size_type;
42 typedef detail::IdType value_type;
43 typedef const value_type* const_iterator;
46 /** Default ctor: empty Queue. */
53 size_type size() const;
54 const_iterator begin() const;
55 const_iterator end() const;
57 /** Return iterator to the 1st occurance of \a val_r or \ref end. */
58 const_iterator find( value_type val_r ) const;
60 /** Return whether the Queue contais at lest one element with value \a val_r. */
61 bool contains( value_type val_r ) const
62 { return( find( val_r ) != end() ); }
64 /** Return the 1st Id in the queue or \c 0 if empty. */
65 value_type first() const;
67 /** Return the last Id in the queue or \c 0 if empty. */
68 value_type last() const;
70 /** Return the Id at \a idx_r in the queue
71 * \throws std::out_of_range if \a idx_r is out of range
73 const value_type & at( size_type idx_r ) const;
75 /** Return the Id at \a idx_r in the queue
76 * \throws std::out_of_range if \a idx_r is out of range
78 value_type & at( size_type idx_r );
80 /** Return the Id at \a idx_r in the queue (no range check) */
81 const value_type & operator[]( size_type idx_r ) const;
83 /** Return the Id at \a idx_r in the queue (no range check) */
84 value_type & operator[]( size_type idx_r );
86 /** Clear the queue. */
89 /** Remove all occurances of \a val_r from the queue. */
90 void remove( value_type val_r );
92 /** Push a value to the end off the Queue. */
93 void push( value_type val_r );
95 void push_back( value_type val_r )
98 /** Push a value if it's not yet in the Queue. */
99 void pushUnique( value_type val_r );
101 /** Pop and return the last Id from the queue or \c 0 if empty. */
104 value_type pop_back()
107 /** Push a value to the beginning off the Queue. */
108 void push_front( value_type val_r );
110 /** Pop and return the 1st Id from the queue or \c 0 if empty. */
111 value_type pop_front();
114 operator struct ::_Queue *(); ///< libsolv backdoor
115 operator const struct ::_Queue *() const ///< libsolv backdoor
116 { return _pimpl.get(); }
118 RWCOW_pointer<struct ::_Queue> _pimpl; ///< Pointer to implementation
121 /** \relates Queue Stream output */
122 std::ostream & operator<<( std::ostream & str, const Queue & obj );
124 /** \relates Queue Stream output assuming a Solvable queue. */
125 std::ostream & dumpOn( std::ostream & str, const Queue & obj );
127 /** \relates Queue */
128 bool operator==( const Queue & lhs, const Queue & rhs );
130 /** \relates Queue */
131 inline bool operator!=( const Queue & lhs, const Queue & rhs )
132 { return !( lhs == rhs ); }
135 ///////////////////////////////////////////////////////////////////
137 /** \relates Queue Clone function for RWCOW_pointer */
138 template<> struct ::_Queue * rwcowClone<struct ::_Queue>( const struct ::_Queue * rhs );
141 ///////////////////////////////////////////////////////////////////
142 #endif // ZYPP_SAT_QUEUE_H