A vector (or an array) of elements.
More...
#include <matrix.h>
Public Types |
typedef T | value_type |
| Makes T available externally.
|
Public Member Functions |
| Vector () |
| Constructs the empty vector.
|
| ~Vector () |
| Destructs the vector, freeing allocated resources.
|
| Vector (Int n) |
| Constructs the zero-based vector.
|
| Vector (Int n, const T &c) |
| Constructs the vector initialized to a constant value.
|
| Vector (Int n, const T *ap) |
| Constructs the vector from an array.
|
| Vector (const Vector< T > &rhs) |
Vector< T > & | operator= (const Vector< T > &rhs) |
| Assigns an existing vector.
|
T & | operator[] (const Int i) |
const T & | operator[] (const Int i) const |
Int | size () const |
| Returns the size.
|
void | resize (Int newn) |
| Resize the array.
|
void | assign (Int newn, const T &c) |
| Resize and assign a constant value.
|
Private Attributes |
Int | nn |
| The size of the array. The upper index is nn-1 .
|
T * | v |
| The elements of the array.
|
Detailed Description
template<class T>
class Vector< T >
A vector (or an array) of elements.
Definition at line 23 of file matrix.h.
Member Typedef Documentation
Makes T
available externally.
Definition at line 29 of file matrix.h.
Constructor & Destructor Documentation
Constructs the empty vector.
Definition at line 33 of file matrix.h.
Destructs the vector, freeing allocated resources.
Definition at line 40 of file matrix.h.
{
if( v != NULL ) {
delete[] v;
}
}
Constructs the zero-based vector.
Definition at line 49 of file matrix.h.
: nn( n )
, v( n > 0 ? new T[n] : NULL )
{}
Constructs the vector initialized to a constant value.
Definition at line 56 of file matrix.h.
: nn( n )
, v( n>0 ? new T[n] : NULL )
{
for( Int i = 0; i < n; ++i ) {
v[i] = c;
}
}
Constructs the vector from an array.
Definition at line 67 of file matrix.h.
: nn( n )
, v( n > 0 ? new T[n] : NULL )
{
for( Int i = 0; i < n; ++i ) {
v[i] = *ap++;
}
}
Definition at line 76 of file matrix.h.
: nn( rhs.nn )
, v( nn > 0 ? new T[nn] : NULL )
{
for( Int i = 0; i < nn; ++i ) {
v[i] = rhs[i];
}
}
Member Function Documentation
Resize and assign a constant value.
Definition at line 141 of file matrix.h.
{
if( newn != nn ) {
if( v != NULL ) {
delete[] v;
}
nn = newn;
v = nn > 0 ? new T[nn] : NULL;
}
for( Int i = 0; i < nn; ++i ) {
v[i] = c;
}
}
Assigns an existing vector.
Postcondition: normal assignment via copying has been performed; if vector and rhs were different sizes, vector has been resized to match the size of rhs.
Definition at line 89 of file matrix.h.
{
if( this != &rhs )
{
if( nn != rhs.nn ) {
if( v != NULL ) {
delete[] v;
}
nn = rhs.nn;
v= nn > 0 ? new T[nn] : NULL;
}
for( Int i = 0; i < nn; ++i ) {
v[i] = rhs[i];
}
}
return *this;
}
template<class T>
T& Vector< T >::operator[] |
( |
const Int |
i | ) |
[inline] |
template<class T>
const T& Vector< T >::operator[] |
( |
const Int |
i | ) |
const [inline] |
Resize the array.
Definition at line 127 of file matrix.h.
{
if( newn != nn )
{
if( v != NULL ) {
delete[] v;
}
nn = newn;
v = nn > 0 ? new T[nn] : NULL;
}
}
Returns the size.
Definition at line 121 of file matrix.h.
Field Documentation
The size of the array. The upper index is nn-1
.
Definition at line 25 of file matrix.h.
The elements of the array.
Definition at line 26 of file matrix.h.
The documentation for this class was generated from the following file: