Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
rw_lists.h
Go to the documentation of this file.
1
27#ifndef RW_23_LIST_H_INCLUDED
28#define RW_23_LIST_H_INCLUDED
29
30#include <rw_containers.h>
31#include <rw_driver.h> // for rw_assert()
32#include <rw_sigdefs.h> // for helper macros
33
34
36// defines enumerations identifying list template arguments,
37// sets of overloaded functions, member types used in the declarations
38// of their signatures, and specific overloads of such member functions
40{
41 // unique identifiers for all overloads of each member function
42 // 6 bits for FuncId
43 // 6 * 4 bits for ArgId (at most 6 arguments including this)
44 // 1 bit for membership
47 // list ()
48 MEMBER_0 (ctor, cont),
49 // list (const allocator_type&)
50 MEMBER_1 (ctor, cont, alloc),
51 // list (const list&)
52 MEMBER_1 (ctor, cont, ccont),
53 // list (size_type)
54 MEMBER_1 (ctor, cont, size),
55 // list (size_type, const value_type&)
56 MEMBER_2 (ctor, cont, size, cref),
57 // list (size_type, const value_type&, const allocator_type&)
58 MEMBER_3 (ctor, cont, size, cref, alloc),
59 // list (InputIterator, InputIterator)
60 MEMBER_1 (ctor, cont, range),
61 // list (InputIterator, InputIterator, const allocator&)
62 MEMBER_2 (ctor, cont, range, alloc),
63
65 // operator= (const list&)
66 MEMBER_1 (op_set, cont, ccont),
67
69 // assign (size_type, const value_type&)
70 MEMBER_2 (assign, cont, size, cref),
71 // assign (InputIterator, InputIterator)
72 MEMBER_1 (assign, cont, range),
73
75 // get_allocator () const
76 MEMBER_0 (get_allocator, ccont),
77
79 // begin ()
80 MEMBER_0 (begin, cont),
81 // begin () const
82 MEMBER_0 (begin_const, ccont),
83 // end ()
84 MEMBER_0 (end, cont),
85 // end () const
86 MEMBER_0 (end_const, ccont),
87
89 // rbegin ()
90 MEMBER_0 (rbegin, cont),
91 // rbegin () const
92 MEMBER_0 (rbegin_const, ccont),
93 // rend ()
94 MEMBER_0 (rend, cont),
95 // rend () const
96 MEMBER_0 (rend_const, ccont),
97
99 // empty ()
100 MEMBER_0 (empty, ccont),
101
103 // size ()
104 MEMBER_0 (size, ccont),
105
107 // max_size ()
108 MEMBER_0 (max_size, ccont),
109
111 // resize (size_type)
112 MEMBER_1 (resize, cont, size),
113 // resize (size_type, value_type)
114 MEMBER_2 (resize, cont, size, val),
115
117 // front ()
118 MEMBER_0 (front, cont),
119 // front () const
120 MEMBER_0 (front_const, ccont),
121 // back ()
122 MEMBER_0 (back, cont),
123 // back () const
124 MEMBER_0 (back_const, ccont),
125
127 // push_front (const value_type&)
128 MEMBER_1 (push_front, cont, cref),
129 // pop_front ()
130 MEMBER_0 (pop_front, cont),
131 // push_back (const value_type&)
132 MEMBER_1 (push_back, cont, cref),
133 // pop_back ()
134 MEMBER_0 (pop_back, cont),
135
137 // insert (iterator, const value_type&)
138 MEMBER_2 (insert, cont, iter, cref),
139 // insert (iterator, size_type, const value_type&)
140 MEMBER_3 (insert, cont, iter, size, cref),
141 // insert (iterator, InputIterator, InputIterator)
142 MEMBER_2 (insert, cont, iter, range),
143
145 // erase (iterator)
146 MEMBER_1 (erase, cont, iter),
147 // erase (iterator, iterator)
148 MEMBER_2 (erase, cont, iter, iter),
149
151 // swap (list&)
152 MEMBER_1 (swap, cont, cont),
153 // swap (list&, list&)
154 NON_MEMBER_2 (swap, cont, cont),
155
157 // clear ()
158 MEMBER_0 (clear, cont),
159
161 // splice (iterator, list&)
162 MEMBER_2 (splice, cont, iter, cont),
163 // splice (iterator, list&, iterator)
164 MEMBER_3 (splice, cont, iter, cont, iter),
165 // splice (iterator, list&, iterator, iterator)
166 MEMBER_4 (splice, cont, iter, cont, iter, iter),
167
169 // remove (const value_type&)
170 MEMBER_1 (remove, cont, cref),
171 // remove_if (Predicate)
172 MEMBER_1 (remove_if, cont, pred),
173
175 // unique (BinaryPredicate)
176 MEMBER_1 (unique, cont, bpred),
177
179 // merge (list&)
180 MEMBER_1 (merge, cont, cont),
181 // merge (list&, Compare)
182 MEMBER_2 (merge, cont, cont, comp),
183
185 // sort ()
186 MEMBER_0 (sort, cont),
187 // sort (Compare)
188 MEMBER_1 (sort, cont, comp),
189
191 // reverse ()
192 MEMBER_0 (reverse, cont),
193
195 // operator== (const list&, const list&)
196 NON_MEMBER_2 (op_equal, ccont, ccont),
197
199 // operator< (const list&, const list&)
200 NON_MEMBER_2 (op_less, ccont, ccont),
201
203 // operator!= (const list&, const list&)
204 NON_MEMBER_2 (op_not_equal, ccont, ccont),
205
207 // operator> (const list&, const list&)
208 NON_MEMBER_2 (op_greater, ccont, ccont),
209
211 // operator>= (const list&, const list&)
212 NON_MEMBER_2 (op_greater_equal, ccont, ccont),
213
215 // operator<= (const list&, const list&)
216 NON_MEMBER_2 (op_less_equal, ccont, ccont)
217 };
218
219// clean up helper macros used above
220#include <rw_sigdefs.h>
221
222};
223
224
226template <class InputIter1, class InputIter2>
227inline bool
228_rw_equal (InputIter1 first1, InputIter1 last1, InputIter2 first2)
229{
230 for (; first1 != last1 && *first1 == *first2; ++first1, ++first2) ;
231
232 return first1 == last1;
233}
234
235// encapsulates the state of a list object
236// used in exception safety tests to determine changes to the state
237// after a modifying operation throws an exception
238template <class List>
240{
241 typedef typename List::const_iterator ListCIter;
242 typedef typename List::const_pointer ListCPtr;
243
244 _RWSTD_SIZE_T size_;
247
248 ListState (List const & lst) : size_ (lst.size ()), iters_ (0), ptrs_ (0) {
249 iters_ = new ListCIter [size_];
250 ptrs_ = new ListCPtr [size_];
251
252 _RWSTD_SIZE_T index = 0;
253 for (ListCIter it = lst.begin (), end = lst.end ();
254 it != end; ++it, ++index) {
255
256 iters_ [index] = it;
257 ptrs_ [index] = &*it;
258 }
259 }
260
262 delete [] iters_;
263 delete [] ptrs_;
264 }
265
266 // invokes rw_assert() to verify that two states are the same
267 void assert_equal (const ListState& state, int line,
268 int case_line, const char* when) const {
269
270 const bool equal = size_ == state.size_
271 && _rw_equal (iters_, iters_ + size_, state.iters_)
272 && _rw_equal (ptrs_, ptrs_ + size_, state.ptrs_);
273
274 rw_assert (equal, 0, case_line,
275 "line %d: %{$FUNCALL}: object state unexpectedly changed "
276 "after %s", line, when);
277 }
278};
279
280
282#endif // RW_23_LIST_H_INCLUDED
#define alloc
Definition 17.names.cpp:441
#define line
Definition 17.names.cpp:490
#define comp
Definition 17.names.cpp:461
#define index
Definition 17.names.cpp:482
#define val
Definition 17.names.cpp:570
bool equal(const T &x, const U &y)
const int end
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630
bool _rw_equal(InputIter1 first1, InputIter1 last1, InputIter2 first2)
Definition rw_lists.h:228
@ MEMBER_1
Definition rw_lists.h:50
@ MEMBER_2
Definition rw_lists.h:56
@ MEMBER_4
Definition rw_lists.h:166
@ NON_MEMBER_2
Definition rw_lists.h:154
@ MEMBER_0
Definition rw_lists.h:48
@ MEMBER_3
Definition rw_lists.h:58
List::const_pointer ListCPtr
Definition rw_lists.h:242
_RWSTD_SIZE_T size_
Definition rw_lists.h:244
ListCIter * iters_
Definition rw_lists.h:245
ListState(List const &lst)
Definition rw_lists.h:248
ListCPtr * ptrs_
Definition rw_lists.h:246
void assert_equal(const ListState &state, int line, int case_line, const char *when) const
Definition rw_lists.h:267
List::const_iterator ListCIter
Definition rw_lists.h:241