Minimalist vector template class. More...
#include <kvector.hpp>
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 . | |
KVector & | operator= (const KVector &v) |
Copy assignment operator. Performs a deep copy. | |
KVector & | operator= (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. |
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.
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.T
must be default constructible.T
must be assignable.T
must be serializable.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;
T t1 = t2; T t1(t2); T(t1);
t1 = t2;
is >> t1;
operator>>()
os << t1;
operator<<()
operator>>()
and operator<<()
must be compatible. Also, operator&()
must not have been overloaded. Definition at line 72 of file kvector.hpp.
typedef T Kalman::KVector< T, BEG, DBG >::type |
Type of objects contained in the vector.
Definition at line 75 of file kvector.hpp.
anonymous enum |
Definition at line 77 of file kvector.hpp.
Kalman::KVector< T, BEG, DBG >::KVector | ( | ) | [inline] |
Default constructor. Creates an empty vector.
Definition at line 89 of file kvector_impl.hpp.
Kalman::KVector< T, BEG, DBG >::KVector | ( | K_UINT_32 | n | ) | [inline, explicit] |
Creates a vector of n
default instances of T
.
n | Number of elements in vector. Can be 0. |
Definition at line 95 of file kvector_impl.hpp.
Kalman::KVector< T, BEG, DBG >::KVector | ( | K_UINT_32 | n, | |
const T & | a | |||
) | [inline] |
Creates a vector of n
copies of a
.
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.
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.
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.
Kalman::KVector< T, BEG, DBG >::KVector | ( | const KVector< T, BEG, DBG > & | v | ) | [inline] |
Copy constructor. Performs a deep copy.
v | Vector to copy. Can be an empty vector. |
Definition at line 117 of file kvector_impl.hpp.
Kalman::KVector< T, BEG, DBG >::~KVector | ( | ) | [inline] |
Destructor.
Definition at line 122 of file kvector_impl.hpp.
void Kalman::KVector< T, BEG, DBG >::assign | ( | K_UINT_32 | n, | |
const T * | v | |||
) | [inline] |
Copies an array of n
instances of T
.
n | Size of C-style array. | |
v | Pointer to first element to copy from C-style array. |
Definition at line 227 of file kvector_impl.hpp.
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.
is | A reference to the input stream. |
Definition at line 251 of file kvector_impl.hpp.
const T & Kalman::KVector< T, BEG, DBG >::operator() | ( | K_UINT_32 | i | ) | const [inline] |
Returns the i'th
element, const
version.
i | Index of element to retrieve from vector. |
const
reference to the i'th
element. OutOfBoundError | Thrown if i is out of vector bounds and DBG == true . |
Definition at line 152 of file kvector_impl.hpp.
T & Kalman::KVector< T, BEG, DBG >::operator() | ( | K_UINT_32 | i | ) | [inline] |
Returns the i'th
element.
i | Index of element to retrieve from vector. |
i'th
element. OutOfBoundError | Thrown if i is out of vector bounds and DBG == true . |
Definition at line 129 of file kvector_impl.hpp.
KVector< T, BEG, DBG > & Kalman::KVector< T, BEG, DBG >::operator= | ( | const KVector< T, BEG, DBG > & | v | ) | [inline] |
Copy assignment operator. Performs a deep copy.
v | Vector to copy. |
Definition at line 217 of file kvector_impl.hpp.
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.
a | Instance to copy to each element of vector. |
Definition at line 198 of file kvector_impl.hpp.
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.
os | A reference to the output stream. |
Definition at line 287 of file kvector_impl.hpp.
void Kalman::KVector< T, BEG, DBG >::resize | ( | K_UINT_32 | n | ) | [inline] |
Resizes the vector. Resulting vector contents are undefined.
n | The new size of the vector. Can be 0. |
KVector<T, BEG, DBG>(v).swap(v)
. Definition at line 184 of file kvector_impl.hpp.
K_UINT_32 Kalman::KVector< T, BEG, DBG >::size | ( | ) | const [inline] |
Returns the vector size.
Definition at line 174 of file kvector_impl.hpp.
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.
v | Vector to swap. |
Definition at line 238 of file kvector_impl.hpp.
K_UINT_32 Kalman::KVector< T, BEG, DBG >::n_ [private] |
Number of elements in vimpl_.
Definition at line 152 of file kvector.hpp.
T* Kalman::KVector< T, BEG, DBG >::v_ [private] |
Pointer to start of vimpl_ array.
In fact, v_ is such that &v_[beg] == &vimpl_[0]
.
v_[0]
is not defined for beg != 0
. Definition at line 151 of file kvector.hpp.
std::vector<T> Kalman::KVector< T, BEG, DBG >::vimpl_ [private] |
Underlying vector implementation.
Definition at line 144 of file kvector.hpp.