PPL  1.2
EList_inlines.hh
Go to the documentation of this file.
1 /* EList class implementation: inline functions.
2  Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3  Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_EList_inlines_hh
25 #define PPL_EList_inlines_hh 1
26 
27 #include <cassert>
28 
29 namespace Parma_Polyhedra_Library {
30 
31 namespace Implementation {
32 
33 template <typename T>
34 inline
36  : Doubly_Linked_Object(this, this) {
37 }
38 
39 template <typename T>
40 inline void
42  next->insert_before(obj);
43 }
44 
45 template <typename T>
46 inline void
48  prev->insert_after(obj);
49 }
50 
51 template <typename T>
52 inline typename EList<T>::iterator
53 EList<T>::insert(iterator position, T& obj) {
54  position->insert_before(obj);
55  return iterator(&obj);
56 }
57 
58 template <typename T>
59 inline typename EList<T>::iterator
61  return iterator(next);
62 }
63 
64 template <typename T>
65 inline typename EList<T>::iterator
67  return iterator(this);
68 }
69 
70 template <typename T>
71 inline typename EList<T>::const_iterator
72 EList<T>::begin() const {
73  return const_iterator(next);
74 }
75 
76 template <typename T>
77 inline typename EList<T>::const_iterator
78 EList<T>::end() const {
79  return const_iterator(const_cast<EList<T>*>(this));
80 }
81 
82 template <typename T>
83 inline bool
84 EList<T>::empty() const {
85  return begin() == end();
86 }
87 
88 template <typename T>
89 inline typename EList<T>::iterator
91  assert(!empty());
92  return iterator(position->erase());
93 }
94 
95 template <typename T>
96 inline
98  // Erase and deallocate all the elements.
99  for (iterator i = begin(), lend = end(), next; i != lend; i = next) {
100  next = erase(i);
101  delete &*i;
102  }
103 }
104 
105 template <typename T>
106 inline bool
107 EList<T>::OK() const {
108  for (const_iterator i = begin(), lend = end(); i != lend; ++i) {
109  if (!i->OK()) {
110  return false;
111  }
112  }
113 
114  return true;
115 }
116 
117 } // namespace Implementation
118 
119 } // namespace Parma_Polyhedra_Library
120 
121 #endif // !defined(PPL_EList_inlines_hh)
iterator begin()
Returns an iterator pointing to the beginning of the list.
void push_back(T &obj)
Pushes obj to the back of the list.
Doubly_Linked_Object * erase()
Erases *this from the chain and returns a pointer to the next element.
void push_front(T &obj)
Pushes obj to the front of the list.
iterator end()
Returns an iterator pointing one past the last element in the list.
A class providing iterators for embedded lists.
bool empty() const
Returns true if and only if the list is empty.
bool OK() const
Checks if all the invariants are satisfied.
The entire library is confined to this namespace.
Definition: version.hh:61
~EList()
Destructs the list and all the elements in it.
A simple kind of embedded list (i.e., a doubly linked objects where the links are embedded in the obj...
Definition: EList_defs.hh:36
iterator insert(iterator position, T &obj)
Inserts obj just before position and returns an iterator that points to the inserted object...