28 #ifndef INCLUDED_MDDS_MULTI_TYPE_VECTOR_HPP
29 #define INCLUDED_MDDS_MULTI_TYPE_VECTOR_HPP
32 #include "multi_type_vector_types.hpp"
33 #include "multi_type_vector_itr.hpp"
40 #if defined(MDDS_UNIT_TEST) || defined (MDDS_MULTI_TYPE_VECTOR_DEBUG)
49 namespace detail {
namespace mtv {
65 T advance_position(
const T& pos,
int steps);
94 template<
typename _ElemBlockFunc,
typename _EventFunc = detail::mtv::event_func>
95 class multi_type_vector
98 typedef size_t size_type;
101 typedef typename mdds::mtv::element_t element_category_type;
102 typedef _ElemBlockFunc element_block_func;
127 size_type m_position;
129 element_block_type* mp_data;
132 block(size_type _position, size_type _size);
133 block(size_type _position, size_type _size, element_block_type* _data);
134 block(
const block& other);
135 block(block&& other);
137 void swap(block& other);
138 void clone_to(block& other)
const;
140 block& operator=(block);
143 struct element_block_deleter
145 void operator() (
const element_block_type* p)
147 element_block_func::delete_block(p);
151 typedef std::vector<block> blocks_type;
153 struct blocks_to_transfer
156 size_type insert_index;
158 blocks_to_transfer();
161 struct iterator_trait
164 typedef blocks_type blocks;
165 typedef typename blocks_type::iterator base_iterator;
168 struct reverse_iterator_trait
171 typedef blocks_type blocks;
172 typedef typename blocks_type::reverse_iterator base_iterator;
175 struct const_iterator_trait
178 typedef blocks_type blocks;
179 typedef typename blocks_type::const_iterator base_iterator;
182 struct const_reverse_iterator_trait
185 typedef blocks_type blocks;
186 typedef typename blocks_type::const_reverse_iterator base_iterator;
189 typedef detail::mtv::iterator_value_node<size_type, element_block_type> itr_node;
190 typedef detail::mtv::private_data_forward_update<itr_node> itr_forward_update;
191 typedef detail::mtv::private_data_no_update<itr_node> itr_no_update;
195 typedef detail::mtv::iterator_base<iterator_trait, itr_forward_update> iterator;
196 typedef detail::mtv::iterator_base<reverse_iterator_trait, itr_no_update> reverse_iterator;
198 typedef detail::mtv::const_iterator_base<const_iterator_trait, itr_forward_update, iterator> const_iterator;
199 typedef detail::mtv::const_iterator_base<const_reverse_iterator_trait, itr_no_update, reverse_iterator> const_reverse_iterator;
218 typedef std::pair<iterator, size_type> position_type;
219 typedef std::pair<const_iterator, size_type> const_position_type;
229 static position_type
next_position(
const position_type& pos);
250 static const_position_type
next_position(
const const_position_type& pos);
261 static const_position_type
advance_position(
const const_position_type& pos,
int steps);
281 template<
typename _Blk>
282 static typename _Blk::value_type
get(
const const_position_type& pos);
344 template<
typename _T>
360 template<
typename _T>
391 template<
typename _T>
426 template<
typename _T>
450 template<
typename _T>
451 iterator set(size_type pos,
const _T& it_begin,
const _T& it_end);
490 template<
typename _T>
491 iterator set(
const iterator& pos_hint, size_type pos,
const _T& it_begin,
const _T& it_end);
502 template<
typename _T>
535 template<
typename _T>
536 iterator insert(size_type pos,
const _T& it_begin,
const _T& it_end);
575 template<
typename _T>
588 template<
typename _T>
589 void get(size_type pos, _T& value)
const;
602 template<
typename _T>
603 _T
get(size_type pos)
const;
619 template<
typename _T>
638 template<
typename _T>
657 template<
typename _T>
729 position_type
position(size_type pos);
765 const_position_type
position(size_type pos)
const;
847 mtv::element_t
get_type(size_type pos)
const;
923 void erase(size_type start_pos, size_type end_pos);
992 size_type
size()
const;
1027 void resize(size_type new_size);
1063 template<
typename _T>
1066 #ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
1067 void dump_blocks(std::ostream& os)
const;
1069 bool check_block_integrity()
const;
1074 void adjust_block_positions(int64_t start_block_index, size_type delta);
1082 void delete_element_block(block& blk);
1091 void delete_element_blocks(
typename blocks_type::iterator it,
typename blocks_type::iterator it_end);
1093 template<
typename _T>
1094 iterator set_impl(size_type pos, size_type block_index,
const _T& value);
1096 template<
typename _T>
1097 iterator release_impl(size_type pos, size_type block_index, _T& value);
1099 template<
typename _T>
1100 iterator push_back_impl(
const _T& value);
1110 size_type get_block_position(size_type row, size_type start_block_index=0)
const;
1116 size_type get_block_position(
const const_iterator& pos_hint, size_type row)
const;
1118 template<
typename _T>
1121 template<
typename _T>
1122 iterator set_cell_to_middle_of_block(
1123 size_type block_index, size_type pos_in_block,
const _T& cell);
1125 template<
typename _T>
1126 void append_cell_to_block(size_type block_index,
const _T& cell);
1128 template<
typename _T>
1130 size_type start_row, size_type block_index, size_type pos_in_block,
const _T& cell);
1132 template<
typename _T>
1133 iterator set_cell_to_block_of_size_one(
1134 size_type block_index,
const _T& cell);
1136 template<
typename _T>
1137 void set_cell_to_top_of_data_block(
1138 size_type block_index,
const _T& cell);
1140 template<
typename _T>
1141 void set_cell_to_bottom_of_data_block(
1142 size_type block_index,
const _T& cell);
1145 size_type start_pos, size_type end_pos, size_type block_index1,
1152 size_type start_pos, size_type end_pos, size_type block_index1,
1160 size_type start_pos, size_type end_pos, size_type block_index1, size_type block_index2,
1174 size_type start_pos, size_type end_pos, size_type block_index1,
bool overwrite);
1177 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos,
1178 size_type block_index1, size_type block_index2, size_type dblock_index1, size_type dblock_index2);
1180 void swap_single_block(
1181 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos,
1182 size_type block_index, size_type other_block_index);
1184 void swap_single_to_multi_blocks(
1185 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos,
1186 size_type block_index, size_type dst_block_index1, size_type dst_block_index2);
1188 void swap_multi_to_multi_blocks(
1189 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos,
1190 size_type block_index1, size_type block_index2, size_type dblock_index1, size_type dblock_index2);
1192 void insert_blocks_at(size_type
position, size_type insert_pos, blocks_type& new_blocks);
1194 void prepare_blocks_to_transfer(blocks_to_transfer& bucket, size_type block_index1, size_type offset1, size_type block_index2, size_type offset2);
1196 iterator set_whole_block_empty(size_type block_index,
bool overwrite);
1198 iterator set_empty_in_single_block(
1199 size_type start_row, size_type end_row, size_type block_index,
bool overwrite);
1210 iterator set_empty_in_multi_blocks(
1211 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
1214 void erase_impl(size_type start_pos, size_type end_pos);
1215 void erase_in_single_block(size_type start_pos, size_type end_pos, size_type block_pos);
1222 iterator insert_empty_impl(size_type pos, size_type block_index, size_type length);
1224 template<
typename _T>
1225 bool set_cells_precheck(
1226 size_type row,
const _T& it_begin,
const _T& it_end, size_type& end_pos);
1228 template<
typename _T>
1230 size_type row, size_type end_row, size_type block_index1,
const _T& it_begin,
const _T& it_end);
1232 template<
typename _T>
1233 iterator insert_cells_impl(size_type row, size_type block_index,
const _T& it_begin,
const _T& it_end);
1235 template<
typename _T>
1236 iterator set_cells_to_single_block(
1237 size_type start_row, size_type end_row, size_type block_index,
1238 const _T& it_begin,
const _T& it_end);
1240 template<
typename _T>
1241 iterator set_cells_to_multi_blocks(
1242 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
1243 const _T& it_begin,
const _T& it_end);
1245 template<
typename _T>
1246 iterator set_cells_to_multi_blocks_block1_non_equal(
1247 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
1248 const _T& it_begin,
const _T& it_end);
1250 template<
typename _T>
1251 iterator set_cells_to_multi_blocks_block1_non_empty(
1252 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
1253 const _T& it_begin,
const _T& it_end);
1263 size_type merge_with_adjacent_blocks(size_type block_index);
1272 bool merge_with_next_block(size_type block_index);
1274 template<
typename _T>
1275 bool append_to_prev_block(
1276 size_type block_index, element_category_type cat, size_type length,
1277 const _T& it_begin,
const _T& it_end);
1279 template<
typename _T>
1280 void insert_cells_to_middle(
1281 size_type row, size_type block_index,
const _T& it_begin,
const _T& it_end);
1296 block& set_new_block_to_middle(
1297 size_type block_index, size_type offset, size_type new_block_size,
bool overwrite);
1299 block* get_previous_block_of_type(size_type block_index, element_category_type cat);
1308 block* get_next_block_of_type(size_type block_index, element_category_type cat);
1328 const element_block_type& src_data, size_type src_offset, size_type dst_index, size_type dst_offset, size_type len);
1330 void exchange_elements(
1332 size_type dst_index1, size_type dst_offset1, size_type dst_index2, size_type dst_offset2,
1333 size_type len, blocks_type& new_blocks);
1335 bool append_empty(size_type len);
1337 inline iterator get_iterator(size_type block_index)
1339 typename blocks_type::iterator block_pos = m_blocks.begin();
1340 std::advance(block_pos, block_index);
1341 return iterator(block_pos, m_blocks.end(), block_index);
1344 inline const_iterator get_const_iterator(size_type block_index)
const
1346 typename blocks_type::const_iterator block_pos = m_blocks.begin();
1347 std::advance(block_pos, block_index);
1348 return const_iterator(block_pos, m_blocks.end(), block_index);
1353 blocks_type m_blocks;
1354 size_type m_cur_size;
1359 #include "multi_type_vector_def.inl"