00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 #ifndef VRS_CONTAINER_SEQUENCECONTAINERSTL_H
00135 #define VRS_CONTAINER_SEQUENCECONTAINERSTL_H
00136
00137 #include <vrs/container/iterator.h>
00138
00139 namespace VRS {
00140
00141 template<typename T, class STL_CONTAINER>
00142 class SequenceContainerIteratorSTL;
00143
00149 template<typename T, class STL_CONTAINER>
00150 class SequenceContainerSTL : public SharedObj {
00151 protected:
00152 SequenceContainerSTL();
00153 SequenceContainerSTL(unsigned int size);
00154 SequenceContainerSTL(unsigned int size, const T& initValue);
00155 SequenceContainerSTL(const Iterator<T>* sourceItr);
00156
00157 public:
00158 typedef typename STL_CONTAINER::iterator iterator;
00159 typedef typename STL_CONTAINER::const_iterator const_iterator;
00160 typedef typename STL_CONTAINER::reference reference;
00161 typedef typename STL_CONTAINER::const_reference const_reference;
00162
00163 unsigned int size() const { return (unsigned int)container_.size(); }
00165
00166 bool isEmpty() const { return container_.empty(); }
00168
00169 void clear() { container_.clear(); }
00170
00171
00172 void setElement(unsigned int index, const T& obj);
00173 T getElement(unsigned int index) const { return operator[](index); }
00175
00176 void prepend(const T& obj);
00177 void prepend(const T& obj, unsigned int count);
00178 void prepend(const Iterator<T>* iter);
00182 void append(const T& obj);
00183 void append(const T& obj, unsigned int count);
00184 void append(const Iterator<T>* iter);
00188 void insert(unsigned int pos, const T& obj);
00189 void insert(unsigned int pos, const T& obj, unsigned int count);
00190 void insert(unsigned int pos, const Iterator<T>* iter);
00196 void removeFirst();
00197 void removeFirst(unsigned int count);
00200 void removeLast();
00201 void removeLast(unsigned int count);
00204 void remove(unsigned int pos);
00205 void remove(unsigned int pos, unsigned int count);
00209 int find(const T& obj) const;
00210 bool contains(const T& obj) const;
00211 bool erase(const T& obj, bool eraseAll = false);
00218 void resize(unsigned int newSize, const T& initValue = T());
00223 virtual Iterator<T>* newIterator() const;
00225
00226 virtual void modified();
00228
00229 VRS_TYPEINFO(SequenceContainerSTL, SharedObj);
00230
00231 public:
00232
00233
00234 typename SequenceContainerSTL<T, STL_CONTAINER>::reference
00235 operator[](unsigned int index) { VRS_CheckArg(index < size(), "index out of range"); return *seek(index); }
00236 typename SequenceContainerSTL<T, STL_CONTAINER>::const_reference
00237 operator[](unsigned int index) const { VRS_CheckArg(index < size(), "index out of range"); return *seek(index); }
00238
00239 iterator beginSTL() { return container_.begin(); }
00240 const_iterator beginSTL() const { return container_.begin(); }
00241 iterator endSTL() { return container_.end(); }
00242 const_iterator endSTL() const { return container_.end(); }
00243
00244 STL_CONTAINER& containerSTL() { return container_; }
00245 const STL_CONTAINER& containerSTL() const { return container_; }
00246
00247 protected:
00248 friend class SequenceContainerIteratorSTL<T, STL_CONTAINER>;
00249 mutable Iterator<T>* iterator_;
00250
00251 private:
00252 iterator seek(unsigned int pos) const {
00253
00254 VRS_CheckArg(pos <= size(), "pos out of range");
00255
00256 SequenceContainerSTL* const nonconstThis = const_cast<SequenceContainerSTL*>(this);
00257
00258 if(pos == 0) {
00259 return nonconstThis->beginSTL();
00260 } else if(pos == size()) {
00261 return nonconstThis->endSTL();
00262 } else if(pos < size() - pos) {
00263
00264 iterator iter = nonconstThis->beginSTL();
00265 std::advance(iter, pos);
00266 return iter;
00267 } else {
00268
00269 iterator iter = nonconstThis->endSTL();
00270 std::advance(iter, int(pos) - int(size()));
00271 return iter;
00272 }
00273 }
00274
00275 STL_CONTAINER container_;
00276 };
00277
00278
00279 template<typename T, class STL_CONTAINER>
00280 class SequenceContainerIteratorSTL : public Iterator<T> {
00281 public:
00282 SequenceContainerIteratorSTL(const SequenceContainerSTL<T, STL_CONTAINER>* container)
00283 : container_(const_cast<SequenceContainerSTL<T, STL_CONTAINER>*>(container)) {
00284 VRS_CheckArg(container, "no container");
00285 container_->iterator_ = this;
00286 }
00287 virtual ~SequenceContainerIteratorSTL() { container_->iterator_ = NULL; }
00288
00289 virtual unsigned int size() const { return container_->size(); }
00290 virtual T get(unsigned int i) const { return (*container_)[i]; }
00291
00292 virtual SharedObj* container() const { return container_; }
00293
00294 VRS_TYPEINFO(SequenceContainerIteratorSTL, Iterator<T>);
00295 VRS_SERIALIZABLE_ABSTRACT_CLASS(SequenceContainerIteratorSTL);
00296
00297 protected:
00298 SequenceContainerIteratorSTL() { }
00299
00300 private:
00301 SO<SequenceContainerSTL<T, STL_CONTAINER> > container_;
00302 };
00303
00304 }
00305
00306 #include <vrs/container/sequencecontainerstl.tli>
00307
00308 #endif // VRS_CONTAINER_SEQUENCECONTAINERSTL_H