libzypp: zypp/ng/sat/queue.cc Source File

libzypp 17.38.14

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>
19#include <zypp-core/base/LogTools.h>
20#include <zypp-core/ng/base/ranges.h>
21#include <zypp/ng/sat/solvable.h>
22
23using std::endl;
24
25
26// defined in zypp::sat::Queue , CQueue type is the same for zypp and zyppng
27#ifdef ZYPPNG
28namespace zypp {
29 template<>
30 sat::detail::CQueue * rwcowClone<sat::detail::CQueue>( const sat::detail::CQueue * rhs )
31 {
32 sat::detail::CQueue * ret = new sat::detail::CQueue;
33 ::queue_init_clone( ret, const_cast<sat::detail::CQueue *>(rhs) );
34 return ret;
35 }
36}
37#endif
38
40namespace zyppng
41{
43 namespace sat
44 {
45
46 Queue::Queue()
47 : _pimpl( new detail::CQueue )
48 { ::queue_init( _pimpl.get() ); }
49
50 Queue::~Queue()
51 { ::queue_free( _pimpl.get() ); }
52
53 bool Queue::empty() const
54 { return( _pimpl->count == 0 ); }
55
56 Queue::size_type Queue::size() const
57 { return _pimpl->count; }
58
59 Queue::const_iterator Queue::begin() const
60 { return _pimpl->elements; }
61
62 Queue::const_iterator Queue::end() const
63 { return _pimpl->elements + _pimpl->count;}
64
65 Queue::const_iterator Queue::find( value_type val_r ) const
66 {
67 auto it = ranges::find( *this, val_r );
68 return it != end() ? it : end();
69 }
70
71 Queue::value_type Queue::first() const
72 {
73 if ( _pimpl->count )
74 return *_pimpl->elements;
75 return 0;
76 }
77
78 Queue::value_type Queue::last() const
79 {
80 if ( _pimpl->count )
81 return _pimpl->elements[_pimpl->count-1];
82 return 0;
83 }
84
85#define M_RANGE_CKECK(IDX,LOC) if ( IDX >= size_type(_pimpl->count) ) throw std::out_of_range( "zypp::sat::Queue::" LOC )
86
87 const Queue::value_type & Queue::at( size_type idx_r ) const
88 { M_RANGE_CKECK( idx_r, "at" ); return _pimpl->elements[idx_r]; }
89
90 Queue::value_type & Queue::at( size_type idx_r )
91 { M_RANGE_CKECK( idx_r, "at" ); return _pimpl->elements[idx_r]; }
92
93 const Queue::value_type & Queue::operator[]( size_type idx_r ) const
94 { return _pimpl->elements[idx_r]; }
95
96 Queue::value_type & Queue::operator[]( size_type idx_r )
97 { return _pimpl->elements[idx_r]; }
98
99 void Queue::clear()
100 { ::queue_empty( *this ); }
101
102 void Queue::remove( value_type val_r )
103 {
104 for ( const_iterator it( find( val_r ) ); it != end(); it = find( val_r ) )
105 ::queue_delete( _pimpl.get(), it - begin() );
106 }
107
108 void Queue::push( value_type val_r )
109 { ::queue_push( _pimpl.get(), val_r ); }
110
111 void Queue::pushUnique( value_type val_r )
112 { ::queue_pushunique( _pimpl.get(), val_r ); }
113
114 Queue::value_type Queue::pop()
115 { return ::queue_pop( _pimpl.get() ); }
116
117 void Queue::push_front( value_type val_r )
118 { ::queue_unshift( _pimpl.get(), val_r ); }
119
120 Queue::value_type Queue::pop_front()
121 { return ::queue_shift( _pimpl.get() ); }
122
123 Queue::operator detail::CQueue *() // COW: nonconst version can't be inlined
124 { return _pimpl.get(); } // without exposing detail::CQueue
125
126 bool operator==( const Queue & lhs, const Queue & rhs )
127 {
128 const detail::CQueue * l = lhs;
129 const detail::CQueue * r = rhs;
130 return( l == r || ( l->count == r->count && ::memcmp( l->elements, r->elements, l->count * sizeof( *l->elements ) ) == 0 ) );
131 }
132
133 } // namespace sat
135} // namespace zyppng
LogTools.h
M_RANGE_CKECK
#define M_RANGE_CKECK(IDX, LOC)
Definition Map.cc:79
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::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::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::~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
zyppng::sat::Queue
Libsolv Id queue wrapper.
Definition queue.h:37
zyppng::sat::Queue::const_iterator
const value_type * const_iterator
Definition queue.h:41
zyppng::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:65
zyppng::sat::Queue::size_type
unsigned int size_type
Definition queue.h:39
zyppng::sat::Queue::value_type
detail::IdType value_type
Definition queue.h:40
zyppng::sat::Queue::end
const_iterator end() const
Definition queue.cc:62
zyppng::sat::Queue::begin
const_iterator begin() const
Definition queue.cc:59
zyppng::sat::Queue::_pimpl
zypp::RWCOW_pointer< zypp::sat::detail::CQueue > _pimpl
Pointer to implementation.
Definition queue.h:116
zypp::sat::detail::CQueue
::s_Queue CQueue
Wrapped libsolv C data type exposed as backdoor.
Definition PoolDefines.h:35
zypp::sat::operator==
bool operator==(const FileConflicts &lhs, const FileConflicts &rhs)
relates: FileConflicts
Definition FileConflicts.h:85
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::rwcowClone< sat::detail::CQueue >
sat::detail::CQueue * rwcowClone< sat::detail::CQueue >(const sat::detail::CQueue *rhs)
relates: Queue Clone function for RWCOW_pointer
Definition Queue.cc:28
zyppng::sat::detail
CLASS NAME : detail::DIWrap.
Definition cap2str.cc:14
zyppng::sat::detail::CQueue
zypp::sat::detail::CQueue CQueue
Definition poolconstants.h:37
zyppng::sat
This file contains private API, this might break at any time between releases.
Definition capabilities.h:22
zyppng
Definition MediaNetworkRequestExecutor.h:16
ranges.h
Namespace routing for C++20 ranges and C++23 ranges::to<T>() backport.
queue.h
solvable.h