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
59 struct std_string_trait
75 template<
typename _MtxTrait>
76 class multi_type_matrix
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;
94 typedef typename store_type::element_block_type element_block_type;
96 typedef typename mtv::boolean_element_block boolean_block_type;
97 typedef typename mtv::double_element_block numeric_block_type;
104 size_pair_type(size_type _row, size_type _column) : row(_row), column(_column) {}
105 size_pair_type(std::initializer_list<size_type> vs)
108 throw invalid_arg_error(
"size_pair_type requires exactly 2 elements.");
110 size_type* ptrs[2] = { &row, &column };
111 size_type** p = ptrs;
113 for (size_type v : vs)
117 bool operator== (
const size_pair_type& r)
const {
return row == r.row && column == r.column; }
118 bool operator!= (
const size_pair_type& r)
const {
return !operator== (r); }
121 struct element_block_node_type
123 friend class multi_type_matrix;
133 template<
typename _Blk>
134 typename _Blk::const_iterator begin()
const;
136 template<
typename _Blk>
137 typename _Blk::const_iterator end()
const;
140 void assign(
const const_position_type& pos, size_type section_size);
143 static mtm::element_t to_mtm_type(mdds::mtv::element_t mtv_type)
147 case string_block_type::block_type:
148 return mdds::mtm::element_string;
149 case integer_block_type::block_type:
150 return mdds::mtm::element_integer;
151 case mdds::mtv::element_type_double:
152 case mdds::mtv::element_type_boolean:
153 case mdds::mtv::element_type_empty:
155 return static_cast<mtm::element_t
>(mtv_type);
157 throw type_error(
"multi_type_matrix: unknown element type.");
162 template<
typename _Func>
166 walk_func(_Func& func) : m_func(func) {}
168 void operator() (
const typename store_type::const_iterator::value_type& mtv_node)
170 element_block_node_type mtm_node;
171 mtm_node.type = to_mtm_type(mtv_node.type);
172 mtm_node.size = mtv_node.size;
173 mtm_node.data = mtv_node.data;
188 static position_type
next_position(
const position_type& pos);
199 static const_position_type
next_position(
const const_position_type& pos);
222 template<
typename _T>
235 template<
typename _T>
236 multi_type_matrix(size_type rows, size_type cols,
const _T& it_begin,
const _T& it_end);
264 position_type
position(size_type row, size_type col);
279 position_type
position(
const position_type& pos_hint, size_type row, size_type col);
291 const_position_type
position(size_type row, size_type col)
const;
305 const_position_type
position(
const const_position_type& pos_hint, size_type row, size_type col)
const;
343 mtm::element_t
get_type(
const const_position_type& pos)
const;
351 mtm::element_t
get_type(size_type row, size_type col)
const;
364 double get_numeric(size_type row, size_type col)
const;
376 double get_numeric(
const const_position_type& pos)
const;
389 integer_type
get_integer(size_type row, size_type col)
const;
401 integer_type
get_integer(
const const_position_type& pos)
const;
414 bool get_boolean(size_type row, size_type col)
const;
426 bool get_boolean(
const const_position_type& pos)
const;
437 const string_type&
get_string(size_type row, size_type col)
const;
447 const string_type&
get_string(
const const_position_type& pos)
const;
459 template<
typename _T>
460 _T
get(size_type row, size_type col)
const;
468 void set_empty(size_type row, size_type col);
477 void set_empty(size_type row, size_type col, size_type length);
486 position_type
set_empty(
const position_type& pos);
509 void set(size_type row, size_type col,
double val);
519 position_type
set(
const position_type& pos,
double val);
528 void set(size_type row, size_type col,
bool val);
538 position_type
set(
const position_type& pos,
bool val);
547 void set(size_type row, size_type col,
const string_type& str);
557 position_type
set(
const position_type& pos,
const string_type& str);
566 void set(size_type row, size_type col, integer_type val);
576 position_type
set(
const position_type& pos, integer_type val);
594 template<
typename _T>
595 void set(size_type row, size_type col,
const _T& it_begin,
const _T& it_end);
611 template<
typename _T>
612 position_type
set(
const position_type& pos,
const _T& it_begin,
const _T& it_end);
625 template<
typename _T>
626 void set_column(size_type col,
const _T& it_begin,
const _T& it_end);
634 size_pair_type
size()
const;
666 template<
typename _T>
667 void copy(size_type rows, size_type cols,
const _T& it_begin,
const _T& it_end);
679 void resize(size_type rows, size_type cols);
690 template<
typename _T>
691 void resize(size_type rows, size_type cols,
const _T& value);
727 template<
typename _Func>
728 _Func
walk(_Func func)
const;
746 template<
typename _Func>
747 _Func
walk(_Func func,
const size_pair_type& start,
const size_pair_type& end)
const;
759 template<
typename _Func>
780 template<
typename _Func>
782 const size_pair_type& start,
const size_pair_type& end)
const;
785 #ifdef MDDS_MULTI_TYPE_MATRIX_DEBUG
788 m_store.dump_blocks(std::cout);
804 inline size_type get_pos(size_type row, size_type col)
const
806 return m_size.row * col + row;
809 inline size_type get_pos(
const const_position_type& pos)
const
811 return pos.first->position + pos.second;
816 size_pair_type m_size;
821 #include "multi_type_matrix_def.inl"