28 #ifndef MDDS_MULTI_TYPE_VECTOR_HPP 29 #define MDDS_MULTI_TYPE_VECTOR_HPP 31 #include "default_deleter.hpp" 33 #include "multi_type_vector_types.hpp" 34 #include "multi_type_vector_itr.hpp" 41 #if defined(MDDS_UNIT_TEST) || defined (MDDS_MULTI_TYPE_VECTOR_DEBUG) 66 T mtv_advance_position(
const T& pos,
int steps);
95 template<
typename _ElemBlockFunc,
typename _EventFunc = detail::mtv_event_func>
99 typedef size_t size_type;
102 typedef typename mdds::mtv::element_t element_category_type;
103 typedef _ElemBlockFunc element_block_func;
129 element_block_type* mp_data;
132 block(size_type _size);
133 block(
const block& other);
137 struct element_block_deleter :
public std::unary_function<void, const element_block_type*>
139 void operator() (
const element_block_type* p)
141 element_block_func::delete_block(p);
145 typedef std::vector<block*> blocks_type;
147 struct blocks_to_transfer
150 size_type insert_index;
152 blocks_to_transfer();
155 struct iterator_trait
158 typedef blocks_type blocks;
159 typedef typename blocks_type::iterator base_iterator;
162 struct reverse_iterator_trait
165 typedef blocks_type blocks;
166 typedef typename blocks_type::reverse_iterator base_iterator;
169 struct const_iterator_trait
172 typedef blocks_type blocks;
173 typedef typename blocks_type::const_iterator base_iterator;
176 struct const_reverse_iterator_trait
179 typedef blocks_type blocks;
180 typedef typename blocks_type::const_reverse_iterator base_iterator;
212 typedef std::pair<iterator, size_type> position_type;
213 typedef std::pair<const_iterator, size_type> const_position_type;
223 static position_type next_position(
const position_type& pos);
234 static position_type advance_position(
const position_type& pos,
int steps);
244 static const_position_type next_position(
const const_position_type& pos);
255 static const_position_type advance_position(
const const_position_type& pos,
int steps);
265 static size_type logical_position(
const const_position_type& pos);
275 template<
typename _Blk>
276 static typename _Blk::value_type
get(
const const_position_type& pos);
281 const_iterator begin()
const;
282 const_iterator end()
const;
284 reverse_iterator rbegin();
285 reverse_iterator rend();
287 const_reverse_iterator rbegin()
const;
288 const_reverse_iterator rend()
const;
290 event_func& event_handler();
291 const event_func& event_handler()
const;
332 template<
typename _T>
348 template<
typename _T>
379 template<
typename _T>
380 iterator
set(size_type pos,
const _T& value);
414 template<
typename _T>
415 iterator
set(
const iterator& pos_hint, size_type pos,
const _T& value);
438 template<
typename _T>
439 iterator
set(size_type pos,
const _T& it_begin,
const _T& it_end);
478 template<
typename _T>
479 iterator
set(
const iterator& pos_hint, size_type pos,
const _T& it_begin,
const _T& it_end);
490 template<
typename _T>
491 iterator push_back(
const _T& value);
500 iterator push_back_empty();
523 template<
typename _T>
524 iterator insert(size_type pos,
const _T& it_begin,
const _T& it_end);
563 template<
typename _T>
564 iterator insert(
const iterator& pos_hint, size_type pos,
const _T& it_begin,
const _T& it_end);
576 template<
typename _T>
577 void get(size_type pos, _T& value)
const;
590 template<
typename _T>
591 _T
get(size_type pos)
const;
607 template<
typename _T>
608 _T release(size_type pos);
626 template<
typename _T>
627 iterator release(size_type pos, _T& value);
645 template<
typename _T>
646 iterator release(
const iterator& pos_hint, size_type pos, _T& value);
673 iterator release_range(size_type start_pos, size_type end_pos);
699 iterator release_range(
const iterator& pos_hint, size_type start_pos, size_type end_pos);
714 position_type position(size_type pos);
732 position_type position(
const iterator& pos_hint, size_type pos);
747 const_position_type position(size_type pos)
const;
765 const_position_type position(
const const_iterator& pos_hint, size_type pos)
const;
791 iterator transfer(size_type start_pos, size_type end_pos,
multi_type_vector& dest, size_type dest_pos);
820 iterator transfer(
const iterator& pos_hint, size_type start_pos, size_type end_pos,
multi_type_vector& dest, size_type dest_pos);
829 mtv::element_t get_type(size_type pos)
const;
842 bool is_empty(size_type pos)
const;
857 iterator set_empty(size_type start_pos, size_type end_pos);
888 iterator set_empty(
const iterator& pos_hint, size_type start_pos, size_type end_pos);
905 void erase(size_type start_pos, size_type end_pos);
925 iterator insert_empty(size_type pos, size_type length);
961 iterator insert_empty(
const iterator& pos_hint, size_type pos, size_type length);
974 size_type size()
const;
993 size_type block_size()
const;
1009 void resize(size_type new_size);
1026 void swap(size_type start_pos, size_type end_pos,
multi_type_vector& other, size_type other_pos);
1031 void shrink_to_fit();
1045 template<
typename _T>
1046 static mtv::element_t get_element_type(
const _T& elem);
1048 #ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG 1049 void dump_blocks(std::ostream& os)
const;
1051 bool check_block_integrity()
const;
1062 void delete_element_block(block* p);
1069 void delete_block(block* p);
1077 void delete_blocks(
typename blocks_type::iterator it,
typename blocks_type::iterator it_end);
1079 template<
typename _T>
1080 iterator set_impl(size_type pos, size_type start_row, size_type block_index,
const _T& value);
1082 template<
typename _T>
1083 iterator release_impl(size_type pos, size_type start_pos, size_type block_index, _T& value);
1104 bool get_block_position(size_type row, size_type& start_pos, size_type& block_index)
const;
1110 void get_block_position(
const const_iterator& pos_hint, size_type pos, size_type& start_pos, size_type& block_index)
const;
1112 template<
typename _T>
1113 void create_new_block_with_new_cell(element_block_type*& data,
const _T& cell);
1115 template<
typename _T>
1116 iterator set_cell_to_middle_of_block(
1117 size_type start_row, size_type block_index, size_type pos_in_block,
const _T& cell);
1119 template<
typename _T>
1120 void append_cell_to_block(size_type block_index,
const _T& cell);
1122 template<
typename _T>
1123 iterator set_cell_to_empty_block(
1124 size_type start_row, size_type block_index, size_type pos_in_block,
const _T& cell);
1126 template<
typename _T>
1127 iterator set_cell_to_block_of_size_one(
1128 size_type start_row, size_type block_index,
const _T& cell);
1130 template<
typename _T>
1131 void set_cell_to_top_of_data_block(
1132 size_type block_index,
const _T& cell);
1134 template<
typename _T>
1135 void set_cell_to_bottom_of_data_block(
1136 size_type block_index,
const _T& cell);
1138 iterator transfer_impl(
1139 size_type start_pos, size_type end_pos, size_type start_pos_in_block1, size_type block_index1,
1145 iterator transfer_single_block(
1146 size_type start_pos, size_type end_pos, size_type start_pos_in_block1, size_type block_index1,
1153 iterator transfer_multi_blocks(
1154 size_type start_pos, size_type end_pos, size_type start_pos_in_block1, size_type block_index1,
1155 size_type start_pos_in_block2, size_type block_index2,
1158 iterator set_empty_impl(
1159 size_type start_pos, size_type end_pos, size_type start_pos_in_block1, size_type block_index1,
1163 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos,
1164 size_type start_pos_in_block1, size_type block_index1, size_type start_pos_in_block2, size_type block_index2,
1165 size_type start_pos_in_dblock1, size_type dblock_index1, size_type start_pos_in_dblock2, size_type dblock_index2);
1167 void swap_single_block(
1168 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos,
1169 size_type start_pos_in_block, size_type block_index, size_type start_pos_in_other_block, size_type other_block_index);
1171 void swap_single_to_multi_blocks(
1172 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos,
1173 size_type start_pos_in_block, size_type block_index, size_type dst_start_pos_in_block1, size_type dst_block_index1,
1174 size_type dst_start_pos_in_block2, size_type dst_block_index2);
1176 void swap_multi_to_multi_blocks(
1177 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos,
1178 size_type start_pos_in_block1, size_type block_index1, size_type start_pos_in_block2, size_type block_index2,
1179 size_type start_pos_in_dblock1, size_type dblock_index1, size_type start_pos_in_dblock2, size_type dblock_index2);
1181 void insert_blocks_at(size_type insert_pos, blocks_type& new_blocks);
1183 void prepare_blocks_to_transfer(blocks_to_transfer& bucket, size_type block_index1, size_type offset1, size_type block_index2, size_type offset2);
1185 iterator set_whole_block_empty(size_type block_index, size_type start_pos_in_block,
bool overwrite);
1187 iterator set_empty_in_single_block(
1188 size_type start_pos, size_type end_pos, size_type block_index, size_type start_pos_in_block,
1191 iterator set_empty_in_multi_blocks(
1192 size_type start_pos, size_type end_pos,
1193 size_type block_index1, size_type start_pos_in_block1,
1194 size_type block_index2, size_type start_pos_in_block2,
bool overwrite);
1196 void erase_impl(size_type start_pos, size_type end_pos);
1197 void erase_in_single_block(
1198 size_type start_pos, size_type end_pos, size_type block_pos, size_type start_pos_in_block);
1200 iterator insert_empty_impl(size_type row, size_type start_pos, size_type block_index, size_type length);
1202 template<
typename _T>
1203 bool set_cells_precheck(
1204 size_type row,
const _T& it_begin,
const _T& it_end, size_type& end_pos);
1206 template<
typename _T>
1207 iterator set_cells_impl(
1208 size_type row, size_type end_row, size_type start_row1, size_type block_index1,
const _T& it_begin,
const _T& it_end);
1210 template<
typename _T>
1211 iterator insert_cells_impl(size_type row, size_type start_row, size_type block_index,
const _T& it_begin,
const _T& it_end);
1213 template<
typename _T>
1214 iterator set_cells_to_single_block(
1215 size_type start_pos, size_type end_pos, size_type block_index,
1216 size_type start_pos_in_block,
const _T& it_begin,
const _T& it_end);
1218 template<
typename _T>
1219 iterator set_cells_to_multi_blocks(
1220 size_type start_pos, size_type end_pos,
1221 size_type block_index1, size_type start_pos_in_block1,
1222 size_type block_index2, size_type start_pos_in_block2,
1223 const _T& it_begin,
const _T& it_end);
1225 template<
typename _T>
1226 iterator set_cells_to_multi_blocks_block1_non_equal(
1227 size_type start_pos, size_type end_pos,
1228 size_type block_index1, size_type start_pos_in_block1,
1229 size_type block_index2, size_type start_pos_in_block2,
1230 const _T& it_begin,
const _T& it_end);
1232 template<
typename _T>
1233 iterator set_cells_to_multi_blocks_block1_non_empty(
1234 size_type start_pos, size_type end_pos,
1235 size_type block_index1, size_type start_pos_in_block1,
1236 size_type block_index2, size_type start_pos_in_block2,
1237 const _T& it_begin,
const _T& it_end);
1247 size_type merge_with_adjacent_blocks(size_type block_index);
1256 bool merge_with_next_block(size_type block_index);
1258 template<
typename _T>
1259 bool append_to_prev_block(
1260 size_type block_index, element_category_type cat, size_type length,
1261 const _T& it_begin,
const _T& it_end);
1263 template<
typename _T>
1264 void insert_cells_to_middle(
1265 size_type row, size_type block_index, size_type start_pos,
1266 const _T& it_begin,
const _T& it_end);
1281 block* set_new_block_to_middle(
1282 size_type block_index, size_type offset, size_type new_block_size,
bool overwrite);
1284 block* get_previous_block_of_type(size_type block_index, element_category_type cat);
1293 block* get_next_block_of_type(size_type block_index, element_category_type cat);
1312 element_block_type* exchange_elements(
1313 const element_block_type& src_data, size_type src_offset, size_type dst_index, size_type dst_offset, size_type len);
1315 void exchange_elements(
1316 const element_block_type& src_data, size_type src_offset,
1317 size_type dst_index1, size_type dst_offset1, size_type dst_index2, size_type dst_offset2,
1318 size_type len, blocks_type& new_blocks);
1320 bool append_empty(size_type len);
1322 inline iterator get_iterator(size_type block_index, size_type start_row)
1324 typename blocks_type::iterator block_pos = m_blocks.begin();
1325 std::advance(block_pos, block_index);
1326 return iterator(block_pos, m_blocks.end(), start_row, block_index);
1329 inline const_iterator get_const_iterator(size_type block_index, size_type start_row)
const 1331 typename blocks_type::const_iterator block_pos = m_blocks.begin();
1332 std::advance(block_pos, block_index);
1333 return const_iterator(block_pos, m_blocks.end(), start_row, block_index);
1337 event_func m_hdl_event;
1338 blocks_type m_blocks;
1339 size_type m_cur_size;
1344 #include "multi_type_vector_def.inl" _EventFunc event_func
Definition: multi_type_vector.hpp:122
Definition: multi_type_vector_types.hpp:88
Definition: multi_type_vector_itr.hpp:109
itr_node value_type
Definition: multi_type_vector.hpp:210
Definition: multi_type_vector_itr.hpp:44
Definition: multi_type_vector.hpp:58
Definition: multi_type_vector_itr.hpp:100
Definition: multi_type_vector_itr.hpp:241
Definition: multi_type_vector_itr.hpp:314
Definition: default_deleter.hpp:33
Definition: multi_type_vector.hpp:96