mdds
macro.hpp
1/*************************************************************************
2 *
3 * Copyright (c) 2012-2021 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_DIR_MACRO_HPP
29#define INCLUDED_MDDS_MULTI_TYPE_VECTOR_DIR_MACRO_HPP
30
44#define MDDS_MTV_DEFINE_ELEMENT_CALLBACKS(type, type_id, empty_value, block_type) \
45\
46 inline mdds::mtv::element_t mdds_mtv_get_element_type(const type&) \
47 { \
48 return type_id; \
49 } \
50\
51 inline void mdds_mtv_get_empty_value(type& val) \
52 { \
53 val = empty_value; \
54 } \
55\
56 inline void mdds_mtv_set_value(mdds::mtv::base_element_block& block, size_t pos, const type& val) \
57 { \
58 block_type::set_value(block, pos, val); \
59 } \
60\
61 inline void mdds_mtv_get_value(const mdds::mtv::base_element_block& block, size_t pos, type& val) \
62 { \
63 block_type::get_value(block, pos, val); \
64 } \
65\
66 template<typename _Iter> \
67 void mdds_mtv_set_values( \
68 mdds::mtv::base_element_block& block, size_t pos, const type&, const _Iter& it_begin, const _Iter& it_end) \
69 { \
70 block_type::set_values(block, pos, it_begin, it_end); \
71 } \
72\
73 inline void mdds_mtv_append_value(mdds::mtv::base_element_block& block, const type& val) \
74 { \
75 block_type::append_value(block, val); \
76 } \
77\
78 inline void mdds_mtv_prepend_value(mdds::mtv::base_element_block& block, const type& val) \
79 { \
80 block_type::prepend_value(block, val); \
81 } \
82\
83 template<typename _Iter> \
84 void mdds_mtv_prepend_values( \
85 mdds::mtv::base_element_block& block, const type&, const _Iter& it_begin, const _Iter& it_end) \
86 { \
87 block_type::prepend_values(block, it_begin, it_end); \
88 } \
89\
90 template<typename _Iter> \
91 void mdds_mtv_append_values( \
92 mdds::mtv::base_element_block& block, const type&, const _Iter& it_begin, const _Iter& it_end) \
93 { \
94 block_type::append_values(block, it_begin, it_end); \
95 } \
96\
97 template<typename _Iter> \
98 void mdds_mtv_assign_values( \
99 mdds::mtv::base_element_block& dest, const type&, const _Iter& it_begin, const _Iter& it_end) \
100 { \
101 block_type::assign_values(dest, it_begin, it_end); \
102 } \
103\
104 template<typename _Iter> \
105 void mdds_mtv_insert_values( \
106 mdds::mtv::base_element_block& block, size_t pos, const type&, const _Iter& it_begin, const _Iter& it_end) \
107 { \
108 block_type::insert_values(block, pos, it_begin, it_end); \
109 } \
110\
111 inline mdds::mtv::base_element_block* mdds_mtv_create_new_block(size_t init_size, const type& val) \
112 { \
113 return block_type::create_block_with_value(init_size, val); \
114 } \
115\
116 template<typename _Iter> \
117 mdds::mtv::base_element_block* mdds_mtv_create_new_block(const type&, const _Iter& it_begin, const _Iter& it_end) \
118 { \
119 return block_type::create_block_with_values(it_begin, it_end); \
120 }
121
129#define MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(type, type_id, empty_value, block_type) \
130\
131 inline mdds::mtv::element_t mdds_mtv_get_element_type(const type*) \
132 { \
133 return type_id; \
134 } \
135\
136 inline void mdds_mtv_get_empty_value(type*& val) \
137 { \
138 val = empty_value; \
139 } \
140\
141 inline void mdds_mtv_set_value(mdds::mtv::base_element_block& block, size_t pos, type* val) \
142 { \
143 block_type::set_value(block, pos, val); \
144 } \
145\
146 inline void mdds_mtv_get_value(const mdds::mtv::base_element_block& block, size_t pos, type*& val) \
147 { \
148 block_type::get_value(block, pos, val); \
149 } \
150\
151 template<typename _Iter> \
152 void mdds_mtv_set_values( \
153 mdds::mtv::base_element_block& block, size_t pos, const type*, const _Iter& it_begin, const _Iter& it_end) \
154 { \
155 block_type::set_values(block, pos, it_begin, it_end); \
156 } \
157\
158 inline void mdds_mtv_append_value(mdds::mtv::base_element_block& block, type* val) \
159 { \
160 block_type::append_value(block, val); \
161 } \
162\
163 inline void mdds_mtv_prepend_value(mdds::mtv::base_element_block& block, type* val) \
164 { \
165 block_type::prepend_value(block, val); \
166 } \
167\
168 template<typename _Iter> \
169 void mdds_mtv_prepend_values( \
170 mdds::mtv::base_element_block& block, const type*, const _Iter& it_begin, const _Iter& it_end) \
171 { \
172 block_type::prepend_values(block, it_begin, it_end); \
173 } \
174\
175 template<typename _Iter> \
176 void mdds_mtv_append_values( \
177 mdds::mtv::base_element_block& block, const type*, const _Iter& it_begin, const _Iter& it_end) \
178 { \
179 block_type::append_values(block, it_begin, it_end); \
180 } \
181\
182 template<typename _Iter> \
183 void mdds_mtv_assign_values( \
184 mdds::mtv::base_element_block& dest, const type*, const _Iter& it_begin, const _Iter& it_end) \
185 { \
186 block_type::assign_values(dest, it_begin, it_end); \
187 } \
188\
189 template<typename _Iter> \
190 void mdds_mtv_insert_values( \
191 mdds::mtv::base_element_block& block, size_t pos, const type*, const _Iter& it_begin, const _Iter& it_end) \
192 { \
193 block_type::insert_values(block, pos, it_begin, it_end); \
194 } \
195\
196 inline mdds::mtv::base_element_block* mdds_mtv_create_new_block(size_t init_size, type* val) \
197 { \
198 return block_type::create_block_with_value(init_size, val); \
199 } \
200\
201 template<typename _Iter> \
202 mdds::mtv::base_element_block* mdds_mtv_create_new_block(const type*, const _Iter& it_begin, const _Iter& it_end) \
203 { \
204 return block_type::create_block_with_values(it_begin, it_end); \
205 }
206
207#endif