mdds
multi_type_vector_custom_func1.hpp
1 /*************************************************************************
2  *
3  * Copyright (c) 2013-2016 Kohei Yoshida
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without
8  * restriction, including without limitation the rights to use,
9  * copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following
12  * conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24  * OTHER DEALINGS IN THE SOFTWARE.
25  *
26  ************************************************************************/
27 
28 #ifndef INCLUDED_MDDS_MULTI_TYPE_VECTOR_CUSTOM_FUNC1_HPP
29 #define INCLUDED_MDDS_MULTI_TYPE_VECTOR_CUSTOM_FUNC1_HPP
30 
31 #include "multi_type_vector_types.hpp"
32 #include "multi_type_vector_trait.hpp"
33 
34 namespace mdds { namespace mtv {
35 
39 template<typename _Block>
41 {
42  static base_element_block* create_new_block(element_t type, size_t init_size)
43  {
44  switch (type)
45  {
46  case _Block::block_type:
47  return _Block::create_block(init_size);
48  default:
49  ;
50  }
51 
52  return element_block_func::create_new_block(type, init_size);
53  }
54 
55  static base_element_block* clone_block(const base_element_block& block)
56  {
57  switch (get_block_type(block))
58  {
59  case _Block::block_type:
60  return _Block::clone_block(block);
61  default:
62  ;
63  }
64 
65  return element_block_func::clone_block(block);
66  }
67 
68  static void delete_block(const base_element_block* p)
69  {
70  if (!p)
71  return;
72 
73  switch (get_block_type(*p))
74  {
75  case _Block::block_type:
76  _Block::delete_block(p);
77  break;
78  default:
79  element_block_func::delete_block(p);
80  }
81  }
82 
83  static void resize_block(base_element_block& block, size_t new_size)
84  {
85  switch (get_block_type(block))
86  {
87  case _Block::block_type:
88  _Block::resize_block(block, new_size);
89  break;
90  default:
91  element_block_func::resize_block(block, new_size);
92  }
93  }
94 
95  static void print_block(const base_element_block& block)
96  {
97  switch (get_block_type(block))
98  {
99  case _Block::block_type:
100  _Block::print_block(block);
101  break;
102  default:
103  element_block_func::print_block(block);
104  }
105  }
106 
107  static void erase(base_element_block& block, size_t pos)
108  {
109  switch (get_block_type(block))
110  {
111  case _Block::block_type:
112  _Block::erase_block(block, pos);
113  break;
114  default:
115  element_block_func::erase(block, pos);
116  }
117  }
118 
119  static void erase(base_element_block& block, size_t pos, size_t size)
120  {
121  switch (get_block_type(block))
122  {
123  case _Block::block_type:
124  _Block::erase_block(block, pos, size);
125  break;
126  default:
127  element_block_func_base::erase(block, pos, size);
128  }
129  }
130 
131  static void append_values_from_block(base_element_block& dest, const base_element_block& src)
132  {
133  switch (get_block_type(dest))
134  {
135  case _Block::block_type:
136  _Block::append_values_from_block(dest, src);
137  break;
138  default:
139  element_block_func_base::append_values_from_block(dest, src);
140  }
141  }
142 
143  static void append_values_from_block(
144  base_element_block& dest, const base_element_block& src, size_t begin_pos, size_t len)
145  {
146  switch (get_block_type(dest))
147  {
148  case _Block::block_type:
149  _Block::append_values_from_block(dest, src, begin_pos, len);
150  break;
151  default:
152  element_block_func_base::append_values_from_block(dest, src, begin_pos, len);
153  }
154  }
155 
156  static void assign_values_from_block(
157  base_element_block& dest, const base_element_block& src, size_t begin_pos, size_t len)
158  {
159  switch (get_block_type(dest))
160  {
161  case _Block::block_type:
162  _Block::assign_values_from_block(dest, src, begin_pos, len);
163  break;
164  default:
165  element_block_func_base::assign_values_from_block(dest, src, begin_pos, len);
166  }
167  }
168 
169  static void prepend_values_from_block(
170  base_element_block& dest, const base_element_block& src, size_t begin_pos, size_t len)
171  {
172  switch (get_block_type(dest))
173  {
174  case _Block::block_type:
175  _Block::prepend_values_from_block(dest, src, begin_pos, len);
176  break;
177  default:
178  element_block_func_base::prepend_values_from_block(dest, src, begin_pos, len);
179  }
180  }
181 
182  static void swap_values(
183  base_element_block& blk1, base_element_block& blk2, size_t pos1, size_t pos2, size_t len)
184  {
185  switch (get_block_type(blk1))
186  {
187  case _Block::block_type:
188  _Block::swap_values(blk1, blk2, pos1, pos2, len);
189  break;
190  default:
191  element_block_func_base::swap_values(blk1, blk2, pos1, pos2, len);
192  }
193  }
194 
195  static bool equal_block(
196  const base_element_block& left, const base_element_block& right)
197  {
198  if (get_block_type(left) == _Block::block_type)
199  {
200  if (get_block_type(right) != _Block::block_type)
201  return false;
202 
203  return _Block::get(left) == _Block::get(right);
204  }
205  else if (mtv::get_block_type(right) == _Block::block_type)
206  return false;
207 
208  return element_block_func::equal_block(left, right);
209  }
210 
211  static void overwrite_values(base_element_block& block, size_t pos, size_t len)
212  {
213  switch (get_block_type(block))
214  {
215  case _Block::block_type:
216  _Block::overwrite_values(block, pos, len);
217  break;
218  default:
219  element_block_func::overwrite_values(block, pos, len);
220  }
221  }
222 
223  static void shrink_to_fit(base_element_block& block)
224  {
225  switch (get_block_type(block))
226  {
227  case _Block::block_type:
228  _Block::shrink_to_fit(block);
229  break;
230  default:
231  element_block_func::shrink_to_fit(block);
232  }
233  }
234 
235  static size_t size(const base_element_block& block)
236  {
237  switch (get_block_type(block))
238  {
239  case _Block::block_type:
240  return _Block::size(block);
241  default:
242  return element_block_func::size(block);
243  }
244  }
245 };
246 
247 }}
248 
249 #endif
Definition: multi_type_vector_types.hpp:87
Definition: multi_type_vector_custom_func1.hpp:40
Definition: flat_segment_tree.hpp:46
static void overwrite_values(base_element_block &block, size_t pos, size_t len)
Definition: multi_type_vector_trait.hpp:618