BALL 1.5.0
Loading...
Searching...
No Matches
list.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 2; -*-
2// vi: set ts=2:
3//
4
5#ifndef BALL_DATATYPE_LIST_H
6#define BALL_DATATYPE_LIST_H
7
8#ifndef BALL_COMMON_H
9# include <BALL/common.h>
10#endif
11
12#ifndef BALL_CONCEPT_VISITOR_H
13# include <BALL/CONCEPT/visitor.h>
14#endif
15
16#ifndef BALL_CONCEPT_PROCESSOR_H
18#endif
19
20#include <list>
21
22#ifdef BALL_COMPILER_GXX || BALL_COMPILER_LLVM
23#warning "This header file is deprecated and should not be used in new code! As a replacement for BALL::List the use of std::list is strongly suggested."
24#endif
25
26namespace BALL
27{
33 template <typename Value>
34 class List
35 : public std::list<Value>
36 {
37 public:
38
42
45 typedef typename std::list<Value>::iterator Iterator;
46 // for STL compatibility
47 typedef typename std::list<Value>::iterator iterator;
48
51 typedef typename std::list<Value>::const_iterator ConstIterator;
52 // for STL compatibility
53 typedef typename std::list<Value>::const_iterator const_iterator;
54
56
58
60
61
65 : std::list<Value>()
66 {
67 }
68
74 List(const List& new_list, bool /* deep = true */)
75 : std::list<Value>(new_list)
76 {
77 }
78
81 void destroy()
82 {
83 std::list<Value>::clear();
84 }
85
88 virtual ~List()
89 {
90 std::list<Value>::clear();
91 }
92
94
96
101 void set(const List& list, bool /* deep */ = true)
102 {
103 std::list<Value>::clear();
104
105 ConstIterator it = list.begin();
106 for ( ; it != list.end(); ++it)
107 {
108 std::list<Value>::push_back(const_cast<Value&>(*it));
109 }
110 }
111
114 const List& operator = (const List& list)
115 {
116 set(list);
117 return *this;
118 }
119
121 void get(List& list, bool deep = true) const
122 {
123 list.set(*this, deep);
124 }
125
127 void swap(List& list)
128 {
129 List<Value> temp;
130 temp.set(*this);
131 (*this).set(list);
132 list.set(temp);
133 }
134
136
138
141 Size getSize() const
142 {
143 return (Size)std::list<Value>::size();
144 }
145
150 bool remove(const Value& item)
151 {
152 Iterator it = std::list<Value>::begin();
153 for (; it != std::list<Value>::end(); ++it)
154 {
155 if (*it == item)
156 {
157 std::list<Value>::erase(it);
158 return true;
159 }
160 }
161 return false;
162 }
163
165
167
171 bool isEmpty() const
172 {
173 return (std::list<Value>::size() == 0);
174 }
175
177
179
184 virtual void host(Visitor<List<Value> >& visitor);
185
187
189
195 {
196 if (!processor.start()) return false;
197
198 for (Iterator it = std::list<Value>::begin(); it != std::list<Value>::end(); ++it)
199 {
200 Processor::Result result = processor(*it);
201 if (result <= Processor::BREAK)
202 {
203 return (result == Processor::BREAK);
204 }
205 }
206
207 return processor.finish();
208 }
209
211
215 bool operator == (const List<Value>& list) const
216 {
217 if (std::list<Value>::size() != list.size())
218 {
219 return false;
220 }
221
222 typename List<Value>::ConstIterator this_it = std::list<Value>::begin();
223 typename List<Value>::ConstIterator list_it = list.begin();
224
225 for (; this_it != std::list<Value>::end(); ++this_it)
226 {
227 if (!(*this_it == *list_it))
228 {
229 return false;
230 }
231 ++list_it;
232 }
233 return true;
234 }
235
239 bool operator != (const List<Value>& list) const
240 {
241 return !(*this == list);
242 }
243
244 };
245
246 template <typename Value>
248 {
249 visitor.visit(*this);
250 }
251} // namespace BALL
252
253#endif // BALL_DATATYPE_LIST_H
#define BALL_CREATE_DEEP(name)
Definition create.h:26
STL namespace.
virtual bool start()
Definition processor.h:92
virtual bool finish()
Definition processor.h:99
const List & operator=(const List &list)
Definition list.h:114
bool operator!=(const List< Value > &list) const
Definition list.h:239
bool apply(UnaryProcessor< Value > &processor)
Definition list.h:194
void destroy()
Definition list.h:81
bool operator==(const List< Value > &list) const
Definition list.h:215
std::list< Value >::iterator Iterator
Definition list.h:45
void swap(List &list)
Swaps the contents of two lists.
Definition list.h:127
void set(const List &list, bool=true)
Definition list.h:101
std::list< Value >::const_iterator ConstIterator
Definition list.h:51
std::list< Value >::const_iterator const_iterator
Definition list.h:53
void get(List &list, bool deep=true) const
Assign the content of a list to another.
Definition list.h:121
virtual void host(Visitor< List< Value > > &visitor)
Definition list.h:247
bool remove(const Value &item)
Definition list.h:150
Size getSize() const
Definition list.h:141
bool isEmpty() const
Definition list.h:171
virtual ~List()
Definition list.h:88
List(const List &new_list, bool)
Definition list.h:74
std::list< Value >::iterator iterator
Definition list.h:47