mdds
multi_type_vector_macro.hpp
1 /*************************************************************************
2  *
3  * Copyright (c) 2012 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 __MDDS_MULTI_TYPE_VECTOR_MACRO_HPP__
29 #define __MDDS_MULTI_TYPE_VECTOR_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(mdds::mtv::base_element_block& block, const _type_&, const _Iter& it_begin, const _Iter& it_end) \
72 { \
73  _block_::prepend_values(block, it_begin, it_end); \
74 } \
75  \
76 template<typename _Iter> \
77 void mdds_mtv_append_values(mdds::mtv::base_element_block& block, const _type_&, const _Iter& it_begin, const _Iter& it_end) \
78 { \
79  _block_::append_values(block, it_begin, it_end); \
80 } \
81  \
82 template<typename _Iter> \
83 void mdds_mtv_assign_values(mdds::mtv::base_element_block& dest, const _type_&, const _Iter& it_begin, const _Iter& it_end) \
84 { \
85  _block_::assign_values(dest, it_begin, it_end); \
86 } \
87  \
88 template<typename _Iter> \
89 void mdds_mtv_insert_values( \
90  mdds::mtv::base_element_block& block, size_t pos, const _type_&, const _Iter& it_begin, const _Iter& it_end) \
91 { \
92  _block_::insert_values(block, pos, it_begin, it_end); \
93 } \
94  \
95 inline mdds::mtv::base_element_block* mdds_mtv_create_new_block(size_t init_size, const _type_& val) \
96 { \
97  return _block_::create_block_with_value(init_size, val); \
98 } \
99  \
100 template<typename _Iter> \
101 mdds::mtv::base_element_block* mdds_mtv_create_new_block(const _type_&, const _Iter& it_begin, const _Iter& it_end) \
102 { \
103  return _block_::create_block_with_values(it_begin, it_end); \
104 }
105 
106 #define MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(_type_,_type_id_,_empty_val_,_block_) \
107  \
108 inline mdds::mtv::element_t mdds_mtv_get_element_type(const _type_*) \
109 { \
110  return _type_id_; \
111 } \
112  \
113 inline void mdds_mtv_get_empty_value(_type_*& val) \
114 { \
115  val = _empty_val_; \
116 } \
117  \
118 inline void mdds_mtv_set_value(mdds::mtv::base_element_block& block, size_t pos, _type_* val) \
119 { \
120  _block_::set_value(block, pos, val); \
121 } \
122  \
123 inline void mdds_mtv_get_value(const mdds::mtv::base_element_block& block, size_t pos, _type_*& val) \
124 { \
125  _block_::get_value(block, pos, val); \
126 } \
127  \
128 template<typename _Iter> \
129 void mdds_mtv_set_values( \
130  mdds::mtv::base_element_block& block, size_t pos, const _type_*, const _Iter& it_begin, const _Iter& it_end) \
131 { \
132  _block_::set_values(block, pos, it_begin, it_end); \
133 } \
134  \
135 inline void mdds_mtv_append_value(mdds::mtv::base_element_block& block, _type_* val) \
136 { \
137  _block_::append_value(block, val); \
138 } \
139  \
140 inline void mdds_mtv_prepend_value(mdds::mtv::base_element_block& block, _type_* val) \
141 { \
142  _block_::prepend_value(block, val); \
143 } \
144  \
145 template<typename _Iter> \
146 void mdds_mtv_prepend_values(mdds::mtv::base_element_block& block, const _type_*, const _Iter& it_begin, const _Iter& it_end) \
147 { \
148  _block_::prepend_values(block, it_begin, it_end); \
149 } \
150  \
151 template<typename _Iter> \
152 void mdds_mtv_append_values(mdds::mtv::base_element_block& block, const _type_*, const _Iter& it_begin, const _Iter& it_end) \
153 { \
154  _block_::append_values(block, it_begin, it_end); \
155 } \
156  \
157 template<typename _Iter> \
158 void mdds_mtv_assign_values(mdds::mtv::base_element_block& dest, const _type_*, const _Iter& it_begin, const _Iter& it_end) \
159 { \
160  _block_::assign_values(dest, it_begin, it_end); \
161 } \
162  \
163 template<typename _Iter> \
164 void mdds_mtv_insert_values( \
165  mdds::mtv::base_element_block& block, size_t pos, const _type_*, const _Iter& it_begin, const _Iter& it_end) \
166 { \
167  _block_::insert_values(block, pos, it_begin, it_end); \
168 } \
169  \
170 inline mdds::mtv::base_element_block* mdds_mtv_create_new_block(size_t init_size, _type_* val) \
171 { \
172  return _block_::create_block_with_value(init_size, val); \
173 } \
174  \
175 template<typename _Iter> \
176 mdds::mtv::base_element_block* mdds_mtv_create_new_block(const _type_*, const _Iter& it_begin, const _Iter& it_end) \
177 { \
178  return _block_::create_block_with_values(it_begin, it_end); \
179 }
180 
181 #endif