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;
83 typedef typename matrix_trait::string_element_block string_block_type;
84 typedef typename matrix_trait::integer_element_block integer_block_type;
86 typedef typename string_block_type::value_type string_type;
87 typedef typename integer_block_type::value_type integer_type;
88 typedef size_t size_type;
94 typedef typename store_type::position_type position_type;
95 typedef typename store_type::const_position_type const_position_type;
107 size_pair_type(size_type _row, size_type _column) : row(_row), column(_column) {}
113 size_type* ptrs[2] = { &row, &column };
114 size_type** p = ptrs;
116 for (size_type v : vs)
120 bool operator== (
const size_pair_type& r)
const {
return row == r.row && column == r.column; }
121 bool operator!= (
const size_pair_type& r)
const {
return !operator== (r); }
136 template<
typename _Blk>
137 typename _Blk::const_iterator begin()
const;
139 template<
typename _Blk>
140 typename _Blk::const_iterator end()
const;
143 void assign(
const const_position_type& pos, size_type section_size);
146 static mtm::element_t to_mtm_type(mdds::mtv::element_t mtv_type)
150 case string_block_type::block_type:
151 return mdds::mtm::element_string;
152 case integer_block_type::block_type:
153 return mdds::mtm::element_integer;
154 case mdds::mtv::element_type_double:
155 case mdds::mtv::element_type_boolean:
156 case mdds::mtv::element_type_empty:
158 return static_cast<mtm::element_t
>(mtv_type);
160 throw type_error(
"multi_type_matrix: unknown element type.");
165 template<
typename _Func>
169 walk_func(_Func& func) : m_func(func) {}
171 void operator() (
const typename store_type::const_iterator::value_type& mtv_node)
173 element_block_node_type mtm_node;
174 mtm_node.type = to_mtm_type(mtv_node.type);
175 mtm_node.size = mtv_node.size;
176 mtm_node.data = mtv_node.data;
225 template<
typename _T>
240 template<
typename _T>
269 position_type
position(size_type row, size_type col);
284 position_type
position(
const position_type& pos_hint, size_type row, size_type col);
296 const_position_type
position(size_type row, size_type col)
const;
310 const_position_type
position(
const const_position_type& pos_hint, size_type row, size_type col)
const;
348 mtm::element_t
get_type(
const const_position_type& pos)
const;
356 mtm::element_t
get_type(size_type row, size_type col)
const;
442 const string_type&
get_string(size_type row, size_type col)
const;
452 const string_type&
get_string(
const const_position_type& pos)
const;
464 template<
typename _T>
465 _T
get(size_type row, size_type col)
const;
486 void set_empty(size_type row, size_type col, size_type length);
518 void set(size_type row, size_type col,
double val);
528 position_type
set(
const position_type& pos,
double val);
537 void set(size_type row, size_type col,
bool val);
547 position_type
set(
const position_type& pos,
bool val);
556 void set(size_type row, size_type col,
const string_type& str);
566 position_type
set(
const position_type& pos,
const string_type& str);
575 void set(size_type row, size_type col, integer_type val);
585 position_type
set(
const position_type& pos, integer_type val);
603 template<
typename _T>
604 void set(size_type row, size_type col,
const _T& it_begin,
const _T& it_end);
620 template<
typename _T>
621 position_type
set(
const position_type& pos,
const _T& it_begin,
const _T& it_end);
634 template<
typename _T>
635 void set_column(size_type col,
const _T& it_begin,
const _T& it_end);
675 template<
typename _T>
676 void copy(size_type rows, size_type cols,
const _T& it_begin,
const _T& it_end);
688 void resize(size_type rows, size_type cols);
699 template<
typename _T>
700 void resize(size_type rows, size_type cols,
const _T& value);
736 template<
typename _Func>
755 template<
typename _Func>
768 template<
typename _Func>
789 template<
typename _Func>
794 #ifdef MDDS_MULTI_TYPE_MATRIX_DEBUG
797 m_store.dump_blocks(std::cout);
813 inline size_type get_pos(size_type row, size_type col)
const
815 return m_size.row * col + row;
818 inline size_type get_pos(
const const_position_type& pos)
const
820 return pos.first->position + pos.second;
825 size_pair_type m_size;
830 #include "multi_type_matrix_def.inl"