28 #ifndef __MDDS_MULTI_TYPE_MATRIX_HPP__
29 #define __MDDS_MULTI_TYPE_MATRIX_HPP__
31 #ifdef MDDS_MULTI_TYPE_MATRIX_DEBUG
32 #ifndef MDDS_MULTI_TYPE_VECTOR_DEBUG
33 #define MDDS_MULTI_TYPE_VECTOR_DEBUG 1
37 #include "multi_type_vector.hpp"
38 #include "multi_type_vector_trait.hpp"
49 element_empty = mdds::mtv::element_type_empty,
50 element_boolean = mdds::mtv::element_type_boolean,
51 element_string = mdds::mtv::element_type_string,
52 element_numeric = mdds::mtv::element_type_numeric,
53 element_integer = mdds::mtv::element_type_int
75 template<
typename _MtxTrait>
78 typedef _MtxTrait matrix_trait;
80 typedef typename matrix_trait::string_element_block string_block_type;
81 typedef typename matrix_trait::integer_element_block integer_block_type;
83 typedef typename string_block_type::value_type string_type;
84 typedef typename integer_block_type::value_type integer_type;
85 typedef size_t size_type;
91 typedef typename store_type::position_type position_type;
92 typedef typename store_type::const_position_type const_position_type;
104 size_pair_type(size_type _row, size_type _column) : row(_row), column(_column) {}
106 bool operator== (
const size_pair_type& r)
const {
return row == r.row && column == r.column; }
107 bool operator!= (
const size_pair_type& r)
const {
return !operator== (r); }
117 const element_block_type* data;
122 template<
typename _Blk>
123 typename _Blk::const_iterator begin()
const;
125 template<
typename _Blk>
126 typename _Blk::const_iterator end()
const;
129 void assign(
const const_position_type& pos, size_type section_size);
132 static mtm::element_t to_mtm_type(mdds::mtv::element_t mtv_type)
136 case string_block_type::block_type:
137 return mdds::mtm::element_string;
138 case integer_block_type::block_type:
139 return mdds::mtm::element_integer;
140 case mdds::mtv::element_type_numeric:
141 case mdds::mtv::element_type_boolean:
142 case mdds::mtv::element_type_empty:
144 return static_cast<mtm::element_t
>(mtv_type);
146 throw type_error(
"multi_type_matrix: unknown element type.");
151 template<
typename _Func>
152 struct walk_func : std::unary_function<typename store_type::const_iterator::value_type, void>
155 walk_func(_Func& func) : m_func(func) {}
157 void operator() (
const typename store_type::const_iterator::value_type& mtv_node)
159 element_block_node_type mtm_node;
160 mtm_node.type = to_mtm_type(mtv_node.type);
161 mtm_node.size = mtv_node.size;
162 mtm_node.data = mtv_node.data;
177 static position_type
next_position(
const position_type& pos);
188 static const_position_type
next_position(
const const_position_type& pos);
211 template<
typename _T>
224 template<
typename _T>
225 multi_type_matrix(size_type rows, size_type cols,
const _T& it_begin,
const _T& it_end);
253 position_type
position(size_type row, size_type col);
268 position_type
position(
const position_type& pos_hint, size_type row, size_type col);
280 const_position_type
position(size_type row, size_type col)
const;
294 const_position_type
position(
const const_position_type& pos_hint, size_type row, size_type col)
const;
332 mtm::element_t
get_type(
const const_position_type& pos)
const;
340 mtm::element_t
get_type(size_type row, size_type col)
const;
353 double get_numeric(size_type row, size_type col)
const;
365 double get_numeric(
const const_position_type& pos)
const;
378 integer_type
get_integer(size_type row, size_type col)
const;
390 integer_type
get_integer(
const const_position_type& pos)
const;
403 bool get_boolean(size_type row, size_type col)
const;
415 bool get_boolean(
const const_position_type& pos)
const;
426 const string_type&
get_string(size_type row, size_type col)
const;
436 const string_type&
get_string(
const const_position_type& pos)
const;
448 template<
typename _T>
449 _T
get(size_type row, size_type col)
const;
457 void set_empty(size_type row, size_type col);
466 void set_empty(size_type row, size_type col, size_type length);
475 position_type
set_empty(
const position_type& pos);
498 void set(size_type row, size_type col,
double val);
508 position_type
set(
const position_type& pos,
double val);
517 void set(size_type row, size_type col,
bool val);
527 position_type
set(
const position_type& pos,
bool val);
536 void set(size_type row, size_type col,
const string_type& str);
546 position_type
set(
const position_type& pos,
const string_type& str);
555 void set(size_type row, size_type col, integer_type val);
565 position_type
set(
const position_type& pos, integer_type val);
583 template<
typename _T>
584 void set(size_type row, size_type col,
const _T& it_begin,
const _T& it_end);
600 template<
typename _T>
601 position_type
set(
const position_type& pos,
const _T& it_begin,
const _T& it_end);
614 template<
typename _T>
615 void set_column(size_type col,
const _T& it_begin,
const _T& it_end);
623 size_pair_type
size()
const;
655 template<
typename _T>
656 void copy(size_type rows, size_type cols,
const _T& it_begin,
const _T& it_end);
668 void resize(size_type rows, size_type cols);
679 template<
typename _T>
680 void resize(size_type rows, size_type cols,
const _T& value);
714 template<
typename _Func>
715 void walk(_Func& func)
const;
731 template<
typename _Func>
732 void walk(_Func& func,
const size_pair_type& start,
const size_pair_type& end)
const;
744 template<
typename _Func>
765 template<
typename _Func>
767 const size_pair_type& start,
const size_pair_type& end)
const;
770 #ifdef MDDS_MULTI_TYPE_MATRIX_DEBUG
773 m_store.dump_blocks(std::cout);
789 inline size_type get_pos(size_type row, size_type col)
const
791 return m_size.row * col + row;
794 inline size_type get_pos(
const const_position_type& pos)
const
796 return pos.first->position + pos.second;
801 size_pair_type m_size;
806 #include "multi_type_matrix_def.inl"
void set_column(size_type col, const _T &it_begin, const _T &it_end)
Definition: multi_type_vector_trait.hpp:692
bool get_boolean(size_type row, size_type col) const
Definition: multi_type_vector_types.hpp:88
static position_type next_position(const position_type &pos)
const string_type & get_string(size_type row, size_type col) const
Definition: global.hpp:84
void swap(multi_type_matrix &r)
size_pair_type size() const
position_type end_position()
void set_empty(size_type row, size_type col)
Definition: multi_type_matrix.hpp:99
multi_type_matrix & transpose()
Definition: multi_type_vector_types.hpp:490
Definition: multi_type_matrix.hpp:76
void copy(const multi_type_matrix &src)
void set_column_empty(size_type col)
void resize(size_type rows, size_type cols)
Definition: default_deleter.hpp:33
mtm::element_t get_type(const const_position_type &pos) const
void set(size_type row, size_type col, double val)
void set_row_empty(size_type row)
position_type position(size_type row, size_type col)
double get_numeric(size_type row, size_type col) const
Definition: multi_type_matrix.hpp:59
integer_type get_integer(size_type row, size_type col) const
size_pair_type matrix_position(const const_position_type &pos) const
Definition: multi_type_matrix.hpp:110
void walk(_Func &func) const