Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / sat / Queue.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/Queue.h
10  */
11 #ifndef ZYPP_SAT_QUEUE_H
12 #define ZYPP_SAT_QUEUE_H
13
14 extern "C"
15 {
16   struct _Queue;
17 }
18 #include <iosfwd>
19
20 #include "zypp/base/PtrTypes.h"
21 #include "zypp/sat/detail/PoolMember.h"
22
23 ///////////////////////////////////////////////////////////////////
24 namespace zypp
25 {
26   ///////////////////////////////////////////////////////////////////
27   namespace sat
28   {
29     class Queue;
30     typedef Queue SolvableQueue;        ///< Queue with Solvable ids
31     typedef Queue StringQueue;          ///< Queue with String ids
32
33     ///////////////////////////////////////////////////////////////////
34     /// \class Queue
35     /// \brief Libsolv Id queue wrapper.
36     /// \todo template value_type to work with IString and other Id based types
37     ///////////////////////////////////////////////////////////////////
38     class Queue
39     {
40       public:
41         typedef unsigned size_type;
42         typedef detail::IdType value_type;
43         typedef const value_type* const_iterator;
44
45       public:
46         /** Default ctor: empty Queue. */
47         Queue();
48
49         /** Dtor */
50         ~Queue();
51
52         bool empty() const;
53         size_type size() const;
54         const_iterator begin() const;
55         const_iterator end() const;
56
57         /** Return iterator to the 1st occurance of \a val_r or \ref end. */
58         const_iterator find( value_type val_r ) const;
59
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() ); }
63
64         /** Return the 1st Id in the queue or \c 0 if empty. */
65         value_type first() const;
66
67         /** Return the last Id in the queue or \c 0 if empty. */
68         value_type last() const;
69
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
72          */
73         const value_type & at( size_type idx_r ) const;
74
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
77          */
78         value_type & at( size_type idx_r );
79
80         /** Return the Id at \a idx_r in the queue (no range check) */
81         const value_type & operator[]( size_type idx_r ) const;
82
83         /** Return the Id at \a idx_r in the queue (no range check) */
84         value_type & operator[]( size_type idx_r );
85
86         /** Clear the queue. */
87         void clear();
88
89         /** Remove all occurances of \a val_r from the queue. */
90         void remove( value_type val_r );
91
92         /** Push a value to the end off the Queue. */
93         void push( value_type val_r );
94         /** \overload */
95         void push_back( value_type val_r )
96         { push( val_r ); }
97
98         /** Push a value if it's not yet in the Queue. */
99         void pushUnique( value_type val_r );
100
101         /** Pop and return the last Id from the queue or \c 0 if empty. */
102         value_type pop();
103         /** \overload */
104         value_type pop_back()
105         { return pop(); }
106
107         /** Push a value to the beginning off the Queue. */
108         void push_front( value_type val_r );
109
110         /** Pop and return the 1st Id from the queue or \c 0 if empty. */
111         value_type pop_front();
112
113      public:
114         operator struct ::_Queue *();                   ///< libsolv backdoor
115         operator const struct ::_Queue *() const        ///< libsolv backdoor
116         { return _pimpl.get(); }
117       private:
118         RWCOW_pointer<struct ::_Queue> _pimpl;          ///< Pointer to implementation
119     };
120
121     /** \relates Queue Stream output */
122     std::ostream & operator<<( std::ostream & str, const Queue & obj );
123
124     /** \relates Queue Stream output assuming a Solvable queue. */
125     std::ostream & dumpOn( std::ostream & str, const Queue & obj );
126
127     /** \relates Queue */
128     bool operator==( const Queue & lhs, const Queue & rhs );
129
130     /** \relates Queue */
131     inline bool operator!=( const Queue & lhs, const Queue & rhs )
132     { return !( lhs == rhs ); }
133
134   } // namespace sat
135   ///////////////////////////////////////////////////////////////////
136
137   /** \relates Queue Clone function for RWCOW_pointer */
138   template<> struct ::_Queue * rwcowClone<struct ::_Queue>( const struct ::_Queue * rhs );
139
140 } // namespace zypp
141 ///////////////////////////////////////////////////////////////////
142 #endif // ZYPP_SAT_QUEUE_H