mdds
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
mdds::multi_type_matrix< _StringTrait > Class Template Reference

#include <multi_type_matrix.hpp>

Classes

struct  element_block_node_type
 
struct  size_pair_type
 
struct  walk_func
 

Public Types

typedef string_trait::string_type string_type
 
typedef size_t size_type
 
typedef store_type::position_type position_type
 
typedef store_type::const_position_type const_position_type
 
typedef store_type::element_block_type element_block_type
 
typedef mtv::boolean_element_block boolean_block_type
 
typedef mtv::numeric_element_block numeric_block_type
 
typedef string_trait::string_element_block string_block_type
 

Public Member Functions

 multi_type_matrix ()
 
 multi_type_matrix (size_type rows, size_type cols)
 
template<typename _T >
 multi_type_matrix (size_type rows, size_type cols, const _T &value)
 
template<typename _T >
 multi_type_matrix (size_type rows, size_type cols, const _T &it_begin, const _T &it_end)
 
 multi_type_matrix (const multi_type_matrix &r)
 
bool operator== (const multi_type_matrix &other) const
 
bool operator!= (const multi_type_matrix &other) const
 
multi_type_matrixoperator= (const multi_type_matrix &r)
 
position_type position (size_type row, size_type col)
 
position_type position (const position_type &pos_hint, size_type row, size_type col)
 
const_position_type position (size_type row, size_type col) const
 
const_position_type position (const const_position_type &pos_hint, size_type row, size_type col) const
 
size_pair_type matrix_position (const const_position_type &pos)
 
position_type end_position ()
 
const_position_type end_position () const
 
mtm::element_t get_type (const const_position_type &pos) const
 
mtm::element_t get_type (size_type row, size_type col) const
 
double get_numeric (size_type row, size_type col) const
 
double get_numeric (const const_position_type &pos) const
 
bool get_boolean (size_type row, size_type col) const
 
bool get_boolean (const const_position_type &pos) const
 
const string_type & get_string (size_type row, size_type col) const
 
const string_type & get_string (const const_position_type &pos) const
 
template<typename _T >
_T get (size_type row, size_type col) const
 
void set_empty (size_type row, size_type col)
 
void set_empty (size_type row, size_type col, size_type length)
 
position_type set_empty (const position_type &pos)
 
void set_column_empty (size_type col)
 
void set_row_empty (size_type row)
 
void set (size_type row, size_type col, double val)
 
position_type set (const position_type &pos, double val)
 
void set (size_type row, size_type col, bool val)
 
position_type set (const position_type &pos, bool val)
 
void set (size_type row, size_type col, const string_type &str)
 
position_type set (const position_type &pos, const string_type &str)
 
template<typename _T >
void set (size_type row, size_type col, const _T &it_begin, const _T &it_end)
 
template<typename _T >
position_type set (const position_type &pos, const _T &it_begin, const _T &it_end)
 
template<typename _T >
void set_column (size_type col, const _T &it_begin, const _T &it_end)
 
size_pair_type size () const
 
multi_type_matrixtranspose ()
 
void copy (const multi_type_matrix &r)
 
void resize (size_type rows, size_type cols)
 
template<typename _T >
void resize (size_type rows, size_type cols, const _T &value)
 
void clear ()
 
bool numeric () const
 
bool empty () const
 
void swap (multi_type_matrix &r)
 
template<typename _Func >
void walk (_Func &func) const
 
template<typename _Func >
void walk (_Func &func, const size_pair_type &start, const size_pair_type &end) const
 

Static Public Member Functions

static mtm::element_t to_mtm_type (mdds::mtv::element_t mtv_type)
 
static position_type next_position (const position_type &pos)
 
static const_position_type next_position (const const_position_type &pos)
 

Detailed Description

template<typename _StringTrait>
class mdds::multi_type_matrix< _StringTrait >

Matrix that can store double, bool, empty and string types. The string type is specified by the string trait template parameter. To use std::string as the string type, use mdds::mtm::std_string_trait.

Constructor & Destructor Documentation

template<typename _StringTrait >
mdds::multi_type_matrix< _StringTrait >::multi_type_matrix ( )

Default constructor.

template<typename _StringTrait >
mdds::multi_type_matrix< _StringTrait >::multi_type_matrix ( size_type  rows,
size_type  cols 
)

Construct a matrix of specified size with specified density type.

Member Function Documentation

template<typename _StringTrait >
void mdds::multi_type_matrix< _StringTrait >::clear ( )

Empty the matrix.

template<typename _StringTrait >
void mdds::multi_type_matrix< _StringTrait >::copy ( const multi_type_matrix< _StringTrait > &  r)

Copy values from the passed matrix instance. If the size of the passed matrix is smaller, then the element values are copied by their positions, while the rest of the elements that fall outside the size of the passed matrix instance will remain unmodified. If the size of the passed matrix instance is larger, then only the elements within the size of this matrix instance will get copied.

Parameters
rpassed matrix object to copy element values from.
template<typename _StringTrait >
bool mdds::multi_type_matrix< _StringTrait >::empty ( ) const

Check whether or not this matrix is empty.

Returns
true if this matrix is empty, or false otherwise.
template<typename _StringTrait >
position_type mdds::multi_type_matrix< _StringTrait >::end_position ( )

Return a position type that represents an end position. This can be used to compare with another position object to see if it is past the last element position.

Returns
end position object
template<typename _StringTrait >
const_position_type mdds::multi_type_matrix< _StringTrait >::end_position ( ) const

Return a position type that represents an end position. This can be used to compare with another position object to see if it is past the last element position.

Returns
end position object
template<typename _StringTrait >
template<typename _T >
_T mdds::multi_type_matrix< _StringTrait >::get ( size_type  row,
size_type  col 
) const

Get the value of element at specified position. The caller must explicitly specify the return type. If the element is not of the specified type, it throws an exception.

Parameters
rowrow position of the element.
colcolumn position of the element.
Returns
value of the element.
template<typename _StringTrait >
bool mdds::multi_type_matrix< _StringTrait >::get_boolean ( size_type  row,
size_type  col 
) const

Get a boolean representation of the element. If the element is of numeric type, true is returned if it's non-zero, otherwise false is returned. If it's of boolean type, its value is returned. If it's of empty or string type, false is returned.

Parameters
rowrow position of the element.
colcolumn position of the element.
Returns
boolean representation of the element.
template<typename _StringTrait >
bool mdds::multi_type_matrix< _StringTrait >::get_boolean ( const const_position_type &  pos) const

Get a boolean representation of the element from a position object. If the element is of numeric type, true is returned if it's non-zero, otherwise false is returned. If it's of boolean type, its value is returned. If it's of empty or string type, false is returned.

Parameters
posposition object of an element
Returns
boolean representation of the element.
template<typename _StringTrait >
double mdds::multi_type_matrix< _StringTrait >::get_numeric ( size_type  row,
size_type  col 
) const

Get a numeric representation of the element. If the element is of numeric type, its value is returned. If it's of boolean type, either 1 or 0 is returned depending on whether it's true or false. If it's of empty or string type, 0 is returned.

Parameters
rowrow position of the element.
colcolumn position of the element.
Returns
numeric representation of the element.
template<typename _StringTrait >
double mdds::multi_type_matrix< _StringTrait >::get_numeric ( const const_position_type &  pos) const

Get a numeric representation of the element from a position object. If the element is of numeric type, its value is returned. If it's of boolean type, either 1 or 0 is returned depending on whether it's true or false. If it's of empty or string type, 0 is returned.

Parameters
posposition object of an element
Returns
numeric representation of the element.
template<typename _StringTrait >
const string_type& mdds::multi_type_matrix< _StringTrait >::get_string ( size_type  row,
size_type  col 
) const

Get the value of a string element. If the element is not of string type, it throws an exception.

Parameters
rowrow position of the element.
colcolumn position of the element.
Returns
value of the element.
template<typename _StringTrait >
const string_type& mdds::multi_type_matrix< _StringTrait >::get_string ( const const_position_type &  pos) const

Get the value of a string element from a position object. If the element is not of string type, it throws an exception.

Parameters
posposition object of an element
Returns
value of the element.
template<typename _StringTrait >
mtm::element_t mdds::multi_type_matrix< _StringTrait >::get_type ( const const_position_type &  pos) const

Get the type of element from a position object. The type can be one of empty, string, numeric, or boolean.

Parameters
posposition object of an element
Returns
element type.
template<typename _StringTrait >
mtm::element_t mdds::multi_type_matrix< _StringTrait >::get_type ( size_type  row,
size_type  col 
) const

Get the type of element specified by its position. The type can be one of empty, string, numeric, or boolean.

Returns
element type.
template<typename _StringTrait >
size_pair_type mdds::multi_type_matrix< _StringTrait >::matrix_position ( const const_position_type &  pos)

Get the row and column positions of the current element from a position object.

Parameters
posposition object.
Returns
0-based row and column positions.
template<typename _StringTrait >
static position_type mdds::multi_type_matrix< _StringTrait >::next_position ( const position_type &  pos)
static

Move to the next logical position. The movement is in the top-to-bottom then left-to-right direction.

Parameters
posposition object.
Returns
position object that references the element at the next logical position.
template<typename _StringTrait >
static const_position_type mdds::multi_type_matrix< _StringTrait >::next_position ( const const_position_type &  pos)
static

Move to the next logical position. The movement is in the top-to-bottom then left-to-right direction.

Parameters
posposition object.
Returns
non-mutable position object that references the element at the next logical position.
template<typename _StringTrait >
bool mdds::multi_type_matrix< _StringTrait >::numeric ( ) const

Check whether or not this matrix is numeric. A numeric matrix contains only numeric or boolean elements. An empty matrix is not numeric.

Returns
true if the matrix contains only numeric or boolean elements, or false otherwise.
template<typename _StringTrait >
position_type mdds::multi_type_matrix< _StringTrait >::position ( size_type  row,
size_type  col 
)

Get a mutable reference of an element (position object) at specified position. The position object can then be passed to an additional method to get the type or value of the element it references, or set a new value to it.

Parameters
rowrow position of the referenced element.
colcolumn position of the referenced element.
Returns
reference object of element at specified position.
template<typename _StringTrait >
position_type mdds::multi_type_matrix< _StringTrait >::position ( const position_type &  pos_hint,
size_type  row,
size_type  col 
)

Get a mutable reference of an element (position object) at specified position. The position object can then be passed to an additional method to get the type or value of the element it references, or set a new value to it.

Parameters
pos_hintposition object to be used as a position hint for faster lookup.
rowrow position of the referenced element.
colcolumn position of the referenced element.
Returns
reference object of element at specified position.
template<typename _StringTrait >
const_position_type mdds::multi_type_matrix< _StringTrait >::position ( size_type  row,
size_type  col 
) const

Get an immutable reference of an element (position object) at specified position. The position object can then be passed to an additional method to get the type or value of the element it references.

Parameters
rowrow position of the referenced element.
colcolumn position of the referenced element.
Returns
reference object of element at specified position.
template<typename _StringTrait >
const_position_type mdds::multi_type_matrix< _StringTrait >::position ( const const_position_type &  pos_hint,
size_type  row,
size_type  col 
) const

Get an immutable reference of an element (position object) at specified position. The position object can then be passed to an additional method to get the type or value of the element it references.

Parameters
pos_hintposition object to be used as a position hint for faster lookup.
rowrow position of the referenced element.
colcolumn position of the referenced element.
Returns
reference object of element at specified position.
template<typename _StringTrait >
void mdds::multi_type_matrix< _StringTrait >::resize ( size_type  rows,
size_type  cols 
)

Resize the matrix to specified size. This method supports resizing to zero-sized matrix; however, either specifying the row or column size to zero will resize the matrix to 0 x 0. When resizing the matrix larger, empty elements will be inserted in the region where no existing elements exist.

Parameters
rowsnew row size
colsnew column size
template<typename _StringTrait >
template<typename _T >
void mdds::multi_type_matrix< _StringTrait >::resize ( size_type  rows,
size_type  cols,
const _T &  value 
)

Resize the matrix to specified size and initial value. The initial value will be applied to new elements created when the specified size is larger than the current one.

Parameters
rowsnew row size
colsnew column size
valueinitial value for new elements
template<typename _StringTrait >
template<typename _T >
void mdds::multi_type_matrix< _StringTrait >::set ( size_type  row,
size_type  col,
const _T &  it_begin,
const _T &  it_end 
)

Set values of multiple elements at once, starting at specified element position following the direction of columns. When the new value series does not fit in the column of the start element, it gets wrapped into the next column(s).

The method will throw an std::out_of_range exception if the specified position is outside the current container range.

Parameters
rowrow position of the start element.
colcolumn position of the start element.
it_beginiterator that points to the begin position of the values being set.
it_enditerator that points to the end position of the values being set.
template<typename _StringTrait >
template<typename _T >
void mdds::multi_type_matrix< _StringTrait >::set_column ( size_type  col,
const _T &  it_begin,
const _T &  it_end 
)

Set values of multiple elements at once in a single column. When the length of passed elements exceeds that of the column, it gets truncated to the column size.

Parameters
colcolumn position
it_beginiterator that points to the begin position of the values being set.
it_enditerator that points to the end position of the values being set.
template<typename _StringTrait >
void mdds::multi_type_matrix< _StringTrait >::set_empty ( size_type  row,
size_type  col 
)

Set specified element position empty.

Parameters
rowrow position of the element.
colcolumn position of the element.
template<typename _StringTrait >
void mdds::multi_type_matrix< _StringTrait >::set_empty ( size_type  row,
size_type  col,
size_type  length 
)

Set specified range of elements empty.

Parameters
rowrow position of the first element.
colcolumn position of the first element.
lengthlength of the range to set empty.
template<typename _StringTrait >
position_type mdds::multi_type_matrix< _StringTrait >::set_empty ( const position_type &  pos)

Set element referenced by the position object empty.

Parameters
posposition object that references element.
template<typename _StringTrait >
size_pair_type mdds::multi_type_matrix< _StringTrait >::size ( ) const

Return the size of matrix as a pair. The first value is the row size, while the second value is the column size.

Returns
matrix size as a value pair.
template<typename _StringTrait >
void mdds::multi_type_matrix< _StringTrait >::swap ( multi_type_matrix< _StringTrait > &  r)

Swap the content of the matrix with another instance.

template<typename _StringTrait >
multi_type_matrix& mdds::multi_type_matrix< _StringTrait >::transpose ( )

Transpose the stored matrix data.

Returns
reference to this matrix instance.
template<typename _StringTrait >
template<typename _Func >
void mdds::multi_type_matrix< _StringTrait >::walk ( _Func &  func) const

Walk all element blocks that consist of the matrix.

Parameters
funcfunction object whose operator() gets called on each element block.
template<typename _StringTrait >
template<typename _Func >
void mdds::multi_type_matrix< _StringTrait >::walk ( _Func &  func,
const size_pair_type start,
const size_pair_type end 
) const

Walk through the element blocks that make up the sub-matrix defined by start and end positions.

Parameters
funcfunction object whose operator() gets called on the element block.
startthe column/row position of the upper-left corner of the sub-matrix.
endthe column/row position of the lower-right corner of the sub-matrix. Both column and row must be greater or equal to those of the start position.