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  * Copyright UMC Utrecht and contributors
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
22 /*=========================================================================
23 
24  Program: Insight Segmentation & Registration Toolkit
25  Module: $RCSfile$
26  Language: C++
27  Date: $Date: 2008-04-15 19:54:41 +0200 (Tue, 15 Apr 2008) $
28  Version: $Revision: 1573 $
29 
30  Copyright (c) Insight Software Consortium. All rights reserved.
31  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
32 
33  This software is distributed WITHOUT ANY WARRANTY; without even
34  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
35  PURPOSE. See the above copyright notices for more information.
36 
37 =========================================================================*/
38 #ifndef __itkVectorDataContainer_h
39 #define __itkVectorDataContainer_h
40 
41 #include "itkDataObject.h"
42 #include "itkObjectFactory.h"
43 
44 #include <utility>
45 #include <vector>
46 
47 namespace itk
48 {
49 
72 template<
73 typename TElementIdentifier,
74 typename TElement
75 >
77  public DataObject,
78  public std::vector< TElement >
79 {
80 public:
81 
84  typedef DataObject Superclass;
86  typedef SmartPointer< const Self > ConstPointer;
87 
89  typedef TElementIdentifier ElementIdentifier;
90  typedef TElement Element;
91 
92 private:
93 
95  typedef std::vector< Element > VectorType;
96  typedef typename VectorType::size_type size_type;
97  typedef typename VectorType::iterator VectorIterator;
98  typedef typename VectorType::const_iterator VectorConstIterator;
99 
100 protected:
101 
106  DataObject(), VectorType() {}
107  VectorDataContainer( size_type n ) :
108  DataObject(), VectorType( n ) {}
109  VectorDataContainer( size_type n, const Element & x ) :
110  DataObject(), VectorType( n, x ) {}
111  VectorDataContainer( const Self & r ) :
112  DataObject(), VectorType( r ) {}
113  template< typename InputIterator >
114  VectorDataContainer( InputIterator first, InputIterator last ) :
115  DataObject(), VectorType( first, last ) {}
116 
117 public:
118 
120  typedef VectorType STLContainerType;
121 
123  itkNewMacro( Self );
124 
126  itkTypeMacro( VectorDataContainer, DataObject );
127 
129  class Iterator;
130  class ConstIterator;
131 
133  STLContainerType & CastToSTLContainer()
134  {
135  return dynamic_cast< STLContainerType & >( *this );
136  }
137 
138 
140  const STLContainerType & CastToSTLConstContainer() const
141  {
142  return dynamic_cast< const STLContainerType & >( *this );
143  }
144 
145 
147  friend class Iterator;
148  friend class ConstIterator;
149 
152  class Iterator
153  {
154 public:
155 
156  Iterator() {}
157  Iterator( size_type d, const VectorIterator & i ) : m_Pos( d ), m_Iter( i ) {}
158 
159  Iterator & operator*() { return *this; }
160  Iterator * operator->() { return this; }
161  Iterator & operator++() { ++m_Pos; ++m_Iter; return *this; }
162  Iterator operator++( int ) { Iterator temp( *this ); ++m_Pos; ++m_Iter; return temp; }
163  Iterator operator+=( int j ){ m_Pos += j; m_Iter += j; return *this; }
164  Iterator operator-=( int j ){ m_Pos -= j; m_Iter -= j; return *this; }
165  Iterator & operator--() { --m_Pos; --m_Iter; return *this; }
166  Iterator operator--( int ) { Iterator temp( *this ); --m_Pos; --m_Iter; return temp; }
167 
168  bool operator==( const Iterator & r ) const { return m_Iter == r.m_Iter; }
169  bool operator!=( const Iterator & r ) const { return m_Iter != r.m_Iter; }
170  bool operator==( const ConstIterator & r ) const { return m_Iter == r.m_Iter; }
171  bool operator!=( const ConstIterator & r ) const { return m_Iter != r.m_Iter; }
172 
174  ElementIdentifier Index( void ) const { return static_cast< ElementIdentifier >( m_Pos ); }
175 
177  Element & Value( void ) const { return *m_Iter; }
178 
179 private:
180 
181  size_type m_Pos;
182  VectorIterator m_Iter;
183  friend class ConstIterator;
184  };
185 
188  class ConstIterator
189  {
190 public:
191 
192  ConstIterator() {}
193  ConstIterator( size_type d, const VectorConstIterator & i ) : m_Pos( d ), m_Iter( i ) {}
194  ConstIterator( const Iterator & r ) { m_Pos = r.m_Pos; m_Iter = r.m_Iter; }
195 
196  ConstIterator & operator*() { return *this; }
197  ConstIterator * operator->() { return this; }
198  ConstIterator & operator++() { ++m_Pos; ++m_Iter; return *this; }
199  ConstIterator operator++( int ) { ConstIterator temp( *this ); ++m_Pos; ++m_Iter; return temp; }
200  ConstIterator operator+=( int j ){ m_Pos += j; m_Iter += j; return *this; }
201  ConstIterator operator-=( int j ){ m_Pos -= j; m_Iter -= j; return *this; }
202  ConstIterator & operator--() { --m_Pos; --m_Iter; return *this; }
203  ConstIterator operator--( int ) { ConstIterator temp( *this ); --m_Pos; --m_Iter; return temp; }
204 
205  ConstIterator & operator=( const Iterator & r ) { m_Pos = r.m_Pos; m_Iter = r.m_Iter; return *this; }
206 
207  bool operator==( const Iterator & r ) const { return m_Iter == r.m_Iter; }
208  bool operator!=( const Iterator & r ) const { return m_Iter != r.m_Iter; }
209  bool operator==( const ConstIterator & r ) const { return m_Iter == r.m_Iter; }
210  bool operator!=( const ConstIterator & r ) const { return m_Iter != r.m_Iter; }
211 
213  ElementIdentifier Index( void ) const { return static_cast< ElementIdentifier >( m_Pos ); }
214 
216  const Element & Value( void ) const { return *m_Iter; }
217 
218 private:
219 
220  size_type m_Pos;
221  VectorConstIterator m_Iter;
222  friend class Iterator;
223  };
224 
225  /* Declare the public interface routines. */
226 
235  Element & ElementAt( ElementIdentifier );
236 
243  const Element & ElementAt( ElementIdentifier ) const;
244 
253  Element & CreateElementAt( ElementIdentifier );
254 
259  Element GetElement( ElementIdentifier ) const;
260 
265  void SetElement( ElementIdentifier, Element );
266 
272  void InsertElement( ElementIdentifier, Element );
273 
278  bool IndexExists( ElementIdentifier ) const;
279 
285  bool GetElementIfIndexExists( ElementIdentifier, Element * ) const;
286 
292  void CreateIndex( ElementIdentifier );
293 
299  void DeleteIndex( ElementIdentifier );
300 
304  ConstIterator Begin( void ) const;
305 
309  ConstIterator End( void ) const;
310 
314  Iterator Begin( void );
315 
319  Iterator End( void );
320 
324  unsigned long Size( void ) const;
325 
335  void Reserve( ElementIdentifier );
336 
343  void Squeeze( void );
344 
348  void Initialize( void );
349 
350 };
351 
352 } // end namespace itk
353 
354 #ifndef ITK_MANUAL_INSTANTIATION
355 #include "itkVectorDataContainer.hxx"
356 #endif
357 
358 #endif // end __itkVectorDataContainer_h
ConstIterator Begin(void) const
ConstIterator End(void) const
bool GetElementIfIndexExists(ElementIdentifier, Element *) const
bool IndexExists(ElementIdentifier) const
void DeleteIndex(ElementIdentifier)
Element & CreateElementAt(ElementIdentifier)
__host__ __device__ void operator-=(int2 &a, int2 b)
SmartPointer< const Self > ConstPointer
VectorDataContainer(size_type n, const Element &x)
STLContainerType & CastToSTLContainer()
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
__host__ __device__ int2 operator*(int2 a, int2 b)
void CreateIndex(ElementIdentifier)
void SetElement(ElementIdentifier, Element)
const STLContainerType & CastToSTLConstContainer() const
std::vector< Element > VectorType
VectorType::size_type size_type
SmartPointer< Self > Pointer
void InsertElement(ElementIdentifier, Element)
bool ITKOpenCL_EXPORT operator==(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)
Element GetElement(ElementIdentifier) const
VectorDataContainer(InputIterator first, InputIterator last)
bool ITKOpenCL_EXPORT operator!=(const OpenCLCommandQueue &lhs, const OpenCLCommandQueue &rhs)
unsigned long Size(void) const
Element & ElementAt(ElementIdentifier)
__host__ __device__ void operator+=(int2 &a, int2 b)
void Reserve(ElementIdentifier)
VectorType::iterator VectorIterator
VectorType::const_iterator VectorConstIterator
TElementIdentifier ElementIdentifier


Generated on 04-09-2015 for elastix by doxygen 1.8.9.1 elastix logo