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 
31 #define MDDS_MTV_DEFINE_ELEMENT_CALLBACKS(_type_, _type_id_, _empty_val_, _block_) \
32 \
33  inline mdds::mtv::element_t mdds_mtv_get_element_type(const _type_&) \
34  { \
35  return _type_id_; \
36  } \
37 \
38  inline void mdds_mtv_get_empty_value(_type_& val) \
39  { \
40  val = _empty_val_; \
41  } \
42 \
43  inline void mdds_mtv_set_value(mdds::mtv::base_element_block& block, size_t pos, const _type_& val) \
44  { \
45  _block_::set_value(block, pos, val); \
46  } \
47 \
48  inline void mdds_mtv_get_value(const mdds::mtv::base_element_block& block, size_t pos, _type_& val) \
49  { \
50  _block_::get_value(block, pos, val); \
51  } \
52 \
53  template<typename _Iter> \
54  void mdds_mtv_set_values( \
55  mdds::mtv::base_element_block& block, size_t pos, const _type_&, const _Iter& it_begin, const _Iter& it_end) \
56  { \
57  _block_::set_values(block, pos, it_begin, it_end); \
58  } \
59 \
60  inline void mdds_mtv_append_value(mdds::mtv::base_element_block& block, const _type_& val) \
61  { \
62  _block_::append_value(block, val); \
63  } \
64 \
65  inline void mdds_mtv_prepend_value(mdds::mtv::base_element_block& block, const _type_& val) \
66  { \
67  _block_::prepend_value(block, val); \
68  } \
69 \
70  template<typename _Iter> \
71  void mdds_mtv_prepend_values( \
72  mdds::mtv::base_element_block& block, const _type_&, const _Iter& it_begin, const _Iter& it_end) \
73  { \
74  _block_::prepend_values(block, it_begin, it_end); \
75  } \
76 \
77  template<typename _Iter> \
78  void mdds_mtv_append_values( \
79  mdds::mtv::base_element_block& block, const _type_&, const _Iter& it_begin, const _Iter& it_end) \
80  { \
81  _block_::append_values(block, it_begin, it_end); \
82  } \
83 \
84  template<typename _Iter> \
85  void mdds_mtv_assign_values( \
86  mdds::mtv::base_element_block& dest, const _type_&, const _Iter& it_begin, const _Iter& it_end) \
87  { \
88  _block_::assign_values(dest, it_begin, it_end); \
89  } \
90 \
91  template<typename _Iter> \
92  void mdds_mtv_insert_values( \
93  mdds::mtv::base_element_block& block, size_t pos, const _type_&, const _Iter& it_begin, const _Iter& it_end) \
94  { \
95  _block_::insert_values(block, pos, it_begin, it_end); \
96  } \
97 \
98  inline mdds::mtv::base_element_block* mdds_mtv_create_new_block(size_t init_size, const _type_& val) \
99  { \
100  return _block_::create_block_with_value(init_size, val); \
101  } \
102 \
103  template<typename _Iter> \
104  mdds::mtv::base_element_block* mdds_mtv_create_new_block( \
105  const _type_&, const _Iter& it_begin, const _Iter& it_end) \
106  { \
107  return _block_::create_block_with_values(it_begin, it_end); \
108  }
109 
110 #define MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(_type_, _type_id_, _empty_val_, _block_) \
111 \
112  inline mdds::mtv::element_t mdds_mtv_get_element_type(const _type_*) \
113  { \
114  return _type_id_; \
115  } \
116 \
117  inline void mdds_mtv_get_empty_value(_type_*& val) \
118  { \
119  val = _empty_val_; \
120  } \
121 \
122  inline void mdds_mtv_set_value(mdds::mtv::base_element_block& block, size_t pos, _type_* val) \
123  { \
124  _block_::set_value(block, pos, val); \
125  } \
126 \
127  inline void mdds_mtv_get_value(const mdds::mtv::base_element_block& block, size_t pos, _type_*& val) \
128  { \
129  _block_::get_value(block, pos, val); \
130  } \
131 \
132  template<typename _Iter> \
133  void mdds_mtv_set_values( \
134  mdds::mtv::base_element_block& block, size_t pos, const _type_*, const _Iter& it_begin, const _Iter& it_end) \
135  { \
136  _block_::set_values(block, pos, it_begin, it_end); \
137  } \
138 \
139  inline void mdds_mtv_append_value(mdds::mtv::base_element_block& block, _type_* val) \
140  { \
141  _block_::append_value(block, val); \
142  } \
143 \
144  inline void mdds_mtv_prepend_value(mdds::mtv::base_element_block& block, _type_* val) \
145  { \
146  _block_::prepend_value(block, val); \
147  } \
148 \
149  template<typename _Iter> \
150  void mdds_mtv_prepend_values( \
151  mdds::mtv::base_element_block& block, const _type_*, const _Iter& it_begin, const _Iter& it_end) \
152  { \
153  _block_::prepend_values(block, it_begin, it_end); \
154  } \
155 \
156  template<typename _Iter> \
157  void mdds_mtv_append_values( \
158  mdds::mtv::base_element_block& block, const _type_*, const _Iter& it_begin, const _Iter& it_end) \
159  { \
160  _block_::append_values(block, it_begin, it_end); \
161  } \
162 \
163  template<typename _Iter> \
164  void mdds_mtv_assign_values( \
165  mdds::mtv::base_element_block& dest, const _type_*, const _Iter& it_begin, const _Iter& it_end) \
166  { \
167  _block_::assign_values(dest, it_begin, it_end); \
168  } \
169 \
170  template<typename _Iter> \
171  void mdds_mtv_insert_values( \
172  mdds::mtv::base_element_block& block, size_t pos, const _type_*, const _Iter& it_begin, const _Iter& it_end) \
173  { \
174  _block_::insert_values(block, pos, it_begin, it_end); \
175  } \
176 \
177  inline mdds::mtv::base_element_block* mdds_mtv_create_new_block(size_t init_size, _type_* val) \
178  { \
179  return _block_::create_block_with_value(init_size, val); \
180  } \
181 \
182  template<typename _Iter> \
183  mdds::mtv::base_element_block* mdds_mtv_create_new_block( \
184  const _type_*, const _Iter& it_begin, const _Iter& it_end) \
185  { \
186  return _block_::create_block_with_values(it_begin, it_end); \
187  }
188 
189 #endif