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