Orfeo Toolbox  4.0
itkFixedArray.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 #ifndef __itkFixedArray_h
19 #define __itkFixedArray_h
20 
21 #include "itkMacro.h"
22 
23 namespace itk
24 {
25 
49 template< typename TValueType, unsigned int VLength = 3 >
51 {
52 public:
54  itkStaticConstMacro(Length, unsigned int, VLength);
55 
57  itkStaticConstMacro(Dimension, unsigned int, VLength);
58 
60  typedef TValueType ValueType;
61 
63  typedef ValueType CArray[VLength];
64 
66  typedef ValueType *Iterator;
67 
69  typedef const ValueType *ConstIterator;
70 
71  class ConstReverseIterator;
72 
78  {
79  public:
81  Iterator operator++() { return --m_Iterator; }
82  Iterator operator++(int) { return m_Iterator--; }
83  Iterator operator--() { return ++m_Iterator; }
84  Iterator operator--(int) { return m_Iterator++; }
85  Iterator operator->() const { return ( m_Iterator - 1 ); }
86  ValueType & operator*() const { return *( m_Iterator - 1 ); }
87  bool operator!=(const ReverseIterator & rit) const { return m_Iterator != rit.m_Iterator; }
88  bool operator==(const ReverseIterator & rit) const { return m_Iterator == rit.m_Iterator; }
89 
90  private:
92  friend class ConstReverseIterator;
93  };
94 
100  {
101  public:
108  ConstIterator operator->() const { return ( m_Iterator - 1 ); }
109  const ValueType & operator*() const { return *( m_Iterator - 1 ); }
110  bool operator!=(const ConstReverseIterator & rit) const { return m_Iterator != rit.m_Iterator; }
111  bool operator==(const ConstReverseIterator & rit) const { return m_Iterator == rit.m_Iterator; }
112 
113  private:
115  };
116 
118  typedef ValueType *pointer;
119 
121  typedef const ValueType *const_pointer;
122 
124  typedef ValueType & reference;
125 
127  typedef const ValueType & const_reference;
128 
129  typedef unsigned int SizeType;
130 
131 public:
133  FixedArray();
134  FixedArray(const ValueType r[VLength]);
135  FixedArray(const ValueType & r);
136 
138  template< typename TFixedArrayValueType >
140  {
142  Iterator i = this->Begin();
143  while ( i != this->End() )
144  {
145  *i++ = static_cast< TValueType >( *input++ );
146  }
147  }
148 
149  template< typename TScalarValue >
150  FixedArray(const TScalarValue *r)
151  {
152  std::copy(r, r + this->Size(), this->GetDataPointer());
153  }
154 
169  template< typename TFixedArrayValueType >
171  {
172  if ( (void *)r.Begin() != (void *)m_InternalArray )
173  {
175  Iterator i = this->Begin();
176  while ( i != this->End() )
177  {
178  *i++ = static_cast< TValueType >( *input++ );
179  }
180  }
181  return *this;
182  }
183 
184  FixedArray & operator=(const ValueType r[VLength]);
185 
189  bool operator==(const FixedArray & r) const;
190 
191  bool operator!=(const FixedArray & r) const
192  { return !operator==(r); }
193 
197  reference operator[](short index) { return m_InternalArray[index]; }
198  const_reference operator[](short index) const { return m_InternalArray[index]; }
199  reference operator[](unsigned short index) { return m_InternalArray[index]; }
200  const_reference operator[](unsigned short index) const { return m_InternalArray[index]; }
201  reference operator[](int index) { return m_InternalArray[index]; }
202  const_reference operator[](int index) const { return m_InternalArray[index]; }
203  reference operator[](unsigned int index) { return m_InternalArray[index]; }
204  const_reference operator[](unsigned int index) const { return m_InternalArray[index]; }
205  reference operator[](long index) { return m_InternalArray[index]; }
206  const_reference operator[](long index) const { return m_InternalArray[index]; }
207  reference operator[](unsigned long index) { return m_InternalArray[index]; }
208  const_reference operator[](unsigned long index) const { return m_InternalArray[index]; }
209  reference operator[](long long index) { return m_InternalArray[index]; }
210  const_reference operator[](long long index) const { return m_InternalArray[index]; }
211  reference operator[](unsigned long long index) { return m_InternalArray[index]; }
212  const_reference operator[](unsigned long long index) const { return m_InternalArray[index]; }
213 
215  void SetElement(unsigned short index, const_reference value)
216  { m_InternalArray[index] = value; }
217  const_reference GetElement(unsigned short index) const { return m_InternalArray[index]; }
218 
221  {
222  return m_InternalArray; \
223  }
224 
225  const ValueType * GetDataPointer() const
226  {
227  return m_InternalArray; \
228  }
229 
231  Iterator Begin();
232 
233  ConstIterator Begin() const;
234 
235  Iterator End();
236 
237  ConstIterator End() const;
238 
239  ReverseIterator rBegin();
240 
241  ConstReverseIterator rBegin() const;
242 
243  ReverseIterator rEnd();
244 
245  ConstReverseIterator rEnd() const;
246 
247  SizeType Size() const;
248 
249  void Fill(const ValueType &);
250 
251 private:
254 
255 public:
256 
257  static FixedArray Filled(const ValueType &);
258 };
259 
260 template< typename TValueType, unsigned int VLength >
261 std::ostream & operator<<(std::ostream & os, const FixedArray< TValueType, VLength > & arr);
262 } // namespace itk
263 
264 #ifndef ITK_MANUAL_INSTANTIATION
265 #include "itkFixedArray.hxx"
266 #endif
267 
269 
270 #endif

Generated at Sat Mar 8 2014 14:38:11 for Orfeo Toolbox with doxygen 1.8.3.1