MessagePack for C++
fixint.hpp
Go to the documentation of this file.
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 
14 
15 namespace msgpack {
16 
20 
21 namespace type {
22 
23 template <typename T>
24 struct fix_int {
25  fix_int() : value(0) { }
26  fix_int(T value) : value(value) { }
27 
28  operator T() const { return value; }
29 
30  T get() const { return value; }
31 
32 private:
33  T value;
34 };
35 
36 } // namespace type
37 
38 namespace adaptor {
39 
40 template <>
41 struct convert<type::fix_int8> {
43  { v = type::detail::convert_integer<int8_t>(o); return o; }
44 };
45 
46 template <>
47 struct convert<type::fix_int16> {
49  { v = type::detail::convert_integer<int16_t>(o); return o; }
50 };
51 
52 template <>
53 struct convert<type::fix_int32> {
55  { v = type::detail::convert_integer<int32_t>(o); return o; }
56 };
57 
58 template <>
59 struct convert<type::fix_int64> {
61  { v = type::detail::convert_integer<int64_t>(o); return o; }
62 };
63 
64 
65 template <>
66 struct convert<type::fix_uint8> {
68  { v = type::detail::convert_integer<uint8_t>(o); return o; }
69 };
70 
71 template <>
72 struct convert<type::fix_uint16> {
74  { v = type::detail::convert_integer<uint16_t>(o); return o; }
75 };
76 
77 template <>
78 struct convert<type::fix_uint32> {
80  { v = type::detail::convert_integer<uint32_t>(o); return o; }
81 };
82 
83 template <>
84 struct convert<type::fix_uint64> {
86  { v = type::detail::convert_integer<uint64_t>(o); return o; }
87 };
88 
89 template <>
90 struct pack<type::fix_int8> {
91  template <typename Stream>
93  { o.pack_fix_int8(v); return o; }
94 };
95 
96 template <>
97 struct pack<type::fix_int16> {
98  template <typename Stream>
100  { o.pack_fix_int16(v); return o; }
101 };
102 
103 template <>
104 struct pack<type::fix_int32> {
105  template <typename Stream>
107  { o.pack_fix_int32(v); return o; }
108 };
109 
110 template <>
111 struct pack<type::fix_int64> {
112  template <typename Stream>
114  { o.pack_fix_int64(v); return o; }
115 };
116 
117 
118 template <>
119 struct pack<type::fix_uint8> {
120  template <typename Stream>
122  { o.pack_fix_uint8(v); return o; }
123 };
124 
125 template <>
126 struct pack<type::fix_uint16> {
127  template <typename Stream>
129  { o.pack_fix_uint16(v); return o; }
130 };
131 
132 template <>
133 struct pack<type::fix_uint32> {
134  template <typename Stream>
136  { o.pack_fix_uint32(v); return o; }
137 };
138 
139 template <>
140 struct pack<type::fix_uint64> {
141  template <typename Stream>
143  { o.pack_fix_uint64(v); return o; }
144 };
145 
146 template <>
147 struct object<type::fix_int8> {
149  if (v.get() < 0) {
151  o.via.i64 = v.get();
152  }
153  else {
155  o.via.u64 = v.get();
156  }
157  }
158 };
159 
160 template <>
161 struct object<type::fix_int16> {
163  if(v.get() < 0) {
165  o.via.i64 = v.get();
166  }
167  else {
169  o.via.u64 = v.get();
170  }
171  }
172 };
173 
174 template <>
175 struct object<type::fix_int32> {
177  if (v.get() < 0) {
179  o.via.i64 = v.get();
180  }
181  else {
183  o.via.u64 = v.get();
184  }
185  }
186 };
187 
188 template <>
189 struct object<type::fix_int64> {
191  if (v.get() < 0) {
193  o.via.i64 = v.get();
194  }
195  else {
197  o.via.u64 = v.get();
198  }
199  }
200 };
201 
202 template <>
203 struct object<type::fix_uint8> {
206 };
207 
208 template <>
209 struct object<type::fix_uint16> {
212 };
213 
214 template <>
215 struct object<type::fix_uint32> {
218 };
219 
220 template <>
221 struct object<type::fix_uint64> {
224 };
225 
226 template <>
227 struct object_with_zone<type::fix_int8> {
229  { static_cast<msgpack::object&>(o) << v; }
230 };
231 
232 template <>
235  { static_cast<msgpack::object&>(o) << v; }
236 };
237 
238 template <>
241  { static_cast<msgpack::object&>(o) << v; }
242 };
243 
244 template <>
247  { static_cast<msgpack::object&>(o) << v; }
248 };
249 
250 
251 template <>
254  { static_cast<msgpack::object&>(o) << v; }
255 };
256 
257 template <>
260  { static_cast<msgpack::object&>(o) << v; }
261 };
262 
263 template <>
266  { static_cast<msgpack::object&>(o) << v; }
267 };
268 
269 template <>
272  { static_cast<msgpack::object&>(o) << v; }
273 };
274 
275 } // namespace adaptor
276 
278 } // MSGPACK_API_VERSION_NAMESPACE(v1)
280 
281 } // namespace msgpack
282 
283 #endif // MSGPACK_V1_TYPE_FIXINT_HPP
packer< Stream > & pack_fix_uint16(uint16_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:746
fix_int< uint32_t > fix_uint32
Definition: fixint_decl.hpp:30
packer< Stream > & pack_fix_uint32(uint32_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:755
void operator()(msgpack::object::with_zone &o, type::fix_int64 v) const
Definition: fixint.hpp:246
void operator()(msgpack::object::with_zone &o, type::fix_int8 v) const
Definition: fixint.hpp:228
msgpack::object const & operator()(msgpack::object const &o, type::fix_int16 &v) const
Definition: fixint.hpp:48
void operator()(msgpack::object::with_zone &o, type::fix_uint8 v) const
Definition: fixint.hpp:253
fix_int< uint64_t > fix_uint64
Definition: fixint_decl.hpp:31
void operator()(msgpack::object::with_zone &o, type::fix_int16 v) const
Definition: fixint.hpp:234
union_type via
Definition: object_fwd.hpp:93
void operator()(msgpack::object &o, type::fix_int8 v) const
Definition: fixint.hpp:148
void operator()(msgpack::object &o, type::fix_uint64 v) const
Definition: fixint.hpp:222
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_int64 &v) const
Definition: fixint.hpp:113
void operator()(msgpack::object &o, type::fix_int16 v) const
Definition: fixint.hpp:162
fix_int(T value)
Definition: fixint.hpp:26
fix_int< uint8_t > fix_uint8
Definition: fixint_decl.hpp:26
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_int32 &v) const
Definition: fixint.hpp:106
msgpack::object const & operator()(msgpack::object const &o, type::fix_int64 &v) const
Definition: fixint.hpp:60
Definition: adaptor_base.hpp:15
void operator()(msgpack::object &o, type::fix_int32 v) const
Definition: fixint.hpp:176
msgpack::object const & operator()(msgpack::object const &o, type::fix_int8 &v) const
Definition: fixint.hpp:42
Definition: object.hpp:34
msgpack::object const & operator()(msgpack::object const &o, type::fix_int32 &v) const
Definition: fixint.hpp:54
fix_int< int64_t > fix_int64
Definition: fixint_decl.hpp:36
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_int8 &v) const
Definition: fixint.hpp:92
int64_t i64
Definition: object_fwd.hpp:79
Definition: object_fwd_decl.hpp:32
void operator()(msgpack::object::with_zone &o, type::fix_uint64 v) const
Definition: fixint.hpp:271
Definition: adaptor_base.hpp:43
void operator()(msgpack::object::with_zone &o, type::fix_uint32 v) const
Definition: fixint.hpp:265
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_int16 &v) const
Definition: fixint.hpp:99
void operator()(msgpack::object &o, type::fix_uint8 v) const
Definition: fixint.hpp:204
void operator()(msgpack::object &o, type::fix_int64 v) const
Definition: fixint.hpp:190
Definition: adaptor_base.hpp:32
fix_int< int8_t > fix_int8
Definition: fixint_decl.hpp:33
packer< Stream > & pack_fix_int32(int32_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:790
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_uint16 &v) const
Definition: fixint.hpp:128
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_uint64 &v) const
Definition: fixint.hpp:142
void operator()(msgpack::object &o, type::fix_uint16 v) const
Definition: fixint.hpp:210
T get() const
Definition: fixint.hpp:30
msgpack::object const & operator()(msgpack::object const &o, type::fix_uint8 &v) const
Definition: fixint.hpp:67
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
Definition: fixint.hpp:24
msgpack::type::object_type type
Definition: object_fwd.hpp:92
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
packer< Stream > & pack_fix_int16(int16_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:781
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_uint8 &v) const
Definition: fixint.hpp:121
msgpack::object const & operator()(msgpack::object const &o, type::fix_uint64 &v) const
Definition: fixint.hpp:85
packer< Stream > & pack_fix_int8(int8_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:773
void operator()(msgpack::object &o, type::fix_uint32 v) const
Definition: fixint.hpp:216
msgpack::object const & operator()(msgpack::object const &o, type::fix_uint32 &v) const
Definition: fixint.hpp:79
void operator()(msgpack::object::with_zone &o, type::fix_int32 v) const
Definition: fixint.hpp:240
Definition: adaptor_base.hpp:38
The class template that supports continuous packing.
Definition: adaptor_base_decl.hpp:24
fix_int< uint16_t > fix_uint16
Definition: fixint_decl.hpp:29
void operator()(msgpack::object::with_zone &o, type::fix_uint16 v) const
Definition: fixint.hpp:259
packer< Stream > & pack_fix_uint8(uint8_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:738
fix_int< int32_t > fix_int32
Definition: fixint_decl.hpp:35
fix_int< int16_t > fix_int16
Definition: fixint_decl.hpp:34
fix_int()
Definition: fixint.hpp:25
packer< Stream > & pack_fix_uint64(uint64_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:764
msgpack::object const & operator()(msgpack::object const &o, type::fix_uint16 &v) const
Definition: fixint.hpp:73
Definition: adaptor_base.hpp:27
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_uint32 &v) const
Definition: fixint.hpp:135
Definition: object_fwd_decl.hpp:31
uint64_t u64
Definition: object_fwd.hpp:78
packer< Stream > & pack_fix_int64(int64_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:799