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