libzypp 17.38.6
queue.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
11
12#include "queue.h"
13
14extern "C"
15{
16#include <solv/queue.h>
17}
18#include <iostream>
21
22using std::endl;
23
24
25// defined in zypp::sat::Queue , CQueue type is the same for zypp and zyppng
26#ifdef ZYPPNG
27namespace zypp {
28 template<>
30 {
32 ::queue_init_clone( ret, const_cast<sat::detail::CQueue *>(rhs) );
33 return ret;
34 }
35}
36#endif
37
39namespace zyppng
40{
42 namespace sat
43 {
44
46 : _pimpl( new detail::CQueue )
47 { ::queue_init( _pimpl.get() ); }
48
50 { ::queue_free( _pimpl.get() ); }
51
52 bool Queue::empty() const
53 { return( _pimpl->count == 0 ); }
54
56 { return _pimpl->count; }
57
59 { return _pimpl->elements; }
60
62 { return _pimpl->elements + _pimpl->count;}
63
65 {
66 for_( it, begin(), end() )
67 if ( *it == val_r )
68 return it;
69 return end();
70 }
71
73 {
74 if ( _pimpl->count )
75 return *_pimpl->elements;
76 return 0;
77 }
78
80 {
81 if ( _pimpl->count )
82 return _pimpl->elements[_pimpl->count-1];
83 return 0;
84 }
85
86#define M_RANGE_CKECK(IDX,LOC) if ( IDX >= size_type(_pimpl->count) ) throw std::out_of_range( "zypp::sat::Queue::" LOC )
87
88 const Queue::value_type & Queue::at( size_type idx_r ) const
89 { M_RANGE_CKECK( idx_r, "at" ); return _pimpl->elements[idx_r]; }
90
92 { M_RANGE_CKECK( idx_r, "at" ); return _pimpl->elements[idx_r]; }
93
95 { return _pimpl->elements[idx_r]; }
96
98 { return _pimpl->elements[idx_r]; }
99
101 { ::queue_empty( *this ); }
102
104 {
105 for ( const_iterator it( find( val_r ) ); it != end(); it = find( val_r ) )
106 ::queue_delete( _pimpl.get(), it - begin() );
107 }
108
110 { ::queue_push( _pimpl.get(), val_r ); }
111
113 { ::queue_pushunique( _pimpl.get(), val_r ); }
114
116 { return ::queue_pop( _pimpl.get() ); }
117
119 { ::queue_unshift( _pimpl.get(), val_r ); }
120
122 { return ::queue_shift( _pimpl.get() ); }
123
124 Queue::operator detail::CQueue *() // COW: nonconst version can't be inlined
125 { return _pimpl.get(); } // without exposing detail::CQueue
126
127 bool operator==( const Queue & lhs, const Queue & rhs )
128 {
129 const detail::CQueue * l = lhs;
130 const detail::CQueue * r = rhs;
131 return( l == r || ( l->count == r->count && ::memcmp( l->elements, r->elements, l->count * sizeof( *l->elements ) ) == 0 ) );
132 }
133
134 } // namespace sat
136} // namespace zyppng
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
#define M_RANGE_CKECK(IDX, LOC)
Definition Map.cc:79
const_iterator find(value_type val_r) const
Return iterator to the 1st occurance of val_r or end.
Definition Queue.cc:58
value_type pop_front()
Pop and return the 1st Id from the queue or 0 if empty.
Definition Queue.cc:115
void remove(value_type val_r)
Remove all occurances of val_r from the queue.
Definition Queue.cc:97
value_type first() const
Return the 1st Id in the queue or 0 if empty.
Definition Queue.cc:66
void push_front(value_type val_r)
Push a value to the beginning off the Queue.
Definition Queue.cc:112
~Queue()
Dtor.
Definition Queue.cc:43
size_type size() const
Definition Queue.cc:49
value_type last() const
Return the last Id in the queue or 0 if empty.
Definition Queue.cc:73
const_iterator end() const
Definition Queue.cc:55
Queue()
Default ctor: empty Queue.
Definition Queue.cc:39
const_iterator begin() const
Definition Queue.cc:52
value_type pop()
Pop and return the last Id from the queue or 0 if empty.
Definition Queue.cc:109
void clear()
Clear the queue.
Definition Queue.cc:94
const value_type & operator[](size_type idx_r) const
Return the Id at idx_r in the queue (no range check).
Definition Queue.cc:88
const value_type & at(size_type idx_r) const
Return the Id at idx_r in the queue.
Definition Queue.cc:82
bool empty() const
Definition Queue.cc:46
void push(value_type val_r)
Push a value to the end off the Queue.
Definition Queue.cc:103
void pushUnique(value_type val_r)
Push a value if it's not yet in the Queue.
Definition Queue.cc:106
Libsolv Id queue wrapper.
Definition queue.h:37
const value_type * const_iterator
Definition queue.h:41
const_iterator find(value_type val_r) const
Return iterator to the 1st occurance of val_r or end.
Definition queue.cc:64
unsigned int size_type
Definition queue.h:39
detail::IdType value_type
Definition queue.h:40
const_iterator end() const
Definition queue.cc:61
const_iterator begin() const
Definition queue.cc:58
zypp::RWCOW_pointer< zypp::sat::detail::CQueue > _pimpl
Pointer to implementation.
Definition queue.h:116
::s_Queue CQueue
Wrapped libsolv C data type exposed as backdoor.
Definition PoolDefines.h:35
bool operator==(const FileConflicts &lhs, const FileConflicts &rhs)
relates: FileConflicts
Easy-to use interface to the ZYPP dependency resolver.
sat::detail::CQueue * rwcowClone< sat::detail::CQueue >(const sat::detail::CQueue *rhs)
relates: Queue Clone function for RWCOW_pointer
Definition Queue.cc:28
CLASS NAME : detail::DIWrap.
Definition cap2str.cc:14
zypp::sat::detail::CQueue CQueue
This file contains private API, this might break at any time between releases.