Bimetric 3+1 toolkit for spherical symmetry
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Vector< T > Class Template Reference

A vector (or an array) of elements. More...

#include <matrix.h>

Collaboration diagram for Vector< T >:

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

template<class T>
typedef T Vector< T >::value_type

Makes T available externally.

Definition at line 29 of file matrix.h.


Constructor & Destructor Documentation

template<class T>
Vector< T >::Vector ( ) [inline]

Constructs the empty vector.

Definition at line 33 of file matrix.h.

        : nn( 0 )
        , v( NULL )
    {}
template<class T>
Vector< T >::~Vector ( ) [inline]

Destructs the vector, freeing allocated resources.

Definition at line 40 of file matrix.h.

    {
        if( v != NULL ) {
            delete[] v;
        }
    }
template<class T>
Vector< T >::Vector ( Int  n) [inline, explicit]

Constructs the zero-based vector.

Definition at line 49 of file matrix.h.

        : nn( n )
        , v( n > 0 ? new T[n] : NULL )
    {}
template<class T>
Vector< T >::Vector ( Int  n,
const T &  c 
) [inline]

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;
        }
    }
template<class T>
Vector< T >::Vector ( Int  n,
const T *  ap 
) [inline]

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++;
        }
    }
template<class T>
Vector< T >::Vector ( const Vector< T > &  rhs) [inline]

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

template<class T>
void Vector< T >::assign ( Int  newn,
const T &  c 
) [inline]

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;
        }
    }
template<class T>
Vector<T>& Vector< T >::operator= ( const Vector< T > &  rhs) [inline]

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]

Definition at line 107 of file matrix.h.

    {
        assertBounds( i >= 0 && i < nn, "Vector subscript out of bounds" );
        return v[i];
    }
template<class T>
const T& Vector< T >::operator[] ( const Int  i) const [inline]

Definition at line 113 of file matrix.h.

    {
        assertBounds( i >= 0 && i < nn, "Vector subscript out of bounds" );
        return v[i];
    }
template<class T>
void Vector< T >::resize ( Int  newn) [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;
        }
    }
template<class T>
Int Vector< T >::size ( ) const [inline]

Returns the size.

Definition at line 121 of file matrix.h.

                      {
        return nn;
    }

Field Documentation

template<class T>
Int Vector< T >::nn [private]

The size of the array. The upper index is nn-1.

Definition at line 25 of file matrix.h.

template<class T>
T* Vector< T >::v [private]

The elements of the array.

Definition at line 26 of file matrix.h.


The documentation for this class was generated from the following file: