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
EList()35 EList<T>::EList()
36   : Doubly_Linked_Object(this, this) {
37 }
38 
39 template <typename T>
40 inline void
push_front(T & obj)41 EList<T>::push_front(T& obj) {
42   next->insert_before(obj);
43 }
44 
45 template <typename T>
46 inline void
push_back(T & obj)47 EList<T>::push_back(T& obj) {
48   prev->insert_after(obj);
49 }
50 
51 template <typename T>
52 inline typename EList<T>::iterator
insert(iterator position,T & obj)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
begin()60 EList<T>::begin() {
61   return iterator(next);
62 }
63 
64 template <typename T>
65 inline typename EList<T>::iterator
end()66 EList<T>::end() {
67   return iterator(this);
68 }
69 
70 template <typename T>
71 inline typename EList<T>::const_iterator
begin() const72 EList<T>::begin() const {
73   return const_iterator(next);
74 }
75 
76 template <typename T>
77 inline typename EList<T>::const_iterator
end() const78 EList<T>::end() const {
79   return const_iterator(const_cast<EList<T>*>(this));
80 }
81 
82 template <typename T>
83 inline bool
empty() const84 EList<T>::empty() const {
85   return begin() == end();
86 }
87 
88 template <typename T>
89 inline typename EList<T>::iterator
erase(iterator position)90 EList<T>::erase(iterator position) {
91   assert(!empty());
92   return iterator(position->erase());
93 }
94 
95 template <typename T>
96 inline
~EList()97 EList<T>::~EList() {
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
OK() const107 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)
122