go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkVectorDataContainer.h
Go to the documentation of this file.
1 /*======================================================================
2 
3  This file is part of the elastix software.
4 
5  Copyright (c) University Medical Center Utrecht. All rights reserved.
6  See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php for
7  details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notices for more information.
12 
13 ======================================================================*/
14 
18 /*=========================================================================
19 
20  Program: Insight Segmentation & Registration Toolkit
21  Module: $RCSfile$
22  Language: C++
23  Date: $Date: 2008-04-15 19:54:41 +0200 (Tue, 15 Apr 2008) $
24  Version: $Revision: 1573 $
25 
26  Copyright (c) Insight Software Consortium. All rights reserved.
27  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
28 
29  This software is distributed WITHOUT ANY WARRANTY; without even
30  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
31  PURPOSE. See the above copyright notices for more information.
32 
33 =========================================================================*/
34 #ifndef __itkVectorDataContainer_h
35 #define __itkVectorDataContainer_h
36 
37 #include "itkDataObject.h"
38 #include "itkObjectFactory.h"
39 
40 #include <utility>
41 #include <vector>
42 
43 namespace itk
44 {
45 
68 template <
69  typename TElementIdentifier,
70  typename TElement
71  >
72 class ITK_EXPORT VectorDataContainer:
73  public DataObject,
74  public std::vector<TElement>
75 {
76 public:
79  typedef DataObject Superclass;
80  typedef SmartPointer<Self> Pointer;
81  typedef SmartPointer<const Self> ConstPointer;
82 
84  typedef TElementIdentifier ElementIdentifier;
85  typedef TElement Element;
86 
87 private:
89  typedef std::vector<Element> VectorType;
90  typedef typename VectorType::size_type size_type;
91  typedef typename VectorType::iterator VectorIterator;
92  typedef typename VectorType::const_iterator VectorConstIterator;
93 
94 protected:
99  DataObject(), VectorType() {}
101  DataObject(), VectorType(n) {}
103  DataObject(), VectorType(n, x) {}
105  DataObject(), VectorType(r) {}
106  template <typename InputIterator>
107  VectorDataContainer(InputIterator first, InputIterator last):
108  DataObject(), VectorType(first, last) {}
109 
110 public:
111 
114 
116  itkNewMacro( Self );
117 
119  itkTypeMacro( VectorDataContainer, DataObject );
120 
122  class Iterator;
123  class ConstIterator;
124 
127  return dynamic_cast<STLContainerType &>(*this); }
128 
131  return dynamic_cast<const STLContainerType &>(*this); }
132 
134  friend class Iterator;
135  friend class ConstIterator;
136 
139  class Iterator
140  {
141  public:
142  Iterator() {}
143  Iterator(size_type d, const VectorIterator& i): m_Pos(d), m_Iter(i) {}
144 
145  Iterator& operator* () { return *this; }
146  Iterator* operator-> () { return this; }
147  Iterator& operator++ () { ++m_Pos; ++m_Iter; return *this; }
148  Iterator operator++ (int) { Iterator temp(*this); ++m_Pos; ++m_Iter; return temp; }
149  Iterator& operator-- () { --m_Pos; --m_Iter; return *this; }
150  Iterator operator-- (int) { Iterator temp(*this); --m_Pos; --m_Iter; return temp; }
151 
152  bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
153  bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
154  bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
155  bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
156 
158  ElementIdentifier Index(void) const { return static_cast<ElementIdentifier>( m_Pos ); }
159 
161  Element& Value(void) const { return *m_Iter; }
162 
163  private:
164  size_type m_Pos;
165  VectorIterator m_Iter;
166  friend class ConstIterator;
167  };
168 
171  class ConstIterator
172  {
173  public:
174  ConstIterator() {}
175  ConstIterator(size_type d, const VectorConstIterator& i): m_Pos(d), m_Iter(i) {}
176  ConstIterator(const Iterator& r) { m_Pos = r.m_Pos; m_Iter = r.m_Iter; }
177 
178  ConstIterator& operator* () { return *this; }
179  ConstIterator* operator-> () { return this; }
180  ConstIterator& operator++ () { ++m_Pos; ++m_Iter; return *this; }
181  ConstIterator operator++ (int) { ConstIterator temp(*this); ++m_Pos; ++m_Iter; return temp; }
182  ConstIterator& operator-- () { --m_Pos; --m_Iter; return *this; }
183  ConstIterator operator-- (int) { ConstIterator temp(*this); --m_Pos; --m_Iter; return temp; }
184 
185  ConstIterator& operator = (const Iterator& r) { m_Pos = r.m_Pos; m_Iter = r.m_Iter; return *this; }
186 
187  bool operator == (const Iterator& r) const { return m_Iter == r.m_Iter; }
188  bool operator != (const Iterator& r) const { return m_Iter != r.m_Iter; }
189  bool operator == (const ConstIterator& r) const { return m_Iter == r.m_Iter; }
190  bool operator != (const ConstIterator& r) const { return m_Iter != r.m_Iter; }
191 
193  ElementIdentifier Index(void) const { return static_cast<ElementIdentifier>( m_Pos ); }
194 
196  const Element& Value(void) const { return *m_Iter; }
197 
198  private:
199  size_type m_Pos;
200  VectorConstIterator m_Iter;
201  friend class Iterator;
202  };
203 
204  /* Declare the public interface routines. */
205 
214  Element& ElementAt( ElementIdentifier );
215 
222  const Element& ElementAt( ElementIdentifier ) const;
223 
232  Element& CreateElementAt( ElementIdentifier );
233 
238  Element GetElement( ElementIdentifier ) const;
239 
244  void SetElement( ElementIdentifier, Element );
245 
251  void InsertElement( ElementIdentifier, Element );
252 
257  bool IndexExists( ElementIdentifier ) const;
258 
264  bool GetElementIfIndexExists( ElementIdentifier, Element * ) const;
265 
271  void CreateIndex( ElementIdentifier );
272 
278  void DeleteIndex( ElementIdentifier );
279 
283  ConstIterator Begin( void ) const;
284 
288  ConstIterator End( void ) const;
289 
293  Iterator Begin( void );
294 
298  Iterator End( void );
299 
303  unsigned long Size( void ) const;
304 
314  void Reserve( ElementIdentifier );
315 
322  void Squeeze( void );
323 
327  void Initialize( void );
328 
329 }; // end class VectorDataContainer
330 
331 } // end namespace itk
332 
333 #ifndef ITK_MANUAL_INSTANTIATION
334 #include "itkVectorDataContainer.txx"
335 #endif
336 
337 #endif // end __itkVectorDataContainer_h


Generated on 21-03-2014 for elastix by doxygen 1.8.1.2 elastix logo