KWStyle - itkFixedArray.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkFixedArray.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:35 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 DEF #ifndef _itkFixedArray_txx
18 DEF #define _itkFixedArray_txx
19
20 #include "itkFixedArray.h"
21
22 namespace itk
23 {
24
25 /**
26  * Default constructor uses compiler's default initialization of memory.
27  * For efficiency, no initialization to zero is done.
28  */
29 template <typename TValueType, unsigned int VLength>
30 FixedArray<TValueType, VLength>
31 ::FixedArray()
32 {
33 }
34
35 /**
36  * Constructor assumes input points to array of correct size.
37  * Values are copied individually instead of with a binary copy.  This
38  * allows the ValueType's assignment operator to be executed.
39  */
40 template <typename TValueType, unsigned int VLength>
41 FixedArray<TValueType, VLength>
42 ::FixedArray(const ValueType r[VLength])
43 {
44   ConstIterator input = r;
45 SEM,SEM   for(Iterator i = this->Begin() ; i != this->End() ;) *i++ = *input++;
46 }
47
48
49 /**
50  * Destructor does nothing special.  Here for completeness.
51  */
52 template <typename TValueType, unsigned int VLength>
53 FixedArray<TValueType, VLength>
54 ::~FixedArray()
55 {
56 }
57
58
59 /**
60  * Assignment operator assumes input points to array of correct size.
61  * Values are copied individually instead of with a binary copy.  This
62  * allows the ValueType's assignment operator to be executed.
63  */
64 template <typename TValueType, unsigned int VLength>
65 FixedArray<TValueType, VLength>&
66 FixedArray<TValueType, VLength>
67 ::operator= (const ValueType r[VLength])
68 {
69   if(r == m_InternalArray) return *this;
70   ConstIterator input = r;
71 SEM,SEM   for(Iterator i = this->Begin() ; i != this->End() ;) *i++ = *input++;
72   return *this;
73 }
74
75
76 /**
77  * Operator != compares different types of arrays.
78  */
79 template <typename TValueType, unsigned int VLength>
80 bool
81 FixedArray<TValueType, VLength>
82 ::operator== (const FixedArray& r) const
83 {
84   ConstIterator i = this->Begin();
85   ConstIterator j = r.Begin();
86   
87 SEM   for( ; i != this->End(); ++i, ++j )
88     {
89     if ( *i != *j ) {return false;}
90     }
91
92   return true;
93 }
94
95 /**
96  * Get an Iterator for the beginning of the FixedArray.
97  */
98 template <typename TValueType, unsigned int VLength>
99 typename FixedArray<TValueType, VLength>::Iterator
100 FixedArray<TValueType, VLength>
101 ::Begin()
102 {
103   return Iterator(m_InternalArray);
104 }
105
106
107 /**
108  * Get a ConstIterator for the beginning of the FixedArray.
109  */
110 template <typename TValueType, unsigned int VLength>
111 typename FixedArray<TValueType, VLength>::ConstIterator
112 FixedArray<TValueType, VLength>
113 ::Begin() const
114 {
115   return ConstIterator(m_InternalArray);
116 }
117
118
119 /**
120  * Get an Iterator for the end of the FixedArray.
121  */
122 template <typename TValueType, unsigned int VLength>
123 typename FixedArray<TValueType, VLength>::Iterator
124 FixedArray<TValueType, VLength>
125 ::End()
126 {
127   return Iterator(m_InternalArray+VLength);
128 }
129
130
131 /**
132  * Get a ConstIterator for the end of the FixedArray.
133  */
134 template <typename TValueType, unsigned int VLength>
135 typename FixedArray<TValueType, VLength>::ConstIterator
136 FixedArray<TValueType, VLength>
137 ::End() const
138 {
139   return ConstIterator(m_InternalArray+VLength);
140 }
141
142
143 /**
144  * Get a begin ReverseIterator.
145  */
146 template <typename TValueType, unsigned int VLength>
147 typename FixedArray<TValueType, VLength>::ReverseIterator
148 FixedArray<TValueType, VLength>
149 ::rBegin() 
150 {
151   return ReverseIterator(m_InternalArray+VLength);
152 }
153
154
155 /**
156  * Get a begin ConstReverseIterator.
157  */
158 template <typename TValueType, unsigned int VLength>
159 typename FixedArray<TValueType, VLength>::ConstReverseIterator
160 FixedArray<TValueType, VLength>
161 ::rBegin() const
162 {
163   return ConstReverseIterator(m_InternalArray+VLength);
164 }
165
166
167 /**
168  * Get an end ReverseIterator.
169  */
170 template <typename TValueType, unsigned int VLength>
171 typename FixedArray<TValueType, VLength>::ReverseIterator
172 FixedArray<TValueType, VLength>
173 ::rEnd() 
174 {
175   return ReverseIterator(m_InternalArray);
176 }
177
178
179 /**
180  * Get an end ConstReverseIterator.
181  */
182 template <typename TValueType, unsigned int VLength>
183 typename FixedArray<TValueType, VLength>::ConstReverseIterator
184 FixedArray<TValueType, VLength>
185 ::rEnd() const 
186 {
187   return ConstReverseIterator(m_InternalArray);
188 }
189
190
191 /**
192  * Get the size of the FixedArray.
193  */
194 template <typename TValueType, unsigned int VLength>
195 typename FixedArray<TValueType, VLength>::SizeType
196 FixedArray<TValueType, VLength>
197 ::Size() const
198 {
199   return VLength; 
200 }
201
202
203 /**
204  * Fill all elements of the array with the given value.
205  */
206 template <typename TValueType, unsigned int VLength>
207 void
208 FixedArray<TValueType, VLength>
209 ::Fill(const ValueType& value)
210 {
211 SEM,SEM   for(Iterator i = this->Begin() ; i != this->End() ;) *i++ = value;
212 }
213
214
215 /**
216  * Return an FixedArray with all elements assigned to the given value.
217  */
218 template <typename TValueType, unsigned int VLength>
219 FixedArray<TValueType, VLength>
220 FixedArray<TValueType, VLength>
221 ::Filled(const ValueType& value)
222 {
223   FixedArray<ValueType, VLength> array;
224   array.Fill(value);
225   return array;
226 }
227
228
229 // namespace itk
230
231 #endif
232

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:08PM
© Kitware Inc.