Orfeo Toolbox
3.16
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
OTB
Utilities
ITK
Code
Common
itkFixedArray.h
Go to the documentation of this file.
1
/*=========================================================================
2
3
Program: Insight Segmentation & Registration Toolkit
4
Module: $RCSfile: itkFixedArray.h,v $
5
Language: C++
6
Date: $Date: 2009-11-28 09:15:37 $
7
Version: $Revision: 1.46 $
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
#ifndef __itkFixedArray_h
18
#define __itkFixedArray_h
19
20
#include "
itkMacro.h
"
21
22
#ifdef _MSC_VER
23
# pragma warning (push)
24
# pragma warning (disable: 4284) // operator-> returning pointer to non-aggregate
25
#endif
26
27
namespace
itk
28
{
29
36
template
<
typename
TVector>
37
struct
GetVectorDimension
38
{
39
itkStaticConstMacro(
VectorDimension
,
unsigned
int
, TVector::Dimension);
40
};
41
42
43
63
template
<
typename
TValueType,
unsigned
int
VLength=3>
64
class
FixedArray
65
{
66
public
:
68
itkStaticConstMacro(
Length
,
unsigned
int
, VLength);
69
71
itkStaticConstMacro(
Dimension
,
unsigned
int
, VLength);
72
74
typedef
TValueType
ValueType
;
75
77
typedef
ValueType
CArray
[VLength];
78
80
typedef
ValueType
*
Iterator
;
81
83
typedef
const
ValueType
*
ConstIterator
;
84
85
class
ConstReverseIterator;
86
89
class
ReverseIterator
90
{
91
public
:
92
explicit
ReverseIterator
(
Iterator
i):
m_Iterator
(i) {}
93
Iterator
operator++
() {
return
--
m_Iterator
; }
94
Iterator
operator++
(
int
) {
return
m_Iterator
--; }
95
Iterator
operator--
() {
return
++
m_Iterator
; }
96
Iterator
operator--
(
int
) {
return
m_Iterator
++; }
97
Iterator
operator->
()
const
{
return
(
m_Iterator
-1); }
98
ValueType
&
operator*
()
const
{
return
*(
m_Iterator
-1); }
99
bool
operator!=
(
const
ReverseIterator
&rit)
const
{
return
m_Iterator
!= rit.
m_Iterator
;}
100
bool
operator==
(
const
ReverseIterator
&rit)
const
{
return
m_Iterator
== rit.
m_Iterator
;}
101
private
:
102
Iterator
m_Iterator
;
103
friend
class
ConstReverseIterator
;
104
};
105
108
class
ConstReverseIterator
109
{
110
public
:
111
explicit
ConstReverseIterator
(
ConstIterator
i):
m_Iterator
(i) {}
112
ConstReverseIterator
(
const
ReverseIterator
& rit) {
m_Iterator
= rit.
m_Iterator
; }
113
ConstIterator
operator++
() {
return
--
m_Iterator
; }
114
ConstIterator
operator++
(
int
) {
return
m_Iterator
--; }
115
ConstIterator
operator--
() {
return
++
m_Iterator
; }
116
ConstIterator
operator--
(
int
) {
return
m_Iterator
++; }
117
ConstIterator
operator->
()
const
{
return
(
m_Iterator
-1); }
118
const
ValueType
&
operator*
()
const
{
return
*(
m_Iterator
-1); }
119
bool
operator!=
(
const
ConstReverseIterator
&rit)
const
{
return
m_Iterator
!= rit.
m_Iterator
;}
120
bool
operator==
(
const
ConstReverseIterator
&rit)
const
{
return
m_Iterator
== rit.
m_Iterator
;}
121
private
:
122
ConstIterator
m_Iterator
;
123
};
124
126
typedef
ValueType
*
pointer
;
127
129
typedef
const
ValueType
*
const_pointer
;
130
132
typedef
ValueType
&
reference
;
133
135
typedef
const
ValueType
&
const_reference
;
136
137
typedef
unsigned
int
SizeType
;
138
139
public
:
141
FixedArray
();
142
FixedArray
(
const
ValueType
r[VLength]);
143
FixedArray
(
const
ValueType
& r);
144
146
template
<
class
TFixedArrayValueType >
147
FixedArray
(
const
FixedArray< TFixedArrayValueType, VLength >
& r)
148
{
149
typename
FixedArray< TFixedArrayValueType, VLength >::ConstIterator
input = r.
Begin
();
150
Iterator
i = this->
Begin
();
151
while
( i != this->
End
() )
152
{
153
*i++ =
static_cast<
TValueType
>
(*input++);
154
}
155
}
156
157
172
template
<
class
TFixedArrayValueType >
173
FixedArray
&
operator=
(
const
FixedArray< TFixedArrayValueType, VLength >
& r)
174
{
175
if
((
void
*)r.
Begin
() == (
void
*)
m_InternalArray
)
return
*
this
;
176
typename
FixedArray< TFixedArrayValueType, VLength >::ConstIterator
input = r.
Begin
();
177
Iterator
i = this->
Begin
();
178
while
( i != this->
End
() )
179
{
180
*i++ =
static_cast<
TValueType
>
(*input++);
181
}
182
return
*
this
;
183
}
184
185
FixedArray
&
operator=
(
const
ValueType
r[VLength]);
186
190
bool
operator==
(
const
FixedArray
& r )
const
;
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
211
void
SetElement
(
unsigned
short
index,
const_reference
value )
212
{
m_InternalArray
[ index ] = value; }
213
const_reference
GetElement
(
unsigned
short
index )
const
{
return
m_InternalArray
[index]; }
214
216
ValueType
*
GetDataPointer
() {
return
m_InternalArray
; }
217
const
ValueType
*
GetDataPointer
()
const
{
return
m_InternalArray
; }
218
220
Iterator
Begin
();
221
ConstIterator
Begin
()
const
;
222
Iterator
End
();
223
ConstIterator
End
()
const
;
224
ReverseIterator
rBegin
();
225
ConstReverseIterator
rBegin
()
const
;
226
ReverseIterator
rEnd
();
227
ConstReverseIterator
rEnd
()
const
;
228
SizeType
Size
()
const
;
229
void
Fill
(
const
ValueType
&);
230
231
private
:
233
CArray
m_InternalArray
;
234
235
public
:
236
237
static
FixedArray
Filled
(
const
ValueType
&);
238
};
239
240
template
<
typename
TValueType,
unsigned
int
VLength>
241
std::ostream & operator<<(std::ostream &os, const FixedArray<TValueType,VLength> &arr);
242
243
}
// namespace itk
244
245
#ifdef _MSC_VER
246
# pragma warning (pop)
247
#endif
248
249
// Define instantiation macro for this template.
250
#define ITK_TEMPLATE_FixedArray(_, EXPORT, x, y) namespace itk { \
251
_(2(class EXPORT FixedArray< ITK_TEMPLATE_2 x >)) \
252
_(1(EXPORT std::ostream& operator<<(std::ostream&, \
253
const FixedArray< ITK_TEMPLATE_2 x >&))) \
254
namespace Templates { typedef FixedArray< ITK_TEMPLATE_2 x > FixedArray##y; } \
255
}
256
257
#if ITK_TEMPLATE_EXPLICIT
258
# include "Templates/itkFixedArray+-.h"
259
#endif
260
261
#if ITK_TEMPLATE_TXX
262
# include "
itkFixedArray.txx
"
263
#endif
264
265
#include "
itkNumericTraitsFixedArrayPixel.h
"
266
267
#endif
Generated at Sat Feb 2 2013 23:38:09 for
Orfeo Toolbox
with
doxygen 1.8.1.1