00001
00002
00003
00004
00005 #ifndef BALL_DATATYPE_LIST_H
00006 #define BALL_DATATYPE_LIST_H
00007
00008 #ifndef BALL_COMMON_H
00009 # include <BALL/common.h>
00010 #endif
00011
00012 #ifndef BALL_CONCEPT_VISITOR_H
00013 # include <BALL/CONCEPT/visitor.h>
00014 #endif
00015
00016 #ifndef BALL_CONCEPT_PROCESSOR_H
00017 # include <BALL/CONCEPT/processor.h>
00018 #endif
00019
00020 #include <list>
00021
00022 #ifdef BALL_COMPILER_GXX
00023 #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."
00024 #endif
00025
00026 namespace BALL
00027 {
00033 template <typename Value>
00034 class List
00035 : public std::list<Value>
00036 {
00037 public:
00038
00042
00045 typedef typename std::list<Value>::iterator Iterator;
00046
00047 typedef typename std::list<Value>::iterator iterator;
00048
00051 typedef typename std::list<Value>::const_iterator ConstIterator;
00052
00053 typedef typename std::list<Value>::const_iterator const_iterator;
00054
00056
00058
00059 BALL_CREATE_DEEP(List)
00060
00061
00064 List()
00065 : std::list<Value>()
00066 {
00067 }
00068
00074 List(const List& new_list, bool )
00075 : std::list<Value>(new_list)
00076 {
00077 }
00078
00081 void destroy()
00082 {
00083 std::list<Value>::clear();
00084 }
00085
00088 virtual ~List()
00089 {
00090 std::list<Value>::clear();
00091 }
00092
00094
00096
00101 void set(const List& list, bool = true)
00102 {
00103 std::list<Value>::clear();
00104
00105 ConstIterator it = list.begin();
00106 for ( ; it != list.end(); ++it)
00107 {
00108 std::list<Value>::push_back(const_cast<Value&>(*it));
00109 }
00110 }
00111
00114 const List& operator = (const List& list)
00115 {
00116 set(list);
00117 return *this;
00118 }
00119
00121 void get(List& list, bool deep = true) const
00122 {
00123 list.set(*this, deep);
00124 }
00125
00127 void swap(List& list)
00128 {
00129 List<Value> temp;
00130 temp.set(*this);
00131 (*this).set(list);
00132 list.set(temp);
00133 }
00134
00136
00138
00141 Size getSize() const
00142 {
00143 return (Size)std::list<Value>::size();
00144 }
00145
00150 bool remove(const Value& item)
00151 {
00152 Iterator it = std::list<Value>::begin();
00153 for (; it != std::list<Value>::end(); ++it)
00154 {
00155 if (*it == item)
00156 {
00157 std::list<Value>::erase(it);
00158 return true;
00159 }
00160 }
00161 return false;
00162 }
00163
00165
00167
00171 bool isEmpty() const
00172 {
00173 return (std::list<Value>::size() == 0);
00174 }
00175
00177
00179
00184 virtual void host(Visitor<List<Value> >& visitor);
00185
00187
00189
00194 bool apply(UnaryProcessor<Value>& processor)
00195 {
00196 if (!processor.start()) return false;
00197
00198 for (Iterator it = std::list<Value>::begin(); it != std::list<Value>::end(); ++it)
00199 {
00200 Processor::Result result = processor(*it);
00201 if (result <= Processor::BREAK)
00202 {
00203 return (result == Processor::BREAK);
00204 }
00205 }
00206
00207 return processor.finish();
00208 }
00209
00211
00215 bool operator == (const List<Value>& list) const
00216 {
00217 if (std::list<Value>::size() != list.size())
00218 {
00219 return false;
00220 }
00221
00222 typename List<Value>::ConstIterator this_it = std::list<Value>::begin();
00223 typename List<Value>::ConstIterator list_it = list.begin();
00224
00225 for (; this_it != std::list<Value>::end(); ++this_it)
00226 {
00227 if (!(*this_it == *list_it))
00228 {
00229 return false;
00230 }
00231 ++list_it;
00232 }
00233 return true;
00234 }
00235
00239 bool operator != (const List<Value>& list) const
00240 {
00241 return !(*this == list);
00242 }
00243
00244 };
00245
00246 template <typename Value>
00247 void List<Value>::host(Visitor<List<Value> >& visitor)
00248 {
00249 visitor.visit(*this);
00250 }
00251 }
00252
00253 #endif // BALL_DATATYPE_LIST_H