libzypp 17.37.10

Queue.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
11 extern "C"
12{
13#include <solv/queue.h>
14}
15#include <iostream>
16#include <zypp/base/LogTools.h>
17
18#include <zypp/sat/Queue.h>
19#include <zypp/sat/Solvable.h>
20
21 using std::endl;
22
24 namespace zypp
25{
26
27 template<>
28 sat::detail::CQueue * rwcowClone<sat::detail::CQueue>( const sat::detail::CQueue * rhs )
29 {
30 sat::detail::CQueue * ret = new sat::detail::CQueue;
31 ::queue_init_clone( ret, const_cast<sat::detail::CQueue *>(rhs) );
32 return ret;
33 }
34
36 namespace sat
37 {
38
39 Queue::Queue()
40 : _pimpl( new detail::CQueue )
41 { ::queue_init( _pimpl.get() ); }
42
43 Queue::~Queue()
44 { ::queue_free( _pimpl.get() ); }
45
46 bool Queue::empty() const
47 { return( _pimpl->count == 0 ); }
48
49 Queue::size_type Queue::size() const
50 { return _pimpl->count; }
51
52 Queue::const_iterator Queue::begin() const
53 { return _pimpl->elements; }
54
55 Queue::const_iterator Queue::end() const
56 { return _pimpl->elements + _pimpl->count;}
57
58 Queue::const_iterator Queue::find( value_type val_r ) const
59 {
60 for_( it, begin(), end() )
61 if ( *it == val_r )
62 return it;
63 return end();
64 }
65
66 Queue::value_type Queue::first() const
67 {
68 if ( _pimpl->count )
69 return *_pimpl->elements;
70 return 0;
71 }
72
73 Queue::value_type Queue::last() const
74 {
75 if ( _pimpl->count )
76 return _pimpl->elements[_pimpl->count-1];
77 return 0;
78 }
79
80#define M_RANGE_CKECK(IDX,LOC) if ( IDX >= size_type(_pimpl->count) ) throw std::out_of_range( "zypp::sat::Queue::" LOC )
81
82 const Queue::value_type & Queue::at( size_type idx_r ) const
83 { M_RANGE_CKECK( idx_r, "at" ); return _pimpl->elements[idx_r]; }
84
85 Queue::value_type & Queue::at( size_type idx_r )
86 { M_RANGE_CKECK( idx_r, "at" ); return _pimpl->elements[idx_r]; }
87
88 const Queue::value_type & Queue::operator[]( size_type idx_r ) const
89 { return _pimpl->elements[idx_r]; }
90
91 Queue::value_type & Queue::operator[]( size_type idx_r )
92 { return _pimpl->elements[idx_r]; }
93
94 void Queue::clear()
95 { ::queue_empty( *this ); }
96
97 void Queue::remove( value_type val_r )
98 {
99 for ( const_iterator it( find( val_r ) ); it != end(); it = find( val_r ) )
100 ::queue_delete( _pimpl.get(), it - begin() );
101 }
102
103 void Queue::push( value_type val_r )
104 { ::queue_push( _pimpl.get(), val_r ); }
105
106 void Queue::pushUnique( value_type val_r )
107 { ::queue_pushunique( _pimpl.get(), val_r ); }
108
109 Queue::value_type Queue::pop()
110 { return ::queue_pop( _pimpl.get() ); }
111
112 void Queue::push_front( value_type val_r )
113 { ::queue_unshift( _pimpl.get(), val_r ); }
114
115 Queue::value_type Queue::pop_front()
116 { return ::queue_shift( _pimpl.get() ); }
117
118 Queue::operator detail::CQueue *() // COW: nonconst version can't be inlined
119 { return _pimpl.get(); } // without exposing detail::CQueue
120
121 std::ostream & operator<<( std::ostream & str, const Queue & obj )
122 { return dumpRangeLine( str << "Queue ", obj.begin(), obj.end() ); }
123
124 std::ostream & dumpOn( std::ostream & str, const Queue & obj )
125 {
126 str << "Queue {";
127 if ( ! obj.empty() )
128 {
129 str << endl;
130 for_( it, obj.begin(), obj.end() )
131 str << " " << Solvable(*it) << endl;
132 }
133 return str << "}";
134 }
135
136 bool operator==( const Queue & lhs, const Queue & rhs )
137 {
138 const detail::CQueue * l = lhs;
139 const detail::CQueue * r = rhs;
140 return( l == r || ( l->count == r->count && ::memcmp( l->elements, r->elements, l->count ) == 0 ) );
141 }
142
143 } // namespace sat
145} // namespace zypp
M_RANGE_CKECK
#define M_RANGE_CKECK(IDX, LOC)
Definition Map.cc:79
Queue.h
Solvable.h
zypp::sat::Queue::find
const_iterator find(value_type val_r) const
Return iterator to the 1st occurance of val_r or end.
Definition Queue.cc:58
zypp::sat::Queue::pop_front
value_type pop_front()
Pop and return the 1st Id from the queue or 0 if empty.
Definition Queue.cc:115
zypp::sat::Queue::value_type
detail::IdType value_type
Definition Queue.h:39
zypp::sat::Queue::_pimpl
RWCOW_pointer< detail::CQueue > _pimpl
Pointer to implementation.
Definition Queue.h:115
zypp::sat::Queue::remove
void remove(value_type val_r)
Remove all occurances of val_r from the queue.
Definition Queue.cc:97
zypp::sat::Queue::first
value_type first() const
Return the 1st Id in the queue or 0 if empty.
Definition Queue.cc:66
zypp::sat::Queue::size_type
unsigned int size_type
Definition Queue.h:38
zypp::sat::Queue::push_front
void push_front(value_type val_r)
Push a value to the beginning off the Queue.
Definition Queue.cc:112
zypp::sat::Queue::const_iterator
const value_type * const_iterator
Definition Queue.h:40
zypp::sat::Queue::~Queue
~Queue()
Dtor.
Definition Queue.cc:43
zypp::sat::Queue::size
size_type size() const
Definition Queue.cc:49
zypp::sat::Queue::last
value_type last() const
Return the last Id in the queue or 0 if empty.
Definition Queue.cc:73
zypp::sat::Queue::end
const_iterator end() const
Definition Queue.cc:55
zypp::sat::Queue::Queue
Queue()
Default ctor: empty Queue.
Definition Queue.cc:39
zypp::sat::Queue::begin
const_iterator begin() const
Definition Queue.cc:52
zypp::sat::Queue::pop
value_type pop()
Pop and return the last Id from the queue or 0 if empty.
Definition Queue.cc:109
zypp::sat::Queue::clear
void clear()
Clear the queue.
Definition Queue.cc:94
zypp::sat::Queue::operator[]
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
zypp::sat::Queue::at
const value_type & at(size_type idx_r) const
Return the Id at idx_r in the queue.
Definition Queue.cc:82
zypp::sat::Queue::empty
bool empty() const
Definition Queue.cc:46
zypp::sat::Queue::push
void push(value_type val_r)
Push a value to the end off the Queue.
Definition Queue.cc:103
zypp::sat::Queue::pushUnique
void pushUnique(value_type val_r)
Push a value if it's not yet in the Queue.
Definition Queue.cc:106
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition Solvable.h:54
str
String related utilities and Regular expression matching.
zypp::sat::detail
Definition PoolImpl.cc:72
zypp::sat::detail::CQueue
::s_Queue CQueue
Wrapped libsolv C data type exposed as backdoor.
Definition PoolMember.h:62
zypp::sat::operator<<
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
Definition FileConflicts.cc:109
zypp::sat::dumpOn
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
Definition LocaleSupport.cc:41
zypp::sat::operator==
bool operator==(const Map &lhs, const Map &rhs)
Definition Map.cc:125
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::dumpRangeLine
std::ostream & dumpRangeLine(std::ostream &str, TIterator begin, TIterator end)
Print range defined by iterators (single line style).
Definition LogTools.h:143
zypp::rwcowClone< sat::detail::CQueue >
sat::detail::CQueue * rwcowClone< sat::detail::CQueue >(const sat::detail::CQueue *rhs)
Definition Queue.cc:28
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
LogTools.h