libzypp  11.13.5
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  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