/src/msgpack-c/include/msgpack/v1/adaptor/fixint.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // MessagePack for C++ static resolution routine |
3 | | // |
4 | | // Copyright (C) 2016 FURUHASHI Sadayuki and KONDO Takatoshi |
5 | | // |
6 | | // Distributed under the Boost Software License, Version 1.0. |
7 | | // (See accompanying file LICENSE_1_0.txt or copy at |
8 | | // http://www.boost.org/LICENSE_1_0.txt) |
9 | | // |
10 | | #ifndef MSGPACK_V1_TYPE_FIXINT_HPP |
11 | | #define MSGPACK_V1_TYPE_FIXINT_HPP |
12 | | |
13 | | #include "msgpack/v1/adaptor/fixint_decl.hpp" |
14 | | |
15 | | namespace msgpack { |
16 | | |
17 | | /// @cond |
18 | | MSGPACK_API_VERSION_NAMESPACE(v1) { |
19 | | /// @endcond |
20 | | |
21 | | namespace type { |
22 | | |
23 | | template <typename T> |
24 | | struct fix_int { |
25 | | typedef T value_type; |
26 | | fix_int() : value(0) { } |
27 | | fix_int(T value) : value(value) { } |
28 | | |
29 | | operator T() const { return value; } |
30 | | |
31 | 0 | T get() const { return value; } Unexecuted instantiation: msgpack::v1::type::fix_int<signed char>::get() const Unexecuted instantiation: msgpack::v1::type::fix_int<short>::get() const Unexecuted instantiation: msgpack::v1::type::fix_int<int>::get() const Unexecuted instantiation: msgpack::v1::type::fix_int<long>::get() const Unexecuted instantiation: msgpack::v1::type::fix_int<unsigned char>::get() const Unexecuted instantiation: msgpack::v1::type::fix_int<unsigned short>::get() const Unexecuted instantiation: msgpack::v1::type::fix_int<unsigned int>::get() const Unexecuted instantiation: msgpack::v1::type::fix_int<unsigned long>::get() const |
32 | | |
33 | | private: |
34 | | T value; |
35 | | }; |
36 | | |
37 | | } // namespace type |
38 | | |
39 | | namespace adaptor { |
40 | | |
41 | | template <> |
42 | | struct convert<type::fix_int8> { |
43 | | msgpack::object const& operator()(msgpack::object const& o, type::fix_int8& v) const |
44 | 0 | { v = type::detail::convert_integer<int8_t>(o); return o; } |
45 | | }; |
46 | | |
47 | | template <> |
48 | | struct convert<type::fix_int16> { |
49 | | msgpack::object const& operator()(msgpack::object const& o, type::fix_int16& v) const |
50 | 0 | { v = type::detail::convert_integer<int16_t>(o); return o; } |
51 | | }; |
52 | | |
53 | | template <> |
54 | | struct convert<type::fix_int32> { |
55 | | msgpack::object const& operator()(msgpack::object const& o, type::fix_int32& v) const |
56 | 0 | { v = type::detail::convert_integer<int32_t>(o); return o; } |
57 | | }; |
58 | | |
59 | | template <> |
60 | | struct convert<type::fix_int64> { |
61 | | msgpack::object const& operator()(msgpack::object const& o, type::fix_int64& v) const |
62 | 0 | { v = type::detail::convert_integer<int64_t>(o); return o; } |
63 | | }; |
64 | | |
65 | | |
66 | | template <> |
67 | | struct convert<type::fix_uint8> { |
68 | | msgpack::object const& operator()(msgpack::object const& o, type::fix_uint8& v) const |
69 | 0 | { v = type::detail::convert_integer<uint8_t>(o); return o; } |
70 | | }; |
71 | | |
72 | | template <> |
73 | | struct convert<type::fix_uint16> { |
74 | | msgpack::object const& operator()(msgpack::object const& o, type::fix_uint16& v) const |
75 | 0 | { v = type::detail::convert_integer<uint16_t>(o); return o; } |
76 | | }; |
77 | | |
78 | | template <> |
79 | | struct convert<type::fix_uint32> { |
80 | | msgpack::object const& operator()(msgpack::object const& o, type::fix_uint32& v) const |
81 | 0 | { v = type::detail::convert_integer<uint32_t>(o); return o; } |
82 | | }; |
83 | | |
84 | | template <> |
85 | | struct convert<type::fix_uint64> { |
86 | | msgpack::object const& operator()(msgpack::object const& o, type::fix_uint64& v) const |
87 | 0 | { v = type::detail::convert_integer<uint64_t>(o); return o; } |
88 | | }; |
89 | | |
90 | | template <> |
91 | | struct pack<type::fix_int8> { |
92 | | template <typename Stream> |
93 | | msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int8& v) const |
94 | | { o.pack_fix_int8(v); return o; } |
95 | | }; |
96 | | |
97 | | template <> |
98 | | struct pack<type::fix_int16> { |
99 | | template <typename Stream> |
100 | | msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int16& v) const |
101 | | { o.pack_fix_int16(v); return o; } |
102 | | }; |
103 | | |
104 | | template <> |
105 | | struct pack<type::fix_int32> { |
106 | | template <typename Stream> |
107 | | msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int32& v) const |
108 | | { o.pack_fix_int32(v); return o; } |
109 | | }; |
110 | | |
111 | | template <> |
112 | | struct pack<type::fix_int64> { |
113 | | template <typename Stream> |
114 | | msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int64& v) const |
115 | | { o.pack_fix_int64(v); return o; } |
116 | | }; |
117 | | |
118 | | |
119 | | template <> |
120 | | struct pack<type::fix_uint8> { |
121 | | template <typename Stream> |
122 | | msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint8& v) const |
123 | | { o.pack_fix_uint8(v); return o; } |
124 | | }; |
125 | | |
126 | | template <> |
127 | | struct pack<type::fix_uint16> { |
128 | | template <typename Stream> |
129 | | msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint16& v) const |
130 | | { o.pack_fix_uint16(v); return o; } |
131 | | }; |
132 | | |
133 | | template <> |
134 | | struct pack<type::fix_uint32> { |
135 | | template <typename Stream> |
136 | | msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint32& v) const |
137 | | { o.pack_fix_uint32(v); return o; } |
138 | | }; |
139 | | |
140 | | template <> |
141 | | struct pack<type::fix_uint64> { |
142 | | template <typename Stream> |
143 | | msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint64& v) const |
144 | | { o.pack_fix_uint64(v); return o; } |
145 | | }; |
146 | | |
147 | | template <> |
148 | | struct object<type::fix_int8> { |
149 | 0 | void operator()(msgpack::object& o, type::fix_int8 v) const { |
150 | 0 | if (v.get() < 0) { |
151 | 0 | o.type = msgpack::type::NEGATIVE_INTEGER; |
152 | 0 | o.via.i64 = v.get(); |
153 | 0 | } |
154 | 0 | else { |
155 | 0 | o.type = msgpack::type::POSITIVE_INTEGER; |
156 | 0 | o.via.u64 = static_cast<uint64_t>(v.get()); |
157 | 0 | } |
158 | 0 | } |
159 | | }; |
160 | | |
161 | | template <> |
162 | | struct object<type::fix_int16> { |
163 | 0 | void operator()(msgpack::object& o, type::fix_int16 v) const { |
164 | 0 | if(v.get() < 0) { |
165 | 0 | o.type = msgpack::type::NEGATIVE_INTEGER; |
166 | 0 | o.via.i64 = v.get(); |
167 | 0 | } |
168 | 0 | else { |
169 | 0 | o.type = msgpack::type::POSITIVE_INTEGER; |
170 | 0 | o.via.u64 = static_cast<uint64_t>(v.get()); |
171 | 0 | } |
172 | 0 | } |
173 | | }; |
174 | | |
175 | | template <> |
176 | | struct object<type::fix_int32> { |
177 | 0 | void operator()(msgpack::object& o, type::fix_int32 v) const { |
178 | 0 | if (v.get() < 0) { |
179 | 0 | o.type = msgpack::type::NEGATIVE_INTEGER; |
180 | 0 | o.via.i64 = v.get(); |
181 | 0 | } |
182 | 0 | else { |
183 | 0 | o.type = msgpack::type::POSITIVE_INTEGER; |
184 | 0 | o.via.u64 = static_cast<uint64_t>(v.get()); |
185 | 0 | } |
186 | 0 | } |
187 | | }; |
188 | | |
189 | | template <> |
190 | | struct object<type::fix_int64> { |
191 | 0 | void operator()(msgpack::object& o, type::fix_int64 v) const { |
192 | 0 | if (v.get() < 0) { |
193 | 0 | o.type = msgpack::type::NEGATIVE_INTEGER; |
194 | 0 | o.via.i64 = v.get(); |
195 | 0 | } |
196 | 0 | else { |
197 | 0 | o.type = msgpack::type::POSITIVE_INTEGER; |
198 | 0 | o.via.u64 = static_cast<uint64_t>(v.get()); |
199 | 0 | } |
200 | 0 | } |
201 | | }; |
202 | | |
203 | | template <> |
204 | | struct object<type::fix_uint8> { |
205 | 0 | void operator()(msgpack::object& o, type::fix_uint8 v) const { |
206 | 0 | o.type = msgpack::type::POSITIVE_INTEGER; |
207 | 0 | o.via.u64 = v.get(); |
208 | 0 | } |
209 | | }; |
210 | | |
211 | | template <> |
212 | | struct object<type::fix_uint16> { |
213 | 0 | void operator()(msgpack::object& o, type::fix_uint16 v) const { |
214 | 0 | o.type = msgpack::type::POSITIVE_INTEGER; |
215 | 0 | o.via.u64 = v.get(); |
216 | 0 | } |
217 | | }; |
218 | | |
219 | | template <> |
220 | | struct object<type::fix_uint32> { |
221 | 0 | void operator()(msgpack::object& o, type::fix_uint32 v) const { |
222 | 0 | o.type = msgpack::type::POSITIVE_INTEGER; |
223 | 0 | o.via.u64 = v.get(); |
224 | 0 | } |
225 | | }; |
226 | | |
227 | | template <> |
228 | | struct object<type::fix_uint64> { |
229 | 0 | void operator()(msgpack::object& o, type::fix_uint64 v) const { |
230 | 0 | o.type = msgpack::type::POSITIVE_INTEGER; |
231 | 0 | o.via.u64 = v.get(); |
232 | 0 | } |
233 | | }; |
234 | | |
235 | | template <> |
236 | | struct object_with_zone<type::fix_int8> { |
237 | 0 | void operator()(msgpack::object::with_zone& o, type::fix_int8 v) const { |
238 | 0 | static_cast<msgpack::object&>(o) << v; |
239 | 0 | } |
240 | | }; |
241 | | |
242 | | template <> |
243 | | struct object_with_zone<type::fix_int16> { |
244 | 0 | void operator()(msgpack::object::with_zone& o, type::fix_int16 v) const { |
245 | 0 | static_cast<msgpack::object&>(o) << v; |
246 | 0 | } |
247 | | }; |
248 | | |
249 | | template <> |
250 | | struct object_with_zone<type::fix_int32> { |
251 | 0 | void operator()(msgpack::object::with_zone& o, type::fix_int32 v) const { |
252 | 0 | static_cast<msgpack::object&>(o) << v; |
253 | 0 | } |
254 | | }; |
255 | | |
256 | | template <> |
257 | | struct object_with_zone<type::fix_int64> { |
258 | 0 | void operator()(msgpack::object::with_zone& o, type::fix_int64 v) const { |
259 | 0 | static_cast<msgpack::object&>(o) << v; |
260 | 0 | } |
261 | | }; |
262 | | |
263 | | |
264 | | template <> |
265 | | struct object_with_zone<type::fix_uint8> { |
266 | 0 | void operator()(msgpack::object::with_zone& o, type::fix_uint8 v) const { |
267 | 0 | static_cast<msgpack::object&>(o) << v; |
268 | 0 | } |
269 | | }; |
270 | | |
271 | | template <> |
272 | | struct object_with_zone<type::fix_uint16> { |
273 | 0 | void operator()(msgpack::object::with_zone& o, type::fix_uint16 v) const { |
274 | 0 | static_cast<msgpack::object&>(o) << v; |
275 | 0 | } |
276 | | }; |
277 | | |
278 | | template <> |
279 | | struct object_with_zone<type::fix_uint32> { |
280 | 0 | void operator()(msgpack::object::with_zone& o, type::fix_uint32 v) const { |
281 | 0 | static_cast<msgpack::object&>(o) << v; |
282 | 0 | } |
283 | | }; |
284 | | |
285 | | template <> |
286 | | struct object_with_zone<type::fix_uint64> { |
287 | 0 | void operator()(msgpack::object::with_zone& o, type::fix_uint64 v) const { |
288 | 0 | static_cast<msgpack::object&>(o) << v; |
289 | 0 | } |
290 | | }; |
291 | | |
292 | | } // namespace adaptor |
293 | | |
294 | | /// @cond |
295 | | } // MSGPACK_API_VERSION_NAMESPACE(v1) |
296 | | /// @endcond |
297 | | |
298 | | } // namespace msgpack |
299 | | |
300 | | #endif // MSGPACK_V1_TYPE_FIXINT_HPP |