Hideaki Tai / msgpack-embedded

Dependents:   hello_message_pack

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fixint.hpp Source File

fixint.hpp

00001 //
00002 // MessagePack for C++ static resolution routine
00003 //
00004 // Copyright (C) 2020 FURUHASHI Sadayuki
00005 //
00006 //    Distributed under the Boost Software License, Version 1.0.
00007 //    (See accompanying file LICENSE_1_0.txt or copy at
00008 //    http://www.boost.org/LICENSE_1_0.txt)
00009 //
00010 #ifndef MSGPACK_TYPE_FIXINT_HPP
00011 #define MSGPACK_TYPE_FIXINT_HPP
00012 
00013 #include "msgpack/versioning.hpp"
00014 #include "msgpack/adaptor/adaptor_base.hpp"
00015 #include "msgpack/adaptor/int.hpp"
00016 
00017 namespace msgpack {
00018 
00019 /// @cond
00020 MSGPACK_API_VERSION_NAMESPACE(v1) {
00021 /// @endcond
00022 
00023 namespace type {
00024 
00025 
00026 template <typename T>
00027 struct fix_int {
00028     fix_int() : value(0) { }
00029     fix_int(T value) : value(value) { }
00030 
00031     operator T() const { return value; }
00032 
00033     T get() const { return value; }
00034 
00035 private:
00036     T value;
00037 };
00038 
00039 
00040 typedef fix_int<uint8_t>  fix_uint8;
00041 typedef fix_int<uint16_t> fix_uint16;
00042 typedef fix_int<uint32_t> fix_uint32;
00043 typedef fix_int<uint64_t> fix_uint64;
00044 
00045 typedef fix_int<int8_t>  fix_int8;
00046 typedef fix_int<int16_t> fix_int16;
00047 typedef fix_int<int32_t> fix_int32;
00048 typedef fix_int<int64_t> fix_int64;
00049 
00050 
00051 }  // namespace type
00052 
00053 namespace adaptor {
00054 
00055 template <>
00056 struct convert<type::fix_int8> {
00057     msgpack::object const& operator()(msgpack::object const& o, type::fix_int8& v) const
00058     { v = type::detail::convert_integer<int8_t>(o); return o; }
00059 };
00060 
00061 template <>
00062 struct convert<type::fix_int16> {
00063     msgpack::object const& operator()(msgpack::object const& o, type::fix_int16& v) const
00064     { v = type::detail::convert_integer<int16_t>(o); return o; }
00065 };
00066 
00067 template <>
00068 struct convert<type::fix_int32> {
00069     msgpack::object const& operator()(msgpack::object const& o, type::fix_int32& v) const
00070     { v = type::detail::convert_integer<int32_t>(o); return o; }
00071 };
00072 
00073 template <>
00074 struct convert<type::fix_int64> {
00075     msgpack::object const& operator()(msgpack::object const& o, type::fix_int64& v) const
00076     { v = type::detail::convert_integer<int64_t>(o); return o; }
00077 };
00078 
00079 
00080 template <>
00081 struct convert<type::fix_uint8> {
00082     msgpack::object const& operator()(msgpack::object const& o, type::fix_uint8& v) const
00083     { v = type::detail::convert_integer<uint8_t>(o); return o; }
00084 };
00085 
00086 template <>
00087 struct convert<type::fix_uint16> {
00088     msgpack::object const& operator()(msgpack::object const& o, type::fix_uint16& v) const
00089     { v = type::detail::convert_integer<uint16_t>(o); return o; }
00090 };
00091 
00092 template <>
00093 struct convert<type::fix_uint32> {
00094     msgpack::object const& operator()(msgpack::object const& o, type::fix_uint32& v) const
00095     { v = type::detail::convert_integer<uint32_t>(o); return o; }
00096 };
00097 
00098 template <>
00099 struct convert<type::fix_uint64> {
00100     msgpack::object const& operator()(msgpack::object const& o, type::fix_uint64& v) const
00101     { v = type::detail::convert_integer<uint64_t>(o); return o; }
00102 };
00103 
00104 template <>
00105 struct pack<type::fix_int8> {
00106     template <typename Stream>
00107     msgpack::packer<Stream> & operator()(msgpack::packer<Stream> & o, const type::fix_int8& v) const
00108     { o.pack_fix_int8(v); return o; }
00109 };
00110 
00111 template <>
00112 struct pack<type::fix_int16> {
00113     template <typename Stream>
00114     msgpack::packer<Stream> & operator()(msgpack::packer<Stream> & o, const type::fix_int16& v) const
00115     { o.pack_fix_int16(v); return o; }
00116 };
00117 
00118 template <>
00119 struct pack<type::fix_int32> {
00120     template <typename Stream>
00121     msgpack::packer<Stream> & operator()(msgpack::packer<Stream> & o, const type::fix_int32& v) const
00122     { o.pack_fix_int32(v); return o; }
00123 };
00124 
00125 template <>
00126 struct pack<type::fix_int64> {
00127     template <typename Stream>
00128     msgpack::packer<Stream> & operator()(msgpack::packer<Stream> & o, const type::fix_int64& v) const
00129     { o.pack_fix_int64(v); return o; }
00130 };
00131 
00132 
00133 template <>
00134 struct pack<type::fix_uint8> {
00135     template <typename Stream>
00136     msgpack::packer<Stream> & operator()(msgpack::packer<Stream> & o, const type::fix_uint8& v) const
00137     { o.pack_fix_uint8(v); return o; }
00138 };
00139 
00140 template <>
00141 struct pack<type::fix_uint16> {
00142     template <typename Stream>
00143     msgpack::packer<Stream> & operator()(msgpack::packer<Stream> & o, const type::fix_uint16& v) const
00144     { o.pack_fix_uint16(v); return o; }
00145 };
00146 
00147 template <>
00148 struct pack<type::fix_uint32> {
00149     template <typename Stream>
00150     msgpack::packer<Stream> & operator()(msgpack::packer<Stream> & o, const type::fix_uint32& v) const
00151     { o.pack_fix_uint32(v); return o; }
00152 };
00153 
00154 template <>
00155 struct pack<type::fix_uint64> {
00156     template <typename Stream>
00157     msgpack::packer<Stream> & operator()(msgpack::packer<Stream> & o, const type::fix_uint64& v) const
00158     { o.pack_fix_uint64(v); return o; }
00159 };
00160 
00161 template <>
00162 struct object<type::fix_int8> {
00163     void operator()(msgpack::object& o, type::fix_int8 v) const {
00164         if (v.get() < 0) {
00165             o.type = msgpack::type::NEGATIVE_INTEGER;
00166             o.via.i64 = v.get();
00167         }
00168         else {
00169             o.type = msgpack::type::POSITIVE_INTEGER;
00170             o.via.u64 = v.get();
00171         }
00172     }
00173 };
00174 
00175 template <>
00176 struct object<type::fix_int16> {
00177     void operator()(msgpack::object& o, type::fix_int16 v) const {
00178         if(v.get() < 0) {
00179             o.type = msgpack::type::NEGATIVE_INTEGER;
00180             o.via.i64 = v.get();
00181         }
00182         else {
00183             o.type = msgpack::type::POSITIVE_INTEGER;
00184             o.via.u64 = v.get();
00185         }
00186     }
00187 };
00188 
00189 template <>
00190 struct object<type::fix_int32> {
00191     void operator()(msgpack::object& o, type::fix_int32 v) const {
00192         if (v.get() < 0) {
00193             o.type = msgpack::type::NEGATIVE_INTEGER;
00194             o.via.i64 = v.get();
00195         }
00196         else {
00197             o.type = msgpack::type::POSITIVE_INTEGER;
00198             o.via.u64 = v.get();
00199         }
00200     }
00201 };
00202 
00203 template <>
00204 struct object<type::fix_int64> {
00205     void operator()(msgpack::object& o, type::fix_int64 v) const {
00206         if (v.get() < 0) {
00207             o.type = msgpack::type::NEGATIVE_INTEGER;
00208             o.via.i64 = v.get();
00209         }
00210         else {
00211             o.type = msgpack::type::POSITIVE_INTEGER;
00212             o.via.u64 = v.get();
00213         }
00214     }
00215 };
00216 
00217 template <>
00218 struct object<type::fix_uint8> {
00219     void operator()(msgpack::object& o, type::fix_uint8 v) const
00220     { o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
00221 };
00222 
00223 template <>
00224 struct object<type::fix_uint16> {
00225     void operator()(msgpack::object& o, type::fix_uint16 v) const
00226     { o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
00227 };
00228 
00229 template <>
00230 struct object<type::fix_uint32> {
00231     void operator()(msgpack::object& o, type::fix_uint32 v) const
00232     { o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
00233 };
00234 
00235 template <>
00236 struct object<type::fix_uint64> {
00237     void operator()(msgpack::object& o, type::fix_uint64 v) const
00238     { o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
00239 };
00240 
00241 template <>
00242 struct object_with_zone<type::fix_int8> {
00243     void operator()(msgpack::object::with_zone& o, type::fix_int8 v) const
00244     { static_cast<msgpack::object&>(o) << v; }
00245 };
00246 
00247 template <>
00248 struct object_with_zone<type::fix_int16> {
00249     void operator()(msgpack::object::with_zone& o, type::fix_int16 v) const
00250     { static_cast<msgpack::object&>(o) << v; }
00251 };
00252 
00253 template <>
00254 struct object_with_zone<type::fix_int32> {
00255     void operator()(msgpack::object::with_zone& o, type::fix_int32 v) const
00256     { static_cast<msgpack::object&>(o) << v; }
00257 };
00258 
00259 template <>
00260 struct object_with_zone<type::fix_int64> {
00261     void operator()(msgpack::object::with_zone& o, type::fix_int64 v) const
00262     { static_cast<msgpack::object&>(o) << v; }
00263 };
00264 
00265 
00266 template <>
00267 struct object_with_zone<type::fix_uint8> {
00268     void operator()(msgpack::object::with_zone& o, type::fix_uint8 v) const
00269     { static_cast<msgpack::object&>(o) << v; }
00270 };
00271 
00272 template <>
00273 struct object_with_zone<type::fix_uint16> {
00274     void operator()(msgpack::object::with_zone& o, type::fix_uint16 v) const
00275     { static_cast<msgpack::object&>(o) << v; }
00276 };
00277 
00278 template <>
00279 struct object_with_zone<type::fix_uint32> {
00280     void operator()(msgpack::object::with_zone& o, type::fix_uint32 v) const
00281     { static_cast<msgpack::object&>(o) << v; }
00282 };
00283 
00284 template <>
00285 struct object_with_zone<type::fix_uint64> {
00286     void operator()(msgpack::object::with_zone& o, type::fix_uint64 v) const
00287     { static_cast<msgpack::object&>(o) << v; }
00288 };
00289 
00290 } // namespace adaptor
00291 
00292 /// @cond
00293 }  // MSGPACK_API_VERSION_NAMESPACE(v1)
00294 /// @endcond
00295 
00296 }  // namespace msgpack
00297 
00298 #endif /* msgpack/type/fixint.hpp */