Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef __itkVectorDataContainer_h
00035 #define __itkVectorDataContainer_h
00036
00037 #include "itkDataObject.h"
00038 #include "itkObjectFactory.h"
00039
00040 #include <utility>
00041 #include <vector>
00042
00043 namespace itk
00044 {
00045
00068 template <
00069 typename TElementIdentifier,
00070 typename TElement
00071 >
00072 class ITK_EXPORT VectorDataContainer:
00073 public DataObject,
00074 public std::vector<TElement>
00075 {
00076 public:
00078 typedef VectorDataContainer Self;
00079 typedef DataObject Superclass;
00080 typedef SmartPointer<Self> Pointer;
00081 typedef SmartPointer<const Self> ConstPointer;
00082
00084 typedef TElementIdentifier ElementIdentifier;
00085 typedef TElement Element;
00086
00087 private:
00089 typedef std::vector<Element> VectorType;
00090 typedef typename VectorType::size_type size_type;
00091 typedef typename VectorType::iterator VectorIterator;
00092 typedef typename VectorType::const_iterator VectorConstIterator;
00093
00094 protected:
00098 VectorDataContainer():
00099 DataObject(), VectorType() {}
00100 VectorDataContainer(size_type n):
00101 DataObject(), VectorType(n) {}
00102 VectorDataContainer(size_type n, const Element& x):
00103 DataObject(), VectorType(n, x) {}
00104 VectorDataContainer(const Self& r):
00105 DataObject(), VectorType(r) {}
00106 template <typename InputIterator>
00107 VectorDataContainer(InputIterator first, InputIterator last):
00108 DataObject(), VectorType(first, last) {}
00109
00110 public:
00111
00113 typedef VectorType STLContainerType;
00114
00116 itkNewMacro( Self );
00117
00119 itkTypeMacro( VectorDataContainer, DataObject );
00120
00122 class Iterator;
00123 class ConstIterator;
00124
00126 STLContainerType & CastToSTLContainer() {
00127 return dynamic_cast<STLContainerType &>(*this); }
00128
00130 const STLContainerType & CastToSTLConstContainer() const {
00131 return dynamic_cast<const STLContainerType &>(*this); }
00132
00134 friend class Iterator;
00135 friend class ConstIterator;
00136
00139 class Iterator
00140 {
00141 public:
00142 Iterator() {}
00143 Iterator(size_type d, const VectorIterator& i): m_Pos(d), m_Iter(i) {}
00144
00145 Iterator& operator* () { return *this; }
00146 Iterator* operator-> () { return this; }
00147 Iterator& operator++ () { ++m_Pos; ++m_Iter; return *this; }
00148 Iterator operator++ (int) { Iterator temp(*this); ++m_Pos; ++m_Iter; return temp; }
00149 Iterator& operator-- () { --m_Pos; --m_Iter; return *this; }
00150 Iterator operator-- (int) { Iterator temp(*this); --m_Pos; --m_Iter; return temp; }
00151
00152 bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00153 bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00154 bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00155 bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00156
00158 ElementIdentifier Index(void) const { return static_cast<ElementIdentifier>( m_Pos ); }
00159
00161 Element& Value(void) const { return *m_Iter; }
00162
00163 private:
00164 size_type m_Pos;
00165 VectorIterator m_Iter;
00166 friend class ConstIterator;
00167 };
00168
00171 class ConstIterator
00172 {
00173 public:
00174 ConstIterator() {}
00175 ConstIterator(size_type d, const VectorConstIterator& i): m_Pos(d), m_Iter(i) {}
00176 ConstIterator(const Iterator& r) { m_Pos = r.m_Pos; m_Iter = r.m_Iter; }
00177
00178 ConstIterator& operator* () { return *this; }
00179 ConstIterator* operator-> () { return this; }
00180 ConstIterator& operator++ () { ++m_Pos; ++m_Iter; return *this; }
00181 ConstIterator operator++ (int) { ConstIterator temp(*this); ++m_Pos; ++m_Iter; return temp; }
00182 ConstIterator& operator-- () { --m_Pos; --m_Iter; return *this; }
00183 ConstIterator operator-- (int) { ConstIterator temp(*this); --m_Pos; --m_Iter; return temp; }
00184
00185 ConstIterator& operator = (const Iterator& r) { m_Pos = r.m_Pos; m_Iter = r.m_Iter; return *this; }
00186
00187 bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00188 bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00189 bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00190 bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00191
00193 ElementIdentifier Index(void) const { return static_cast<ElementIdentifier>( m_Pos ); }
00194
00196 const Element& Value(void) const { return *m_Iter; }
00197
00198 private:
00199 size_type m_Pos;
00200 VectorConstIterator m_Iter;
00201 friend class Iterator;
00202 };
00203
00204
00205
00214 Element& ElementAt( ElementIdentifier );
00215
00222 const Element& ElementAt( ElementIdentifier ) const;
00223
00232 Element& CreateElementAt( ElementIdentifier );
00233
00238 Element GetElement( ElementIdentifier ) const;
00239
00244 void SetElement( ElementIdentifier, Element );
00245
00251 void InsertElement( ElementIdentifier, Element );
00252
00257 bool IndexExists( ElementIdentifier ) const;
00258
00264 bool GetElementIfIndexExists( ElementIdentifier, Element * ) const;
00265
00271 void CreateIndex( ElementIdentifier );
00272
00278 void DeleteIndex( ElementIdentifier );
00279
00283 ConstIterator Begin( void ) const;
00284
00288 ConstIterator End( void ) const;
00289
00293 Iterator Begin( void );
00294
00298 Iterator End( void );
00299
00303 unsigned long Size( void ) const;
00304
00314 void Reserve( ElementIdentifier );
00315
00322 void Squeeze( void );
00323
00327 void Initialize( void );
00328
00329 };
00330
00331 }
00332
00333 #ifndef ITK_MANUAL_INSTANTIATION
00334 #include "itkVectorDataContainer.txx"
00335 #endif
00336
00337 #endif // end __itkVectorDataContainer_h