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_double,
53 element_integer = mdds::mtv::element_type_int32
78 template<
typename _MtxTrait>
81 typedef _MtxTrait matrix_trait;
84 typedef typename matrix_trait::string_element_block string_block_type;
85 typedef typename matrix_trait::integer_element_block integer_block_type;
87 typedef typename string_block_type::value_type string_type;
88 typedef typename integer_block_type::value_type integer_type;
89 typedef size_t size_type;
95 typedef typename store_type::position_type position_type;
96 typedef typename store_type::const_position_type const_position_type;
109 size_pair_type(size_type _row, size_type _column) : row(_row), column(_column)
116 size_type* ptrs[2] = {&row, &column};
117 size_type** p = ptrs;
119 for (size_type v : vs)
125 return row == r.row && column == r.column;
129 return !operator==(r);
140 const element_block_type* data;
145 template<
typename _Blk>
146 typename _Blk::const_iterator begin()
const;
148 template<
typename _Blk>
149 typename _Blk::const_iterator end()
const;
152 void assign(
const const_position_type& pos, size_type section_size);
155 static mtm::element_t to_mtm_type(mdds::mtv::element_t mtv_type)
159 case string_block_type::block_type:
160 return mdds::mtm::element_string;
161 case integer_block_type::block_type:
162 return mdds::mtm::element_integer;
163 case mdds::mtv::element_type_double:
164 case mdds::mtv::element_type_boolean:
165 case mdds::mtv::element_type_empty:
167 return static_cast<mtm::element_t
>(mtv_type);
169 throw type_error(
"multi_type_matrix: unknown element type.");
174 template<
typename _Func>
178 walk_func(_Func& func) : m_func(func)
181 void operator()(
const typename store_type::const_iterator::value_type& mtv_node)
183 element_block_node_type mtm_node;
184 mtm_node.type = to_mtm_type(mtv_node.type);
185 mtm_node.size = mtv_node.size;
186 mtm_node.data = mtv_node.data;
201 static position_type
next_position(
const position_type& pos);
212 static const_position_type
next_position(
const const_position_type& pos);
235 template<
typename _T>
250 template<
typename _T>
251 multi_type_matrix(size_type rows, size_type cols,
const _T& it_begin,
const _T& it_end);
279 position_type
position(size_type row, size_type col);
294 position_type
position(
const position_type& pos_hint, size_type row, size_type col);
306 const_position_type
position(size_type row, size_type col)
const;
320 const_position_type
position(
const const_position_type& pos_hint, size_type row, size_type col)
const;
358 mtm::element_t
get_type(
const const_position_type& pos)
const;
366 mtm::element_t
get_type(size_type row, size_type col)
const;
379 double get_numeric(size_type row, size_type col)
const;
391 double get_numeric(
const const_position_type& pos)
const;
404 integer_type
get_integer(size_type row, size_type col)
const;
416 integer_type
get_integer(
const const_position_type& pos)
const;
429 bool get_boolean(size_type row, size_type col)
const;
441 bool get_boolean(
const const_position_type& pos)
const;
452 const string_type&
get_string(size_type row, size_type col)
const;
462 const string_type&
get_string(
const const_position_type& pos)
const;
474 template<
typename _T>
475 _T
get(size_type row, size_type col)
const;
483 void set_empty(size_type row, size_type col);
496 void set_empty(size_type row, size_type col, size_type length);
505 position_type
set_empty(
const position_type& pos);
528 void set(size_type row, size_type col,
double val);
538 position_type
set(
const position_type& pos,
double val);
547 void set(size_type row, size_type col,
bool val);
557 position_type
set(
const position_type& pos,
bool val);
566 void set(size_type row, size_type col,
const string_type& str);
576 position_type
set(
const position_type& pos,
const string_type& str);
585 void set(size_type row, size_type col, integer_type val);
595 position_type
set(
const position_type& pos, integer_type val);
613 template<
typename _T>
614 void set(size_type row, size_type col,
const _T& it_begin,
const _T& it_end);
630 template<
typename _T>
631 position_type
set(
const position_type& pos,
const _T& it_begin,
const _T& it_end);
644 template<
typename _T>
645 void set_column(size_type col,
const _T& it_begin,
const _T& it_end);
653 size_pair_type
size()
const;
685 template<
typename _T>
686 void copy(size_type rows, size_type cols,
const _T& it_begin,
const _T& it_end);
698 void resize(size_type rows, size_type cols);
709 template<
typename _T>
710 void resize(size_type rows, size_type cols,
const _T& value);
746 template<
typename _Func>
747 _Func
walk(_Func func)
const;
765 template<
typename _Func>
766 _Func
walk(_Func func,
const size_pair_type& start,
const size_pair_type& end)
const;
778 template<
typename _Func>
799 template<
typename _Func>
801 _Func func,
const multi_type_matrix& right,
const size_pair_type& start,
const size_pair_type& end)
const;
803 #ifdef MDDS_MULTI_TYPE_MATRIX_DEBUG
806 m_store.dump_blocks(std::cout);
821 inline size_type get_pos(size_type row, size_type col)
const
823 return m_size.row * col + row;
826 inline size_type get_pos(
const const_position_type& pos)
const
828 return pos.first->position + pos.second;
833 size_pair_type m_size;
838 #include "multi_type_matrix_def.inl"
void set_column(size_type col, const _T &it_begin, const _T &it_end)
Definition: trait.hpp:745
bool get_boolean(size_type row, size_type col) const
static position_type next_position(const position_type &pos)
const string_type & get_string(size_type row, size_type col) const
Definition: global.hpp:114
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: global.hpp:100
_Func walk(_Func func) const
Definition: multi_type_matrix.hpp:103
multi_type_matrix & transpose()
Definition: types.hpp:615
Definition: multi_type_matrix.hpp:79
void copy(const multi_type_matrix &src)
void set_column_empty(size_type col)
void resize(size_type rows, size_type cols)
Definition: flat_segment_tree.hpp:46
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)
Definition: types.hpp:173
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:133