Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

colvarmodule::vector1d< T, length > Class Template Reference

Arbitrary size array (one dimensions) suitable for linear algebra operations (i.e. for floating point numbers it can be used with library functions). More...

#include <colvartypes.h>

List of all members.

Public Member Functions

size_t size ()
 Length of the array.
 vector1d (T const &t=T())
 Default constructor.
void reset ()
 Set all elements to zero.
 vector1d (T const *v)
 Constructor from a 1-d C array.
 vector1d (vector1d< T, length > const &v)
 Copy constructor.
vector1d< T, length > & operator= (vector1d< T, length > const &v)
 Assignment.
 ~vector1d ()
 Destructor.
T * c_array ()
 Return the 1-d C array.
 operator T * ()
 Return the 1-d C array.

Protected Attributes

T * array
 Underlying C-array.

Friends

operator * (vector1d< T, length > const &v1, vector1d< T, length > const &v2)
 Inner product.
std::ostream & operator<< (std::ostream &os, vector1d< T, length > const &v)
 Formatted output.


Detailed Description

template<class T, size_t const length>
class colvarmodule::vector1d< T, length >

Arbitrary size array (one dimensions) suitable for linear algebra operations (i.e. for floating point numbers it can be used with library functions).

Definition at line 172 of file colvartypes.h.


Constructor & Destructor Documentation

template<class T, size_t const length>
colvarmodule::vector1d< T, length >::vector1d T const &  t = T()  )  [inline]
 

Default constructor.

Definition at line 188 of file colvartypes.h.

00189   {
00190     array = new T[length];
00191     reset();
00192   }

template<class T, size_t const length>
colvarmodule::vector1d< T, length >::vector1d T const *  v  )  [inline]
 

Constructor from a 1-d C array.

Definition at line 203 of file colvartypes.h.

00204   {
00205     array = new T[length];
00206     for (size_t i = 0; i < length; i++) {
00207       array[i] = v[i];
00208     }
00209   }

template<class T, size_t const length>
colvarmodule::vector1d< T, length >::vector1d vector1d< T, length > const &  v  )  [inline]
 

Copy constructor.

Definition at line 212 of file colvartypes.h.

References colvarmodule::vector1d< T, length >::array.

00213   {
00214     array = new T[length];
00215     for (size_t i = 0; i < length; i++) {
00216       array[i] = v.array[i];
00217     }
00218   }

template<class T, size_t const length>
colvarmodule::vector1d< T, length >::~vector1d  )  [inline]
 

Destructor.

Definition at line 230 of file colvartypes.h.

00230                      {
00231     delete [] array;
00232   }


Member Function Documentation

template<class T, size_t const length>
T* colvarmodule::vector1d< T, length >::c_array  )  [inline]
 

Return the 1-d C array.

Definition at line 235 of file colvartypes.h.

00235 { return array; }

template<class T, size_t const length>
colvarmodule::vector1d< T, length >::operator T *  )  [inline]
 

Return the 1-d C array.

Definition at line 238 of file colvartypes.h.

00238 { return array; }

template<class T, size_t const length>
vector1d<T, length>& colvarmodule::vector1d< T, length >::operator= vector1d< T, length > const &  v  )  [inline]
 

Assignment.

Definition at line 221 of file colvartypes.h.

References colvarmodule::vector1d< T, length >::array.

00222   {
00223     for (size_t i = 0; i < length; i++) {
00224       this->array[i] = v.array[i];
00225     }
00226     return *this;
00227   }

template<class T, size_t const length>
void colvarmodule::vector1d< T, length >::reset  )  [inline]
 

Set all elements to zero.

Definition at line 195 of file colvartypes.h.

00196   {
00197     for (size_t i = 0; i < length; i++) {
00198       array[i] = T (0.0);
00199     }
00200   }

template<class T, size_t const length>
size_t colvarmodule::vector1d< T, length >::size  )  [inline]
 

Length of the array.

Definition at line 182 of file colvartypes.h.

00183   {
00184     return length;
00185   }


Friends And Related Function Documentation

template<class T, size_t const length>
T operator * vector1d< T, length > const &  v1,
vector1d< T, length > const &  v2
[friend]
 

Inner product.

Definition at line 241 of file colvartypes.h.

00243   {
00244     T prod (0.0);
00245     for (size_t i = 0; i < length; i++) {
00246       prod += v1.array[i] * v2.array[i];
00247     }
00248     return prod;
00249   }

template<class T, size_t const length>
std::ostream& operator<< std::ostream &  os,
vector1d< T, length > const &  v
[friend]
 

Formatted output.

Definition at line 252 of file colvartypes.h.

00254   {
00255     std::streamsize const w = os.width();
00256     std::streamsize const p = os.precision();
00257 
00258     os << "( ";
00259     for (size_t i = 0; i < length-1; i++) {
00260       os.width (w); os.precision (p);
00261       os << v.array[i] << " , ";
00262     }
00263     os.width (w); os.precision (p);
00264     os << v.array[length-1] << " )";
00265     return os;
00266   }


Member Data Documentation

template<class T, size_t const length>
T* colvarmodule::vector1d< T, length >::array [protected]
 

Underlying C-array.

Definition at line 177 of file colvartypes.h.

Referenced by colvarmodule::vector1d< T, length >::operator=(), and colvarmodule::vector1d< T, length >::vector1d().


The documentation for this class was generated from the following file:
Generated on Tue Nov 24 04:07:48 2009 for NAMD by  doxygen 1.3.9.1