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"
48 element_empty = mdds::mtv::element_type_empty,
49 element_boolean = mdds::mtv::element_type_boolean,
50 element_string = mdds::mtv::element_type_string,
51 element_numeric = mdds::mtv::element_type_double,
52 element_integer = mdds::mtv::element_type_int32
75 template<
typename Traits>
78 typedef Traits traits_type;
81 typedef typename traits_type::string_element_block string_block_type;
82 typedef typename traits_type::integer_element_block integer_block_type;
84 typedef typename string_block_type::value_type string_type;
85 typedef typename integer_block_type::value_type integer_type;
86 typedef size_t size_type;
93 typename traits_type::string_element_block,
typename traits_type::integer_element_block>;
99 typedef typename store_type::position_type position_type;
100 typedef typename store_type::const_position_type const_position_type;
113 size_pair_type(size_type _row, size_type _column) : row(_row), column(_column)
120 size_type* ptrs[2] = {&row, &column};
121 size_type** p = ptrs;
123 for (size_type v : vs)
129 return row == r.row && column == r.column;
133 return !operator==(r);
144 const element_block_type* data;
149 template<
typename _Blk>
150 typename _Blk::const_iterator begin()
const;
152 template<
typename _Blk>
153 typename _Blk::const_iterator end()
const;
156 void assign(
const const_position_type& pos, size_type section_size);
159 static mtm::element_t to_mtm_type(mdds::mtv::element_t mtv_type)
163 case string_block_type::block_type:
164 return mdds::mtm::element_string;
165 case integer_block_type::block_type:
166 return mdds::mtm::element_integer;
167 case mdds::mtv::element_type_double:
168 case mdds::mtv::element_type_boolean:
169 case mdds::mtv::element_type_empty:
171 return static_cast<mtm::element_t
>(mtv_type);
173 throw type_error(
"multi_type_matrix: unknown element type.");
178 template<
typename FuncT>
182 walk_func(FuncT& func) : m_func(func)
185 void operator()(
const typename store_type::const_iterator::value_type& mtv_node)
187 element_block_node_type mtm_node;
188 mtm_node.type = to_mtm_type(mtv_node.type);
189 mtm_node.size = mtv_node.size;
190 mtm_node.data = mtv_node.data;
205 static position_type
next_position(
const position_type& pos);
216 static const_position_type
next_position(
const const_position_type& pos);
239 template<
typename _T>
254 template<
typename _T>
255 multi_type_matrix(size_type rows, size_type cols,
const _T& it_begin,
const _T& it_end);
283 position_type
position(size_type row, size_type col);
298 position_type
position(
const position_type& pos_hint, size_type row, size_type col);
310 const_position_type
position(size_type row, size_type col)
const;
324 const_position_type
position(
const const_position_type& pos_hint, size_type row, size_type col)
const;
362 mtm::element_t
get_type(
const const_position_type& pos)
const;
370 mtm::element_t
get_type(size_type row, size_type col)
const;
383 double get_numeric(size_type row, size_type col)
const;
395 double get_numeric(
const const_position_type& pos)
const;
408 integer_type
get_integer(size_type row, size_type col)
const;
420 integer_type
get_integer(
const const_position_type& pos)
const;
433 bool get_boolean(size_type row, size_type col)
const;
445 bool get_boolean(
const const_position_type& pos)
const;
456 const string_type&
get_string(size_type row, size_type col)
const;
466 const string_type&
get_string(
const const_position_type& pos)
const;
478 template<
typename _T>
479 _T
get(size_type row, size_type col)
const;
487 void set_empty(size_type row, size_type col);
500 void set_empty(size_type row, size_type col, size_type length);
509 position_type
set_empty(
const position_type& pos);
532 void set(size_type row, size_type col,
double val);
542 position_type
set(
const position_type& pos,
double val);
551 void set(size_type row, size_type col,
bool val);
561 position_type
set(
const position_type& pos,
bool val);
570 void set(size_type row, size_type col,
const string_type& str);
580 position_type
set(
const position_type& pos,
const string_type& str);
589 void set(size_type row, size_type col, integer_type val);
599 position_type
set(
const position_type& pos, integer_type val);
617 template<
typename _T>
618 void set(size_type row, size_type col,
const _T& it_begin,
const _T& it_end);
634 template<
typename _T>
635 position_type
set(
const position_type& pos,
const _T& it_begin,
const _T& it_end);
648 template<
typename _T>
649 void set_column(size_type col,
const _T& it_begin,
const _T& it_end);
657 size_pair_type
size()
const;
689 template<
typename _T>
690 void copy(size_type rows, size_type cols,
const _T& it_begin,
const _T& it_end);
702 void resize(size_type rows, size_type cols);
713 template<
typename _T>
714 void resize(size_type rows, size_type cols,
const _T& value);
750 template<
typename FuncT>
751 FuncT
walk(FuncT func)
const;
769 template<
typename FuncT>
770 FuncT
walk(FuncT func,
const size_pair_type& start,
const size_pair_type& end)
const;
782 template<
typename FuncT>
803 template<
typename FuncT>
805 FuncT func,
const multi_type_matrix& right,
const size_pair_type& start,
const size_pair_type& end)
const;
807 #ifdef MDDS_MULTI_TYPE_MATRIX_DEBUG
810 m_store.dump_blocks(std::cout);
825 inline size_type get_pos(size_type row, size_type col)
const
827 return m_size.row * col + row;
830 inline size_type get_pos(
const const_position_type& pos)
const
832 return pos.first->position + pos.second;
837 size_pair_type m_size;
842 #include "multi_type_matrix_def.inl"
position_type end_position()
static position_type next_position(const position_type &pos)
double get_numeric(size_type row, size_type col) const
bool get_boolean(size_type row, size_type col) const
size_pair_type size() const
void set_column_empty(size_type col)
FuncT walk(FuncT func) const
Definition: global.hpp:114
mtm::element_t get_type(const const_position_type &pos) const
void resize(size_type rows, size_type cols)
integer_type get_integer(size_type row, size_type col) const
Definition: global.hpp:100
Definition: multi_type_matrix.hpp:107
void set_column(size_type col, const _T &it_begin, const _T &it_end)
void set(size_type row, size_type col, double val)
Definition: types.hpp:830
size_pair_type matrix_position(const const_position_type &pos) const
void copy(const multi_type_matrix &src)
Definition: multi_type_matrix.hpp:76
void set_empty(size_type row, size_type col)
multi_type_matrix & transpose()
const string_type & get_string(size_type row, size_type col) const
Definition: flat_segment_tree.hpp:46
void set_row_empty(size_type row)
Definition: block_funcs.hpp:64
Definition: types.hpp:159
position_type position(size_type row, size_type col)
Definition: multi_type_matrix.hpp:58
Definition: multi_type_matrix.hpp:137
void swap(multi_type_matrix &r)