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  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  T get() const { return value; }
32 
33 private:
34  T value;
35 };
36 
37 } // namespace type
38 
39 namespace adaptor {
40 
41 template <>
42 struct convert<type::fix_int8> {
44  { v = type::detail::convert_integer<int8_t>(o); return o; }
45 };
46 
47 template <>
48 struct convert<type::fix_int16> {
50  { v = type::detail::convert_integer<int16_t>(o); return o; }
51 };
52 
53 template <>
54 struct convert<type::fix_int32> {
56  { v = type::detail::convert_integer<int32_t>(o); return o; }
57 };
58 
59 template <>
60 struct convert<type::fix_int64> {
62  { v = type::detail::convert_integer<int64_t>(o); return o; }
63 };
64 
65 
66 template <>
67 struct convert<type::fix_uint8> {
69  { v = type::detail::convert_integer<uint8_t>(o); return o; }
70 };
71 
72 template <>
73 struct convert<type::fix_uint16> {
75  { v = type::detail::convert_integer<uint16_t>(o); return o; }
76 };
77 
78 template <>
79 struct convert<type::fix_uint32> {
81  { v = type::detail::convert_integer<uint32_t>(o); return o; }
82 };
83 
84 template <>
85 struct convert<type::fix_uint64> {
87  { v = type::detail::convert_integer<uint64_t>(o); return o; }
88 };
89 
90 template <>
91 struct pack<type::fix_int8> {
92  template <typename Stream>
94  { o.pack_fix_int8(v); return o; }
95 };
96 
97 template <>
98 struct pack<type::fix_int16> {
99  template <typename Stream>
101  { o.pack_fix_int16(v); return o; }
102 };
103 
104 template <>
105 struct pack<type::fix_int32> {
106  template <typename Stream>
108  { o.pack_fix_int32(v); return o; }
109 };
110 
111 template <>
112 struct pack<type::fix_int64> {
113  template <typename Stream>
115  { o.pack_fix_int64(v); return o; }
116 };
117 
118 
119 template <>
120 struct pack<type::fix_uint8> {
121  template <typename Stream>
123  { o.pack_fix_uint8(v); return o; }
124 };
125 
126 template <>
127 struct pack<type::fix_uint16> {
128  template <typename Stream>
130  { o.pack_fix_uint16(v); return o; }
131 };
132 
133 template <>
134 struct pack<type::fix_uint32> {
135  template <typename Stream>
137  { o.pack_fix_uint32(v); return o; }
138 };
139 
140 template <>
141 struct pack<type::fix_uint64> {
142  template <typename Stream>
144  { o.pack_fix_uint64(v); return o; }
145 };
146 
147 template <>
148 struct object<type::fix_int8> {
150  if (v.get() < 0) {
152  o.via.i64 = v.get();
153  }
154  else {
156  o.via.u64 = static_cast<uint64_t>(v.get());
157  }
158  }
159 };
160 
161 template <>
162 struct object<type::fix_int16> {
164  if(v.get() < 0) {
166  o.via.i64 = v.get();
167  }
168  else {
170  o.via.u64 = static_cast<uint64_t>(v.get());
171  }
172  }
173 };
174 
175 template <>
176 struct object<type::fix_int32> {
178  if (v.get() < 0) {
180  o.via.i64 = v.get();
181  }
182  else {
184  o.via.u64 = static_cast<uint64_t>(v.get());
185  }
186  }
187 };
188 
189 template <>
190 struct object<type::fix_int64> {
192  if (v.get() < 0) {
194  o.via.i64 = v.get();
195  }
196  else {
198  o.via.u64 = static_cast<uint64_t>(v.get());
199  }
200  }
201 };
202 
203 template <>
204 struct object<type::fix_uint8> {
207  o.via.u64 = v.get();
208  }
209 };
210 
211 template <>
212 struct object<type::fix_uint16> {
215  o.via.u64 = v.get();
216  }
217 };
218 
219 template <>
220 struct object<type::fix_uint32> {
223  o.via.u64 = v.get();
224  }
225 };
226 
227 template <>
228 struct object<type::fix_uint64> {
231  o.via.u64 = v.get();
232  }
233 };
234 
235 template <>
236 struct object_with_zone<type::fix_int8> {
238  static_cast<msgpack::object&>(o) << v;
239  }
240 };
241 
242 template <>
245  static_cast<msgpack::object&>(o) << v;
246  }
247 };
248 
249 template <>
252  static_cast<msgpack::object&>(o) << v;
253  }
254 };
255 
256 template <>
259  static_cast<msgpack::object&>(o) << v;
260  }
261 };
262 
263 
264 template <>
267  static_cast<msgpack::object&>(o) << v;
268  }
269 };
270 
271 template <>
274  static_cast<msgpack::object&>(o) << v;
275  }
276 };
277 
278 template <>
281  static_cast<msgpack::object&>(o) << v;
282  }
283 };
284 
285 template <>
288  static_cast<msgpack::object&>(o) << v;
289  }
290 };
291 
292 } // namespace adaptor
293 
295 } // MSGPACK_API_VERSION_NAMESPACE(v1)
297 
298 } // namespace msgpack
299 
300 #endif // MSGPACK_V1_TYPE_FIXINT_HPP
The class template that supports continuous packing.
Definition: pack.hpp:33
packer< Stream > & pack_fix_int64(int64_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:822
packer< Stream > & pack_fix_uint64(uint64_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:787
packer< Stream > & pack_fix_int8(int8_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:796
packer< Stream > & pack_fix_int32(int32_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:813
packer< Stream > & pack_fix_uint16(uint16_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:769
packer< Stream > & pack_fix_uint32(uint32_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:778
packer< Stream > & pack_fix_int16(int16_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:804
packer< Stream > & pack_fix_uint8(uint8_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:761
fix_int< int8_t > fix_int8
Definition: fixint_decl.hpp:33
fix_int< uint64_t > fix_uint64
Definition: fixint_decl.hpp:31
fix_int< uint8_t > fix_uint8
Definition: fixint_decl.hpp:26
fix_int< int32_t > fix_int32
Definition: fixint_decl.hpp:35
fix_int< int16_t > fix_int16
Definition: fixint_decl.hpp:34
fix_int< int64_t > fix_int64
Definition: fixint_decl.hpp:36
fix_int< uint32_t > fix_uint32
Definition: fixint_decl.hpp:30
@ POSITIVE_INTEGER
Definition: object_fwd_decl.hpp:30
@ NEGATIVE_INTEGER
Definition: object_fwd_decl.hpp:31
fix_int< uint16_t > fix_uint16
Definition: fixint_decl.hpp:29
Definition: adaptor_base.hpp:15
msgpack::object const & operator()(msgpack::object const &o, type::fix_int16 &v) const
Definition: fixint.hpp:49
msgpack::object const & operator()(msgpack::object const &o, type::fix_int32 &v) const
Definition: fixint.hpp:55
msgpack::object const & operator()(msgpack::object const &o, type::fix_int64 &v) const
Definition: fixint.hpp:61
msgpack::object const & operator()(msgpack::object const &o, type::fix_int8 &v) const
Definition: fixint.hpp:43
msgpack::object const & operator()(msgpack::object const &o, type::fix_uint16 &v) const
Definition: fixint.hpp:74
msgpack::object const & operator()(msgpack::object const &o, type::fix_uint32 &v) const
Definition: fixint.hpp:80
msgpack::object const & operator()(msgpack::object const &o, type::fix_uint64 &v) const
Definition: fixint.hpp:86
msgpack::object const & operator()(msgpack::object const &o, type::fix_uint8 &v) const
Definition: fixint.hpp:68
Definition: adaptor_base.hpp:27
void operator()(msgpack::object &o, type::fix_int16 v) const
Definition: fixint.hpp:163
void operator()(msgpack::object &o, type::fix_int32 v) const
Definition: fixint.hpp:177
void operator()(msgpack::object &o, type::fix_int64 v) const
Definition: fixint.hpp:191
void operator()(msgpack::object &o, type::fix_int8 v) const
Definition: fixint.hpp:149
void operator()(msgpack::object &o, type::fix_uint16 v) const
Definition: fixint.hpp:213
void operator()(msgpack::object &o, type::fix_uint32 v) const
Definition: fixint.hpp:221
void operator()(msgpack::object &o, type::fix_uint64 v) const
Definition: fixint.hpp:229
void operator()(msgpack::object &o, type::fix_uint8 v) const
Definition: fixint.hpp:205
void operator()(msgpack::object::with_zone &o, type::fix_int16 v) const
Definition: fixint.hpp:244
void operator()(msgpack::object::with_zone &o, type::fix_int32 v) const
Definition: fixint.hpp:251
void operator()(msgpack::object::with_zone &o, type::fix_int64 v) const
Definition: fixint.hpp:258
void operator()(msgpack::object::with_zone &o, type::fix_int8 v) const
Definition: fixint.hpp:237
void operator()(msgpack::object::with_zone &o, type::fix_uint16 v) const
Definition: fixint.hpp:273
void operator()(msgpack::object::with_zone &o, type::fix_uint32 v) const
Definition: fixint.hpp:280
void operator()(msgpack::object::with_zone &o, type::fix_uint64 v) const
Definition: fixint.hpp:287
void operator()(msgpack::object::with_zone &o, type::fix_uint8 v) const
Definition: fixint.hpp:266
Definition: adaptor_base.hpp:43
Definition: adaptor_base.hpp:38
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_int16 &v) const
Definition: fixint.hpp:100
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_int32 &v) const
Definition: fixint.hpp:107
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_int64 &v) const
Definition: fixint.hpp:114
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_int8 &v) const
Definition: fixint.hpp:93
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_uint16 &v) const
Definition: fixint.hpp:129
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_uint32 &v) const
Definition: fixint.hpp:136
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_uint64 &v) const
Definition: fixint.hpp:143
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_uint8 &v) const
Definition: fixint.hpp:122
Definition: adaptor_base.hpp:32
Definition: object.hpp:35
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
union_type via
Definition: object_fwd.hpp:93
msgpack::type::object_type type
Definition: object_fwd.hpp:92
Definition: fixint.hpp:24
fix_int(T value)
Definition: fixint.hpp:27
T get() const
Definition: fixint.hpp:31
fix_int()
Definition: fixint.hpp:26
T value_type
Definition: fixint.hpp:25
uint64_t u64
Definition: object_fwd.hpp:78
int64_t i64
Definition: object_fwd.hpp:79
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:66