32#include "../global.hpp"
34#include <unordered_map>
38namespace mdds {
namespace mtv {
42inline void throw_unknown_block(
const char* func,
const mdds::mtv::element_t type)
44 std::ostringstream os;
45 os << func <<
": failed to map to a element block function (type=" << type <<
")";
46 throw general_error(os.str());
49template<
typename Ret,
typename... Args>
51 const std::unordered_map<element_t, std::function<Ret(Args...)>>& func_map, element_t type,
52 const char* src_func_name)
54 auto it = func_map.find(type);
55 if (it == func_map.end())
56 detail::throw_unknown_block(src_func_name, type);
63template<
typename... Ts>
68 static const std::unordered_map<element_t, std::function<
base_element_block*(std::size_t)>> func_map{
69 {Ts::block_type, Ts::create_block}...};
71 auto& f = detail::find_func(func_map, type, __func__);
78 func_map{{Ts::block_type, Ts::clone_block}...};
80 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
89 static const std::unordered_map<element_t, std::function<void(
const base_element_block*)>> func_map{
90 {Ts::block_type, Ts::delete_block}...};
94 auto& f = detail::find_func(func_map, get_block_type(*p), __func__);
100 static const std::unordered_map<element_t, std::function<void(
base_element_block&, std::size_t)>> func_map{
101 {Ts::block_type, Ts::resize_block}...};
103 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
109 static const std::unordered_map<element_t, std::function<void(
const base_element_block&)>> func_map{
110 {Ts::block_type, Ts::print_block}...};
112 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
118 static const std::unordered_map<element_t, std::function<void(
base_element_block&, std::size_t)>> func_map{
119 {Ts::block_type, Ts::erase_value}...};
121 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
127 static const std::unordered_map<element_t, std::function<void(
base_element_block&, std::size_t, std::size_t)>>
128 func_map{{Ts::block_type, Ts::erase_values}...};
130 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
137 func_map{{Ts::block_type, Ts::append_block}...};
139 auto& f = detail::find_func(func_map, get_block_type(dest), __func__);
143 static void append_values_from_block(
147 static const std::unordered_map<element_t, func_type> func_map{
148 {Ts::block_type, Ts::append_values_from_block}...};
150 auto& f = detail::find_func(func_map, get_block_type(dest), __func__);
151 f(dest, src, begin_pos, len);
154 static void assign_values_from_block(
158 static const std::unordered_map<element_t, func_type> func_map{
159 {Ts::block_type, Ts::assign_values_from_block}...};
161 auto& f = detail::find_func(func_map, get_block_type(dest), __func__);
162 f(dest, src, begin_pos, len);
165 static void prepend_values_from_block(
169 static const std::unordered_map<element_t, func_type> func_map{
170 {Ts::block_type, Ts::prepend_values_from_block}...};
172 auto& f = detail::find_func(func_map, get_block_type(dest), __func__);
173 f(dest, src, begin_pos, len);
176 static void swap_values(
179 element_t blk1_type = get_block_type(blk1);
180 assert(blk1_type == get_block_type(blk2));
184 static const std::unordered_map<element_t, func_type> func_map{{Ts::block_type, Ts::swap_values}...};
186 auto& f = detail::find_func(func_map, blk1_type, __func__);
187 f(blk1, blk2, pos1, pos2, len);
192 element_t block_type = get_block_type(left);
193 if (block_type != get_block_type(right))
197 static const std::unordered_map<element_t, func_type> func_map{{Ts::block_type, Ts::equal_block}...};
199 auto& f = detail::find_func(func_map, block_type, __func__);
200 return f(left, right);
203 static void overwrite_values(
base_element_block& block, std::size_t pos, std::size_t len)
206 static const std::unordered_map<element_t, func_type> func_map{{Ts::block_type, Ts::overwrite_values}...};
208 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
215 static const std::unordered_map<element_t, func_type> func_map{{Ts::block_type, Ts::shrink_to_fit}...};
217 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
224 static const std::unordered_map<element_t, func_type> func_map{{Ts::block_type, Ts::size}...};
226 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
Definition: types.hpp:160
Definition: block_funcs.hpp:65