Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkFixedArray.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkFixedArray.h,v $ 00005 Language: C++ 00006 Date: $Date: 2003/09/10 14:29:07 $ 00007 Version: $Revision: 1.32 $ 00008 00009 Copyright (c) Insight Software Consortium. All rights reserved. 00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 #ifndef __itkFixedArray_h 00018 #define __itkFixedArray_h 00019 00020 #include "itkMacro.h" 00021 00022 namespace itk 00023 { 00024 00031 template <typename TVector> 00032 struct GetVectorDimension 00033 { 00034 itkStaticConstMacro(VectorDimension, unsigned int, TVector::Dimension); 00035 }; 00036 00037 00038 00058 template <typename TValueType, unsigned int VLength=3> 00059 class FixedArray 00060 { 00061 public: 00063 itkStaticConstMacro(Length, unsigned int, VLength); 00064 00066 itkStaticConstMacro(Dimension, unsigned int, VLength); 00067 00069 typedef TValueType ValueType; 00070 00072 typedef ValueType CArray[VLength]; 00073 00075 typedef ValueType* Iterator; 00076 00078 typedef const ValueType* ConstIterator; 00079 00081 class ReverseIterator 00082 { 00083 public: 00084 explicit ReverseIterator(Iterator i): m_Iterator(i) {} 00085 Iterator operator++() { return --m_Iterator; } 00086 Iterator operator++(int) { return m_Iterator--; } 00087 Iterator operator--() { return ++m_Iterator; } 00088 Iterator operator--(int) { return m_Iterator++; } 00089 Iterator operator->() const { return (m_Iterator-1); } 00090 ValueType& operator*() const { return *(m_Iterator-1); } 00091 private: 00092 Iterator m_Iterator; 00093 }; 00094 00096 class ConstReverseIterator 00097 { 00098 public: 00099 explicit ConstReverseIterator(ConstIterator i): m_Iterator(i) {} 00100 ConstIterator operator++() { return --m_Iterator; } 00101 ConstIterator operator++(int) { return m_Iterator--; } 00102 ConstIterator operator--() { return ++m_Iterator; } 00103 ConstIterator operator--(int) { return m_Iterator++; } 00104 ConstIterator operator->() const { return (m_Iterator-1); } 00105 const ValueType& operator*() const { return *(m_Iterator-1); } 00106 private: 00107 ConstIterator m_Iterator; 00108 }; 00109 00111 typedef ValueType* pointer; 00112 00114 typedef const ValueType* const_pointer; 00115 00117 typedef ValueType& reference; 00118 00120 typedef const ValueType& const_reference; 00121 00122 typedef unsigned int SizeType; 00123 00124 public: 00126 FixedArray(); 00127 FixedArray(const FixedArray& r); 00128 FixedArray(const ValueType r[VLength]); 00129 00132 ~FixedArray(); 00133 00135 FixedArray& operator= (const FixedArray& r); 00136 FixedArray& operator= (const ValueType r[VLength]); 00137 00141 bool operator==(const FixedArray& r ) const; 00142 bool operator!=(const FixedArray& r ) const 00143 { return !operator==(r); } 00144 00148 reference operator[](short index) { return m_InternalArray[index]; } 00149 const_reference operator[](short index) const { return m_InternalArray[index]; } 00150 reference operator[](unsigned short index) { return m_InternalArray[index]; } 00151 const_reference operator[](unsigned short index) const { return m_InternalArray[index]; } 00152 reference operator[](int index) { return m_InternalArray[index]; } 00153 const_reference operator[](int index) const { return m_InternalArray[index]; } 00154 reference operator[](unsigned int index) { return m_InternalArray[index]; } 00155 const_reference operator[](unsigned int index) const { return m_InternalArray[index]; } 00156 reference operator[](long index) { return m_InternalArray[index]; } 00157 const_reference operator[](long index) const { return m_InternalArray[index]; } 00158 reference operator[](unsigned long index) { return m_InternalArray[index]; } 00159 const_reference operator[](unsigned long index) const { return m_InternalArray[index]; } 00160 00162 void SetElement( unsigned short index, const_reference value ) 00163 { m_InternalArray[ index ] = value; } 00164 const_reference GetElement( unsigned short index ) const { return m_InternalArray[index]; } 00165 00167 ValueType* GetDataPointer() { return m_InternalArray; } 00168 const ValueType* GetDataPointer() const { return m_InternalArray; } 00169 00171 Iterator Begin(); 00172 ConstIterator Begin() const; 00173 Iterator End(); 00174 ConstIterator End() const; 00175 ReverseIterator rBegin(); 00176 ConstReverseIterator rBegin() const; 00177 ReverseIterator rEnd(); 00178 ConstReverseIterator rEnd() const; 00179 SizeType Size() const; 00180 void Fill(const ValueType&); 00181 00182 private: 00184 CArray m_InternalArray; 00185 00186 public: 00187 00188 static FixedArray Filled(const ValueType&); 00189 }; 00190 00191 template <typename TValueType, unsigned int VLength> 00192 std::ostream & operator<<(std::ostream &os, const FixedArray<TValueType,VLength> &arr) 00193 { 00194 os << "["; 00195 if ( VLength == 1 ) 00196 { 00197 os << arr[0] ; 00198 } 00199 else 00200 { 00201 for (int i=0; i < static_cast<int>(VLength) - 1; ++i) 00202 { 00203 os << arr[i] << ", "; 00204 } 00205 os << arr[VLength-1]; 00206 } 00207 os << "]"; 00208 return os; 00209 } 00210 00211 } // namespace itk 00212 00213 #ifndef ITK_MANUAL_INSTANTIATION 00214 #include "itkFixedArray.txx" 00215 #endif 00216 00217 #endif

Generated at Sat Mar 31 02:18:40 2007 for ITK by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2000