Kalman::KVector< T, BEG, DBG > Class Template Reference

Minimalist vector template class. More...

#include <kvector.hpp>

List of all members.

Public Types

enum  { beg = BEG }
typedef T type
 Type of objects contained in the vector.

Public Member Functions

void assign (K_UINT_32 n, const T *v)
 Copies an array of n instances of T.
KVectoroperator= (const KVector &v)
 Copy assignment operator. Performs a deep copy.
KVectoroperator= (const T &a)
 Assigns a copy of a to all elements of the vector.
void resize (K_UINT_32 n)
 Resizes the vector. Resulting vector contents are undefined.
void swap (KVector &v)
 Constant-time swap function between two vectors.
Streaming functions

void get (std::istream &is)
 Reads a vector from a stream.
void put (std::ostream &os) const
 Writes a vector to a stream.
Constructors and destructor.

 KVector (const KVector &v)
 Copy constructor. Performs a deep copy.
 KVector (K_UINT_32 n, const T *v)
 Creates a vector from an array of n instances of T.
 KVector (K_UINT_32 n, const T &a)
 Creates a vector of n copies of a.
 KVector (K_UINT_32 n)
 Creates a vector of n default instances of T.
 KVector ()
 Default constructor. Creates an empty vector.
 ~KVector ()
 Destructor.
Member access functions.

const T & operator() (K_UINT_32 i) const
 Returns the i'th element, const version.
T & operator() (K_UINT_32 i)
 Returns the i'th element.
K_UINT_32 size () const
 Returns the vector size.

Private Attributes

K_UINT_32 n_
 Number of elements in vimpl_.
T * v_
 Pointer to start of vimpl_ array.
std::vector< T > vimpl_
 Underlying vector implementation.

Detailed Description

template<typename T, K_UINT_32 BEG, bool DBG>
class Kalman::KVector< T, BEG, DBG >

Minimalist vector template class.

This vector class does not define any fancy linear algebra functions, nor even any operator between vectors. Its sole purpose is to well encapsulate an extensible array representing a vector, and also to allow starting index to be 0 or 1.

Template parameters
  • T : Type of elements contained in the vector. Usually float or double.
  • BEG : Starting index of vector. Can be either 0 or 1.
  • DGB : Debug flag. If true, then bound-checking will be performed, and OutOfBoundError exceptions can be thrown.
Type requirements for T
  • T must be default constructible.
  • T must be assignable.
  • T must be serializable.
This means that, if t1, t2 are instances of T, is is of type istream and os is of type ostream, the following expressions must be valid :
  •  T(); T t1; 
    
    Default constructor
  •  T t1 = t2; T t1(t2); T(t1); 
    
    Copy constructor
  •  t1 = t2; 
    
    Assignment operator
  •  is >> t1; 
    
    operator>>()
  •  os << t1; 
    
    operator<<()
Finally, note that operator>>() and operator<<() must be compatible. Also, operator&() must not have been overloaded.

Definition at line 72 of file kvector.hpp.


Member Typedef Documentation

template<typename T, K_UINT_32 BEG, bool DBG>
typedef T Kalman::KVector< T, BEG, DBG >::type

Type of objects contained in the vector.

Definition at line 75 of file kvector.hpp.


Member Enumeration Documentation

template<typename T, K_UINT_32 BEG, bool DBG>
anonymous enum
Enumerator:
beg 

Starting index of vector, either 0 or 1.

Definition at line 77 of file kvector.hpp.


Constructor & Destructor Documentation

template<typename T , K_UINT_32 BEG, bool DBG>
Kalman::KVector< T, BEG, DBG >::KVector (  )  [inline]

Default constructor. Creates an empty vector.

Definition at line 89 of file kvector_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
Kalman::KVector< T, BEG, DBG >::KVector ( K_UINT_32  n  )  [inline, explicit]

Creates a vector of n default instances of T.

Parameters:
n Number of elements in vector. Can be 0.

Definition at line 95 of file kvector_impl.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
Kalman::KVector< T, BEG, DBG >::KVector ( K_UINT_32  n,
const T &  a 
) [inline]

Creates a vector of n copies of a.

Parameters:
n Number of elements in vector. Can be 0.
a Value to copy multiple times in the vector.

Definition at line 101 of file kvector_impl.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
Kalman::KVector< T, BEG, DBG >::KVector ( K_UINT_32  n,
const T *  v 
) [inline]

Creates a vector from an array of n instances of T.

This function allows to transform a C-style array of T objects in a KVector<T, BEG, DBG> equivalent array. Note that objects from the C-style array are copied into the vector, which may slow down application if used extensively.

Parameters:
n Size of the v array. Can be 0.
v Pointer to an n-size array of T objects.

Definition at line 111 of file kvector_impl.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
Kalman::KVector< T, BEG, DBG >::KVector ( const KVector< T, BEG, DBG > &  v  )  [inline]

Copy constructor. Performs a deep copy.

Parameters:
v Vector to copy. Can be an empty vector.

Definition at line 117 of file kvector_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
Kalman::KVector< T, BEG, DBG >::~KVector (  )  [inline]

Destructor.

Definition at line 122 of file kvector_impl.hpp.


Member Function Documentation

template<typename T, K_UINT_32 BEG, bool DBG>
void Kalman::KVector< T, BEG, DBG >::assign ( K_UINT_32  n,
const T *  v 
) [inline]

Copies an array of n instances of T.

Parameters:
n Size of C-style array.
v Pointer to first element to copy from C-style array.
Warning:
This function invalidates pointers inside the vector.

Definition at line 227 of file kvector_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
void Kalman::KVector< T, BEG, DBG >::get ( std::istream &  is  )  [inline]

Reads a vector from a stream.

This function will extract size() elements from a stream to fill the vector, while considering the formatting constraints of the current vector printing context.

Parameters:
is A reference to the input stream.
See also:
createKVectorContext()
selectKVectorContext()

Definition at line 251 of file kvector_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
const T & Kalman::KVector< T, BEG, DBG >::operator() ( K_UINT_32  i  )  const [inline]

Returns the i'th element, const version.

Parameters:
i Index of element to retrieve from vector.
Returns:
A const reference to the i'th element.
Exceptions:
OutOfBoundError Thrown if i is out of vector bounds and DBG == true.

Definition at line 152 of file kvector_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
T & Kalman::KVector< T, BEG, DBG >::operator() ( K_UINT_32  i  )  [inline]

Returns the i'th element.

Parameters:
i Index of element to retrieve from vector.
Returns:
A reference to the i'th element.
Exceptions:
OutOfBoundError Thrown if i is out of vector bounds and DBG == true.

Definition at line 129 of file kvector_impl.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
KVector< T, BEG, DBG > & Kalman::KVector< T, BEG, DBG >::operator= ( const KVector< T, BEG, DBG > &  v  )  [inline]

Copy assignment operator. Performs a deep copy.

Parameters:
v Vector to copy.
Returns:
A reference to the assigned vector.
Warning:
This function invalidates pointers inside the vector.

Definition at line 217 of file kvector_impl.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
KVector< T, BEG, DBG > & Kalman::KVector< T, BEG, DBG >::operator= ( const T &  a  )  [inline]

Assigns a copy of a to all elements of the vector.

Parameters:
a Instance to copy to each element of vector.
Returns:
A reference to the vector.

Definition at line 198 of file kvector_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
void Kalman::KVector< T, BEG, DBG >::put ( std::ostream &  os  )  const [inline]

Writes a vector to a stream.

This function will send all the vector elements to a stream, while considering the formatting constraints of the current vector printing context.

Parameters:
os A reference to the output stream.
See also:
createKVectorContext()
selectKVectorContext()

Definition at line 287 of file kvector_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
void Kalman::KVector< T, BEG, DBG >::resize ( K_UINT_32  n  )  [inline]

Resizes the vector. Resulting vector contents are undefined.

Parameters:
n The new size of the vector. Can be 0.
Warning:
This function may invalidates pointers inside the vector.
Note:
Resizing to a smaller size does not free any memory. To do so, one can swap the vector to shrink with a temporary copy of itself : KVector<T, BEG, DBG>(v).swap(v).

Definition at line 184 of file kvector_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
K_UINT_32 Kalman::KVector< T, BEG, DBG >::size (  )  const [inline]

Returns the vector size.

Returns:
The number of elements in the vector.

Definition at line 174 of file kvector_impl.hpp.

template<typename T , K_UINT_32 BEG, bool DBG>
void Kalman::KVector< T, BEG, DBG >::swap ( KVector< T, BEG, DBG > &  v  )  [inline]

Constant-time swap function between two vectors.

This function is fast, since it exchanges pointers to underlying implementation without copying any element.

Parameters:
v Vector to swap.
Note:
No pointer is invalidated by this function. They still point to the same element, but in the other vector.

Definition at line 238 of file kvector_impl.hpp.


Member Data Documentation

template<typename T, K_UINT_32 BEG, bool DBG>
K_UINT_32 Kalman::KVector< T, BEG, DBG >::n_ [private]

Number of elements in vimpl_.

Definition at line 152 of file kvector.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
T* Kalman::KVector< T, BEG, DBG >::v_ [private]

Pointer to start of vimpl_ array.

In fact, v_ is such that &v_[beg] == &vimpl_[0].

Warning:
This means that v_[0] is not defined for beg != 0.

Definition at line 151 of file kvector.hpp.

template<typename T, K_UINT_32 BEG, bool DBG>
std::vector<T> Kalman::KVector< T, BEG, DBG >::vimpl_ [private]

Underlying vector implementation.

Definition at line 144 of file kvector.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Defines


kfilter
Author(s): Vincent Zalzal, Sylvain Marleau, Richard Gourdeau
autogenerated on Wed Jul 23 04:33:42 2014