libzypp  13.10.6
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  namespace sat
28  {
29 
31  : _pimpl( new struct ::_Queue )
32  {
33  ::queue_init( _pimpl );
34  }
35 
37  {
38  ::queue_free( _pimpl );
39  delete( _pimpl );
40  }
41 
42  bool Queue::empty() const
43  { return( _pimpl->count == 0 ); }
44 
46  { return _pimpl->count; }
47 
49  { return _pimpl->elements; }
50 
52  { return _pimpl->elements + _pimpl->count;}
53 
55  {
56  for_( it, begin(), end() )
57  if ( *it != val_r )
58  return it;
59  return end();
60  }
61 
63  {
64  if ( empty() )
65  return 0;
66  return *_pimpl->elements;
67  }
68 
70  {
71  if ( empty() )
72  return 0;
73  return _pimpl->elements[_pimpl->count-1];
74  }
75 
76  void Queue::clear()
77  { ::queue_empty( *this ); }
78 
79  void Queue::remove( value_type val_r )
80  {
81  const_iterator it( find( val_r ) );
82  if ( it != end() )
83  {
84  ::queue_delete( _pimpl, it - begin() );
85  }
86  }
87 
88  void Queue::push( value_type val_r )
89  { ::queue_push( _pimpl, val_r ); }
90 
92  { return ::queue_pop( _pimpl ); }
93 
95  { ::queue_unshift( _pimpl, val_r ); }
96 
98  { return ::queue_shift( _pimpl ); }
99 
100  std::ostream & operator<<( std::ostream & str, const Queue & obj )
101  { return dumpRangeLine( str << "Queue ", obj.begin(), obj.end() ); }
102 
103  std::ostream & dumpOn( std::ostream & str, const Queue & obj )
104  {
105  str << "Queue {";
106  if ( ! obj.empty() )
107  {
108  str << endl;
109  for_( it, obj.begin(), obj.end() )
110  str << " " << Solvable(*it) << endl;
111  }
112  return str << "}";
113  }
114 
115  bool operator==( const Queue & lhs, const Queue & rhs )
116  {
117  const struct ::_Queue * l = lhs;
118  const struct ::_Queue * r = rhs;
119  return( l == r || ( l->count == r->count && ::memcmp( l->elements, r->elements, l->count ) == 0 ) );
120  }
121 
123  } // namespace sat
126 } // namespace zypp
void remove(value_type val_r)
Remove all occurances of val_r from the queue.
Definition: Queue.cc:79
A Solvable object within the sat Pool.
Definition: Solvable.h:55
std::ostream & operator<<(std::ostream &str, const LocaleSupport &obj)
detail::IdType value_type
Definition: Queue.h:36
bool operator==(const Map &lhs, const Map &rhs)
Definition: Map.cc:118
struct::_Queue * _pimpl
Pointer to implementation.
Definition: Queue.h:98
value_type last() const
Return the last Id in the queue or 0 if empty.
Definition: Queue.cc:69
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
const_iterator find(value_type val_r) const
Return iterator to the 1st occurance of val_r or end.
Definition: Queue.cc:54
const_iterator end() const
Definition: Queue.cc:51
void push(value_type val_r)
Push a value to the end off the Queue.
Definition: Queue.cc:88
const_iterator begin() const
Definition: Queue.cc:48
value_type pop_front()
Pop and return the 1st Id from the queue or 0 if empty.
Definition: Queue.cc:97
unsigned size_type
Definition: Queue.h:35
void push_front(value_type val_r)
Push a value to the beginning off the Queue.
Definition: Queue.cc:94
const value_type * const_iterator
Definition: Queue.h:37
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
std::ostream & dumpRangeLine(std::ostream &str, _Iterator begin, _Iterator end)
Print range defined by iterators (single line style).
Definition: LogTools.h:114
Libsolv Id queue wrapper.
Definition: Queue.h:32
void clear()
Clear the queue.
Definition: Queue.cc:76
size_type size() const
Definition: Queue.cc:45
Queue()
Default ctor: empty Queue.
Definition: Queue.cc:30
~Queue()
Dtor.
Definition: Queue.cc:36
value_type first() const
Return the 1st Id in the queue or 0 if empty.
Definition: Queue.cc:62
bool empty() const
Definition: Queue.cc:42
value_type pop()
Pop and return the last Id from the queue or 0 if empty.
Definition: Queue.cc:91