Edinburgh Speech Tools  2.1-release
EST_TVector< T > Class Template Reference

Template vector. More...

#include <include/EST_TVector.h>

Inheritance diagram for EST_TVector< T >:
Collaboration diagram for EST_TVector< T >:

Public Member Functions

INLINE ssize_t vcell_pos (ssize_t c, ssize_t cs) const
 The memory access rule, in one place for easy reference. More...
 
INLINE ssize_t vcell_pos (ssize_t c) const
 
INLINE ssize_t vcell_pos_1 (ssize_t c) const
 
INLINE const T & fast_a_v (int c) const
 quick method for returning (x[n]) More...
 
INLINE T & fast_a_v (int c)
 
INLINE const T & fast_a_1 (int c) const
 
INLINE T & fast_a_1 (int c)
 
void set_values (const T *data, int step, int start_c, int num_c)
 Get and set values from array. More...
 
void get_values (T *data, int step, int start_c, int num_c) const
 
void copy (const EST_TVector< T > &a)
 private copy function, called from all other copying functions. More...
 
void copy_data (const EST_TVector< T > &a)
 just copy data, no resizing, no size check. More...
 
void just_resize (int new_cols, T **old_vals)
 resize the memory and reset the bounds, but don't set values. More...
 
void default_vals ()
 sets data and length to default values (0 in both cases). More...
 
 EST_TVector ()
 default constructor More...
 
 EST_TVector (const EST_TVector< T > &v)
 copy constructor More...
 
 EST_TVector (ssize_t n)
 "size" constructor - make vector of size n. More...
 
 EST_TVector (int, T *memory, int offset=0, int free_when_destroyed=0)
 construct from memory supplied by caller More...
 
 ~EST_TVector ()
 destructor. More...
 
void resize (ssize_t n, int set=1)
 
const T * memory () const
 
T * memory ()
 
void set_memory (T *buffer, int offset, ssize_t columns, int free_when_destroyed=0)
 
EST_TVectoroperator= (const EST_TVector &s)
 assignment operator More...
 
void fill (const T &v)
 Fill entire array will value v. More...
 
void empty ()
 Fill vector with default value. More...
 
int operator== (const EST_TVector &v) const
 is true if vectors are equal size and all elements are equal. More...
 
int operator!= (const EST_TVector &v) const
 is true if vectors are not equal size or a single elements isn't equal. More...
 
void copy_section (T *dest, int offset=0, int num=-1) const
 Copy data in and out. Subclassed by SimpleVector for speed. More...
 
void set_section (const T *src, int offset=0, int num=-1)
 
void sub_vector (EST_TVector< T > &sv, int start_c=0, int len=-1)
 Create a sub vector. More...
 
void integrity () const
 
template<>
const EST_DMatrixdef_val
 
template<>
EST_DMatrixerror_return
 
template<>
const EST_DVectordef_val
 
template<>
EST_DVectorerror_return
 
template<>
const EST_FMatrixdef_val
 
template<>
EST_FMatrixerror_return
 
Access

Basic access methods for vectors.

INLINE ssize_t num_columns () const
 number of items in vector. More...
 
INLINE ssize_t length () const
 number of items in vector. More...
 
INLINE ssize_t n () const
 number of items in vector. More...
 
INLINE const T & a_no_check (ssize_t n) const
 read-only const access operator: without bounds checking More...
 
INLINE T & a_no_check (ssize_t n)
 read/write non-const access operator: without bounds checking More...
 
INLINE const T & a_no_check_1 (ssize_t n) const
 read-only const access operator: without bounds checking More...
 
INLINE T & a_no_check_1 (ssize_t n)
 read/write non-const access operator: without bounds checking More...
 
const T & a_check (ssize_t n) const
 read-only const access operator: with bounds checking More...
 
T & a_check (ssize_t n)
 read/write non-const access operator: with bounds checking More...
 
const T & a (ssize_t n) const
 
T & a (ssize_t n)
 
const T & operator() (ssize_t n) const
 read-only const access operator: return reference to nth member More...
 
T & operator[] (ssize_t n)
 read/write non const access operator: return reference to nth member More...
 

Public Attributes

T * p_memory
 
ssize_t p_num_columns
 Visible shape. More...
 
ssize_t p_offset
 How to access the memory. More...
 
ssize_t p_column_step
 
bool p_sub_matrix
 

Static Public Attributes

static const T * def_val = &def_val_item_ptr
 default value, used for filling matrix after resizing More...
 
static T * error_return = &error_return_item_ptr
 

Friends

class EST_TMatrix< T >
 Matrix must be friend to set up subvectors. More...
 
std::ostream & operator<< (std::ostream &st, const EST_TVector< T > &m)
 print out vector. More...
 

Detailed Description

template<class T>
class EST_TVector< T >

Template vector.

Template Parameters
TType of vector elements

This serves as a base class for a vector of type T. This acts as a higher level version of a normal C array as defined as float *x, etc.

The vector can be resized after declaration, access can be with or without bounds checking. Round brackets denote read-only access (for consts) while square brackets are for read-write access. In both cases references are returned.

The standard operators () and [] should be thought of as having no bounds checking, though they may do so optionally as a compile time option. The methods EST_TVector::a_check and EST_TVector::a_nocheck provide explicit boundary checking/nonchecking, both const and non-const versions are provided.

Access through () and [] are guaranteed to be as fast as standard C arrays (assuming a reasonable optimizing compiler).

int i;
for (i=0; i < x.length(); ++i)
x[i] = sqrt((float)i);
x.resize(20);
for (i=10; i < x.length(); ++i)
x[i] = sqrt((float)i);

To instantiate a template for a a vector of type FooBar

#include "../base_class/EST_TVector.cc"
// If you want List to vector conversion (and defined a TList)
#include "../base_class/EST_Tvectlist.cc"
template class EST_TVector<FooBar>;
template std::ostream& operator <<
(std::ostream &st, const EST_TVector<FooBar> &v);

The EST library already has template vector instantiations for int, float, double and EST_String. Also types are defined for them in EST_types.h as EST_IVector, EST_FVector, EST_DVector and EST_StrVector for ints, floats, doubless and EST_String respectively.

See also
matrix_example

Definition at line 145 of file EST_TVector.h.

Constructor & Destructor Documentation

template<class T >
EST_TVector< T >::EST_TVector ( )

default constructor

Definition at line 61 of file EST_TVector.cc.

template<class T>
EST_TVector< T >::EST_TVector ( const EST_TVector< T > &  v)

copy constructor

Definition at line 74 of file EST_TVector.cc.

template<class T>
EST_TVector< T >::EST_TVector ( ssize_t  n)

"size" constructor - make vector of size n.

Definition at line 67 of file EST_TVector.cc.

template<class T>
EST_TVector< T >::EST_TVector ( int  n,
T *  memory,
int  offset = 0,
int  free_when_destroyed = 0 
)

construct from memory supplied by caller

Definition at line 81 of file EST_TVector.cc.

template<class T >
EST_TVector< T >::~EST_TVector ( )

destructor.

Definition at line 90 of file EST_TVector.cc.

Member Function Documentation

template<class T>
INLINE ssize_t EST_TVector< T >::vcell_pos ( ssize_t  c,
ssize_t  cs 
) const
inline

The memory access rule, in one place for easy reference.

Definition at line 165 of file EST_TVector.h.

template<class T>
INLINE ssize_t EST_TVector< T >::vcell_pos ( ssize_t  c) const
inline

Definition at line 168 of file EST_TVector.h.

template<class T>
INLINE ssize_t EST_TVector< T >::vcell_pos_1 ( ssize_t  c) const
inline

Definition at line 174 of file EST_TVector.h.

template<class T>
INLINE const T& EST_TVector< T >::fast_a_v ( int  c) const
inline

quick method for returning (x[n])

Definition at line 180 of file EST_TVector.h.

template<class T>
INLINE T& EST_TVector< T >::fast_a_v ( int  c)
inline

Definition at line 182 of file EST_TVector.h.

template<class T>
INLINE const T& EST_TVector< T >::fast_a_1 ( int  c) const
inline

Definition at line 184 of file EST_TVector.h.

template<class T>
INLINE T& EST_TVector< T >::fast_a_1 ( int  c)
inline

Definition at line 185 of file EST_TVector.h.

template<class T>
void EST_TVector< T >::set_values ( const T *  data,
int  step,
int  start_c,
int  num_c 
)

Get and set values from array.

Definition at line 126 of file EST_TVector.cc.

template<class T>
void EST_TVector< T >::get_values ( T *  data,
int  step,
int  start_c,
int  num_c 
) const

Definition at line 137 of file EST_TVector.cc.

template<class T>
void EST_TVector< T >::copy ( const EST_TVector< T > &  a)

private copy function, called from all other copying functions.

Definition at line 154 of file EST_TVector.cc.

template<class T>
void EST_TVector< T >::copy_data ( const EST_TVector< T > &  a)

just copy data, no resizing, no size check.

Definition at line 148 of file EST_TVector.cc.

template<class T>
void EST_TVector< T >::just_resize ( int  new_cols,
T **  old_vals 
)

resize the memory and reset the bounds, but don't set values.

Definition at line 161 of file EST_TVector.cc.

template<class T >
void EST_TVector< T >::default_vals ( void  )

sets data and length to default values (0 in both cases).

Definition at line 50 of file EST_TVector.cc.

template<class T >
void EST_TVector< T >::resize ( ssize_t  n,
int  set = 1 
)

resize vector. If set=1, then the current values in the vector are preserved up to the new length n. If the new length exceeds the old length, the rest of the vector is filled with the def_val

Definition at line 196 of file EST_TVector.cc.

template<class T>
const T* EST_TVector< T >::memory ( ) const
inline

For when you absolutely have to have access to the memory.

Definition at line 238 of file EST_TVector.h.

template<class T>
T* EST_TVector< T >::memory ( )
inline

Definition at line 239 of file EST_TVector.h.

template<class T>
INLINE ssize_t EST_TVector< T >::num_columns ( ) const
inline

number of items in vector.

Definition at line 247 of file EST_TVector.h.

template<class T>
INLINE ssize_t EST_TVector< T >::length ( void  ) const
inline

number of items in vector.

Definition at line 249 of file EST_TVector.h.

template<class T>
INLINE ssize_t EST_TVector< T >::n ( void  ) const
inline

number of items in vector.

Definition at line 251 of file EST_TVector.h.

template<class T>
INLINE const T& EST_TVector< T >::a_no_check ( ssize_t  n) const
inline

read-only const access operator: without bounds checking

Definition at line 254 of file EST_TVector.h.

template<class T>
INLINE T& EST_TVector< T >::a_no_check ( ssize_t  n)
inline

read/write non-const access operator: without bounds checking

Definition at line 256 of file EST_TVector.h.

template<class T>
INLINE const T& EST_TVector< T >::a_no_check_1 ( ssize_t  n) const
inline

read-only const access operator: without bounds checking

Definition at line 258 of file EST_TVector.h.

template<class T>
INLINE T& EST_TVector< T >::a_no_check_1 ( ssize_t  n)
inline

read/write non-const access operator: without bounds checking

Definition at line 260 of file EST_TVector.h.

template<class T >
const T & EST_TVector< T >::a_check ( ssize_t  n) const

read-only const access operator: with bounds checking

Definition at line 249 of file EST_TVector.cc.

template<class T >
T & EST_TVector< T >::a_check ( ssize_t  n)

read/write non-const access operator: with bounds checking

Definition at line 240 of file EST_TVector.cc.

template<class T>
const T& EST_TVector< T >::a ( ssize_t  n) const
inline

Definition at line 269 of file EST_TVector.h.

template<class T>
T& EST_TVector< T >::a ( ssize_t  n)
inline

Definition at line 270 of file EST_TVector.h.

template<class T>
const T& EST_TVector< T >::operator() ( ssize_t  n) const
inline

read-only const access operator: return reference to nth member

Definition at line 273 of file EST_TVector.h.

template<class T>
T& EST_TVector< T >::operator[] ( ssize_t  n)
inline

read/write non const access operator: return reference to nth member

Definition at line 280 of file EST_TVector.h.

template<class T>
void EST_TVector< T >::set_memory ( T *  buffer,
int  offset,
ssize_t  columns,
int  free_when_destroyed = 0 
)

Definition at line 112 of file EST_TVector.cc.

template<class T >
EST_TVector< T > & EST_TVector< T >::operator= ( const EST_TVector< T > &  s)

assignment operator

Definition at line 233 of file EST_TVector.cc.

template<class T>
void EST_TVector< T >::fill ( const T &  v)

Fill entire array will value v.

Definition at line 105 of file EST_TVector.cc.

template<class T>
void EST_TVector< T >::empty ( )
inline

Fill vector with default value.

Definition at line 294 of file EST_TVector.h.

template<class T >
int EST_TVector< T >::operator== ( const EST_TVector< T > &  v) const

is true if vectors are equal size and all elements are equal.

Definition at line 255 of file EST_TVector.cc.

template<class T>
int EST_TVector< T >::operator!= ( const EST_TVector< T > &  v) const
inline

is true if vectors are not equal size or a single elements isn't equal.

Definition at line 299 of file EST_TVector.h.

template<class T>
void EST_TVector< T >::copy_section ( T *  dest,
int  offset = 0,
int  num = -1 
) const

Copy data in and out. Subclassed by SimpleVector for speed.

Definition at line 271 of file EST_TVector.cc.

template<class T>
void EST_TVector< T >::set_section ( const T *  src,
int  offset = 0,
int  num = -1 
)

Definition at line 285 of file EST_TVector.cc.

template<class T>
void EST_TVector< T >::sub_vector ( EST_TVector< T > &  sv,
int  start_c = 0,
int  len = -1 
)

Create a sub vector.

Definition at line 298 of file EST_TVector.cc.

template<class T >
void EST_TVector< T >::integrity ( ) const

Definition at line 315 of file EST_TVector.cc.

template<>
const EST_DMatrix * EST_TVector< EST_DMatrix >::def_val ( )

Definition at line 45 of file vector_dmatrix_t.cc.

template<>
EST_DMatrix * EST_TVector< EST_DMatrix >::error_return ( )

Definition at line 46 of file vector_dmatrix_t.cc.

template<>
const EST_DVector * EST_TVector< EST_DVector >::def_val ( )

Definition at line 45 of file vector_dvector_t.cc.

template<>
EST_DVector * EST_TVector< EST_DVector >::error_return ( )

Definition at line 46 of file vector_dvector_t.cc.

template<>
const EST_FMatrix * EST_TVector< EST_FMatrix >::def_val ( )

Definition at line 45 of file vector_fmatrix_t.cc.

template<>
EST_FMatrix * EST_TVector< EST_FMatrix >::error_return ( )

Definition at line 46 of file vector_fmatrix_t.cc.

Friends And Related Function Documentation

template<class T>
friend class EST_TMatrix< T >
friend

Matrix must be friend to set up subvectors.

Definition at line 320 of file EST_TVector.h.

template<class T>
std::ostream& operator<< ( std::ostream &  st,
const EST_TVector< T > &  m 
)
friend

print out vector.

Definition at line 310 of file EST_TVector.h.

Member Data Documentation

template<class T>
T* EST_TVector< T >::p_memory

Pointer to the start of the vector. The start of allocated memory is p_memory-p_offset.

Definition at line 152 of file EST_TVector.h.

template<class T>
ssize_t EST_TVector< T >::p_num_columns

Visible shape.

Definition at line 155 of file EST_TVector.h.

template<class T>
ssize_t EST_TVector< T >::p_offset

How to access the memory.

Definition at line 158 of file EST_TVector.h.

template<class T>
ssize_t EST_TVector< T >::p_column_step

Definition at line 159 of file EST_TVector.h.

template<class T>
bool EST_TVector< T >::p_sub_matrix

Definition at line 161 of file EST_TVector.h.

template<class T>
EST_Item *const * EST_Item_ptr_Vector::def_val = &def_val_item_ptr
static

default value, used for filling matrix after resizing

Definition at line 220 of file EST_TVector.h.

template<class T>
EST_Item ** EST_Item_ptr_Vector::error_return = &error_return_item_ptr
static

A reference to this variable is returned if you try and access beyond the bounds of the matrix. The value is undefined, but you can check for the reference you get having the same address as this variable to test for an error.

Definition at line 227 of file EST_TVector.h.


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