Overture
Version 25
Main Page
Namespaces
Classes
Files
File List
File Members
Overture.v25.d
include
VectorSimple.h
Go to the documentation of this file.
1
#ifndef __VECTOR_SIMPLE_H__
2
#define __VECTOR_SIMPLE_H__
3
4
#include "
ArraySimpleCommon.h
"
5
6
// // //
8
12
template
<
class
T>
13
class
VectorSimple
14
{
15
16
public
:
18
20
inline
VectorSimple
() : data(0), nsize(0) { }
21
23
26
inline
EXPLICIT
VectorSimple
(
const
int
&
s
)
27
{
28
nsize =
s
;
29
data =
new
T[
s
];
30
}
31
33
37
inline
VectorSimple
(
const
VectorSimple<T>
&a ) : data(0), nsize(0)
38
{
39
if
( nsize != a.
size
() )
40
{
41
if
( data!=0 )
delete
[] data;
42
data =
new
T[a.
size
()];
43
}
44
45
nsize = a.nsize;
46
for
(
int
s
=0;
s
<nsize;
s
++ )
47
data[
s
] = a[
s
];
48
}
49
51
inline
~VectorSimple
()
52
{
53
if
( data!=0 )
delete
[] data;
54
55
data = 0;
56
nsize = 0;
57
}
58
60
62
inline
int
size
()
const
63
{
64
return
nsize;
65
}
66
68
71
inline
T *
ptr
()
72
{
73
return
data;
74
}
75
77
81
inline
VectorSimple<T>
&
operator=
(
const
VectorSimple<T>
&a )
82
{
83
if
( nsize != a.
size
() )
84
{
85
if
( data!=0 )
delete
[] data;
86
data =
new
T[a.
size
()];
87
}
88
89
nsize = a.nsize;
90
for
(
int
s
=0;
s
<nsize;
s
++ )
91
data[
s
] = a[
s
];
92
93
return
*
this
;
94
}
95
inline
VectorSimple<T>
&
operator=
(
const
T &a )
96
{
97
for
(
int
s
=0;
s
<nsize;
s
++ )
98
data[
s
] = a;
99
100
return
*
this
;
101
}
102
104
107
inline
T &
operator()
(
const
int
&i )
108
{
109
assert
(
RANGE_CHK
(i>=0 && i<nsize));
110
return
data[i];
111
}
112
114
117
inline
const
T &
operator()
(
const
int
&i )
const
118
{
119
assert
(
RANGE_CHK
(i>=0 && i<nsize));
120
return
data[i];
121
}
122
124
128
inline
T &
operator[]
(
const
int
&i )
129
{
130
assert
(
RANGE_CHK
(i>=0 && i<nsize));
131
return
data[i];
132
}
133
135
139
inline
const
T &
operator[]
(
const
int
&i )
const
140
{
141
assert
(
RANGE_CHK
(i>=0 && i<nsize));
142
return
data[i];
143
}
144
145
private
:
146
T *data;
147
int
nsize;
148
};
149
150
template
<
class
T>
151
ostream & operator<< (ostream &os, VectorSimple<T> &a)
152
{
153
// /Description : overloading of ostream to make printing VectorSimples easier
154
155
os<<
"********** VectorSimple[ "
<<a.size()<<
" ]\n"
;
156
157
for
(
int
i=0; i<a.size(); i++ )
158
os<<
"a( "
<<i<<
" ) = "
<<a[i]<<endl;
159
160
return
os;
161
}
162
163
#endif
Generated on Fri Jan 4 2013 10:18:01 for Overture by
1.8.3