10 #include "../global.hpp"
12 #include <unordered_map>
16 namespace mdds {
namespace mtv {
20 inline void throw_unknown_block(
const char* func,
const mdds::mtv::element_t type)
22 std::ostringstream os;
23 os << func <<
": failed to map to a element block function (type=" << type <<
")";
24 throw general_error(os.str());
27 template<
typename Ret,
typename... Args>
29 const std::unordered_map<element_t, std::function<Ret(Args...)>>& func_map, element_t type,
30 const char* src_func_name)
32 auto it = func_map.find(type);
33 if (it == func_map.end())
34 detail::throw_unknown_block(src_func_name, type);
41 template<
typename... Ts>
46 static const std::unordered_map<element_t, std::function<base_element_block*(std::size_t)>> func_map{
47 {Ts::block_type, Ts::create_block}...};
49 auto& f = detail::find_func(func_map, type, __func__);
55 static const std::unordered_map<element_t, std::function<base_element_block*(const base_element_block&)>>
56 func_map{{Ts::block_type, Ts::copy_block}...};
58 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
64 static const std::unordered_map<element_t, std::function<base_element_block*(const base_element_block&)>>
65 func_map{{Ts::block_type, Ts::clone_block}...};
67 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
76 static const std::unordered_map<element_t, std::function<void(const base_element_block*)>> func_map{
77 {Ts::block_type, Ts::delete_block}...};
81 auto& f = detail::find_func(func_map, get_block_type(*p), __func__);
87 static const std::unordered_map<element_t, std::function<void(base_element_block&, std::size_t)>> func_map{
88 {Ts::block_type, Ts::resize_block}...};
90 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
96 static const std::unordered_map<element_t, std::function<void(const base_element_block&)>> func_map{
97 {Ts::block_type, Ts::print_block}...};
99 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
105 static const std::unordered_map<element_t, std::function<void(base_element_block&, std::size_t)>> func_map{
106 {Ts::block_type, Ts::erase_value}...};
108 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
114 static const std::unordered_map<element_t, std::function<void(base_element_block&, std::size_t, std::size_t)>>
115 func_map{{Ts::block_type, Ts::erase_values}...};
117 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
123 static const std::unordered_map<element_t, std::function<void(base_element_block&, const base_element_block&)>>
124 func_map{{Ts::block_type, Ts::append_block}...};
126 auto& f = detail::find_func(func_map, get_block_type(dest), __func__);
130 static void append_values_from_block(
133 using func_type = std::function<void(base_element_block&, const base_element_block&, std::size_t, std::size_t)>;
134 static const std::unordered_map<element_t, func_type> func_map{
135 {Ts::block_type, Ts::append_values_from_block}...};
137 auto& f = detail::find_func(func_map, get_block_type(dest), __func__);
138 f(dest, src, begin_pos, len);
141 static void assign_values_from_block(
144 using func_type = std::function<void(base_element_block&, const base_element_block&, std::size_t, std::size_t)>;
145 static const std::unordered_map<element_t, func_type> func_map{
146 {Ts::block_type, Ts::assign_values_from_block}...};
148 auto& f = detail::find_func(func_map, get_block_type(dest), __func__);
149 f(dest, src, begin_pos, len);
152 static void prepend_values_from_block(
155 using func_type = std::function<void(base_element_block&, const base_element_block&, std::size_t, std::size_t)>;
156 static const std::unordered_map<element_t, func_type> func_map{
157 {Ts::block_type, Ts::prepend_values_from_block}...};
159 auto& f = detail::find_func(func_map, get_block_type(dest), __func__);
160 f(dest, src, begin_pos, len);
163 static void swap_values(
166 element_t blk1_type = get_block_type(blk1);
167 assert(blk1_type == get_block_type(blk2));
170 std::function<void(base_element_block&, base_element_block&, std::size_t, std::size_t, std::size_t)>;
171 static const std::unordered_map<element_t, func_type> func_map{{Ts::block_type, Ts::swap_values}...};
173 auto& f = detail::find_func(func_map, blk1_type, __func__);
174 f(blk1, blk2, pos1, pos2, len);
179 element_t block_type = get_block_type(left);
180 if (block_type != get_block_type(right))
183 using func_type = std::function<bool(const base_element_block&, const base_element_block&)>;
184 static const std::unordered_map<element_t, func_type> func_map{{Ts::block_type, Ts::equal_block}...};
186 auto& f = detail::find_func(func_map, block_type, __func__);
187 return f(left, right);
190 static void overwrite_values(
base_element_block& block, std::size_t pos, std::size_t len)
192 using func_type = std::function<void(base_element_block&, std::size_t, std::size_t)>;
193 static const std::unordered_map<element_t, func_type> func_map{{Ts::block_type, Ts::overwrite_values}...};
195 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
201 using func_type = std::function<void(base_element_block&)>;
202 static const std::unordered_map<element_t, func_type> func_map{{Ts::block_type, Ts::shrink_to_fit}...};
204 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
210 using func_type = std::function<std::size_t(const base_element_block&)>;
211 static const std::unordered_map<element_t, func_type> func_map{{Ts::block_type, Ts::size}...};
213 auto& f = detail::find_func(func_map, get_block_type(block), __func__);
Definition: types.hpp:157
Definition: cref_wrapper.hpp:12
Definition: block_funcs.hpp:42
Definition: types.hpp:134