00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkVectorContainer_h
00018 #define __itkVectorContainer_h
00019
00020 #include "itkObject.h"
00021 #include "itkObjectFactory.h"
00022
00023 #include <utility>
00024 #include <vector>
00025
00026 namespace itk
00027 {
00028
00044 template <
00045 typename TElementIdentifier,
00046 typename TElement
00047 >
00048 class ITK_EXPORT VectorContainer:
00049 public Object,
00050 private std::vector<TElement>
00051 {
00052 public:
00054 typedef VectorContainer Self;
00055 typedef Object Superclass;
00056 typedef SmartPointer<Self> Pointer;
00057 typedef SmartPointer<const Self> ConstPointer;
00058
00060 typedef TElementIdentifier ElementIdentifier;
00061 typedef TElement Element;
00062
00063 private:
00065 typedef std::vector<Element> VectorType;
00066 typedef typename VectorType::size_type size_type;
00067 typedef typename VectorType::iterator VectorIterator;
00068 typedef typename VectorType::const_iterator VectorConstIterator;
00069
00070 protected:
00074 VectorContainer():
00075 Object(), VectorType() {}
00076 VectorContainer(size_type n):
00077 Object(), VectorType(n) {}
00078 VectorContainer(size_type n, const Element& x):
00079 Object(), VectorType(n, x) {}
00080 VectorContainer(const Self& r):
00081 Object(), VectorType(r) {}
00082 template <typename InputIterator>
00083 VectorContainer(InputIterator first, InputIterator last):
00084 Object(), VectorType(first, last) {}
00085
00086 public:
00088 itkNewMacro(Self);
00089
00091 itkTypeMacro(VectorContainer, Object);
00092
00094 class Iterator;
00095 class ConstIterator;
00096
00098 friend class Iterator;
00099 friend class ConstIterator;
00100
00103 class Iterator
00104 {
00105 public:
00106 Iterator() {}
00107 Iterator(size_type d, const VectorIterator& i): m_Pos(d), m_Iter(i) {}
00108
00109 Iterator& operator* () { return *this; }
00110 Iterator* operator-> () { return this; }
00111 Iterator& operator++ () { ++m_Pos; ++m_Iter; return *this; }
00112 Iterator operator++ (int) { Iterator temp(*this); ++m_Pos; ++m_Iter; return temp; }
00113 Iterator& operator-- () { --m_Pos; --m_Iter; return *this; }
00114 Iterator operator-- (int) { Iterator temp(*this); --m_Pos; --m_Iter; return temp; }
00115
00116 bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00117 bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00118 bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00119 bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00120
00122 ElementIdentifier Index(void) const { return m_Pos; }
00123
00125 Element& Value(void) const { return *m_Iter; }
00126
00127 private:
00128 size_type m_Pos;
00129 VectorIterator m_Iter;
00130 friend class ConstIterator;
00131 };
00132
00135 class ConstIterator
00136 {
00137 public:
00138 ConstIterator() {}
00139 ConstIterator(size_type d, const VectorConstIterator& i): m_Pos(d), m_Iter(i) {}
00140 ConstIterator(const Iterator& r) { m_Pos = r.m_Pos; m_Iter = r.m_Iter; }
00141
00142 ConstIterator& operator* () { return *this; }
00143 ConstIterator* operator-> () { return this; }
00144 ConstIterator& operator++ () { ++m_Pos; ++m_Iter; return *this; }
00145 ConstIterator operator++ (int) { ConstIterator temp(*this); ++m_Pos; ++m_Iter; return temp; }
00146 ConstIterator& operator-- () { --m_Pos; --m_Iter; return *this; }
00147 ConstIterator operator-- (int) { ConstIterator temp(*this); --m_Pos; --m_Iter; return temp; }
00148
00149 Iterator& operator = (Iterator& r) { m_Pos = r.m_Pos; m_Iter = r.m_Iter; return r; }
00150
00151 bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
00152 bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
00153 bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
00154 bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
00155
00157 ElementIdentifier Index(void) const { return m_Pos; }
00158
00160 const Element& Value(void) const { return *m_Iter; }
00161
00162 private:
00163 size_type m_Pos;
00164 VectorConstIterator m_Iter;
00165 friend class Iterator;
00166 };
00167
00169 Element& ElementAt(ElementIdentifier);
00170 const Element& ElementAt(ElementIdentifier) const;
00171 Element& CreateElementAt(ElementIdentifier);
00172 Element GetElement(ElementIdentifier) const;
00173 void SetElement(ElementIdentifier, Element);
00174 void InsertElement(ElementIdentifier, Element);
00175 bool IndexExists(ElementIdentifier) const;
00176 bool GetElementIfIndexExists(ElementIdentifier, Element*) const;
00177 void CreateIndex(ElementIdentifier);
00178 void DeleteIndex(ElementIdentifier);
00179 ConstIterator Begin(void) const;
00180 ConstIterator End(void) const;
00181 Iterator Begin(void);
00182 Iterator End(void);
00183 unsigned long Size(void) const;
00184 void Reserve(ElementIdentifier);
00185 void Squeeze(void);
00186 void Initialize(void);
00187
00188 };
00189
00190 }
00191
00192 #ifndef ITK_MANUAL_INSTANTIATION
00193 #include "itkVectorContainer.txx"
00194 #endif
00195
00196 #endif