MessagePack for C++
Toggle main menu visibility
Loading...
Searching...
No Matches
msgpack
v1
adaptor
float.hpp
Go to the documentation of this file.
1
//
2
// MessagePack for C++ static resolution routine
3
//
4
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
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_FLOAT_HPP
11
#define MSGPACK_V1_TYPE_FLOAT_HPP
12
13
#include "
msgpack/versioning.hpp
"
14
#include "
msgpack/object_fwd.hpp
"
15
#include <vector>
16
17
namespace
msgpack
{
18
20
MSGPACK_API_VERSION_NAMESPACE
(v1) {
22
23
// FIXME check overflow, underflow
24
25
namespace
adaptor
{
26
27
template
<>
28
struct
convert
<float> {
29
msgpack::object
const
&
operator()
(
msgpack::object
const
& o,
float
& v)
const
{
30
if
(o.
type
==
msgpack::type::FLOAT32
|| o.
type
==
msgpack::type::FLOAT64
) {
31
v =
static_cast<
float
>
(o.
via
.
f64
);
32
}
33
else
if
(o.
type
==
msgpack::type::POSITIVE_INTEGER
) {
34
v =
static_cast<
float
>
(o.
via
.
u64
);
35
}
36
else
if
(o.
type
==
msgpack::type::NEGATIVE_INTEGER
) {
37
v =
static_cast<
float
>
(o.
via
.
i64
);
38
}
39
else
{
40
throw
msgpack::type_error
();
41
}
42
return
o;
43
}
44
};
45
46
template
<>
47
struct
pack
<float> {
48
template
<
typename
Stream>
49
msgpack::packer<Stream>
&
operator()
(
msgpack::packer<Stream>
& o,
const
float
& v)
const
{
50
o.
pack_float
(v);
51
return
o;
52
}
53
};
54
55
56
template
<>
57
struct
convert
<double> {
58
msgpack::object
const
&
operator()
(
msgpack::object
const
& o,
double
& v)
const
{
59
if
(o.
type
==
msgpack::type::FLOAT32
|| o.
type
==
msgpack::type::FLOAT64
) {
60
v = o.
via
.
f64
;
61
}
62
else
if
(o.
type
==
msgpack::type::POSITIVE_INTEGER
) {
63
v =
static_cast<
double
>
(o.
via
.
u64
);
64
}
65
else
if
(o.
type
==
msgpack::type::NEGATIVE_INTEGER
) {
66
v =
static_cast<
double
>
(o.
via
.
i64
);
67
}
68
else
{
69
throw
msgpack::type_error
();
70
}
71
return
o;
72
}
73
};
74
75
template
<>
76
struct
pack
<double> {
77
template
<
typename
Stream>
78
msgpack::packer<Stream>
&
operator()
(
msgpack::packer<Stream>
& o,
const
double
& v)
const
{
79
o.
pack_double
(v);
80
return
o;
81
}
82
};
83
84
85
template
<>
86
struct
object
<float> {
87
void
operator()
(
msgpack::object
& o,
float
v)
const
{
88
o.
type
=
msgpack::type::FLOAT32
;
89
o.
via
.
f64
=
static_cast<
double
>
(v);
90
}
91
};
92
93
template
<>
94
struct
object
<double> {
95
void
operator()
(
msgpack::object
& o,
double
v)
const
{
96
o.
type
=
msgpack::type::FLOAT64
;
97
o.
via
.
f64
= v;
98
}
99
};
100
101
template
<>
102
struct
object_with_zone
<float> {
103
void
operator()
(
msgpack::object::with_zone
& o,
float
v)
const
{
104
static_cast<
msgpack::object
&
>
(o) << v;
105
}
106
};
107
108
template
<>
109
struct
object_with_zone
<double> {
110
void
operator()
(
msgpack::object::with_zone
& o,
double
v)
const
{
111
static_cast<
msgpack::object
&
>
(o) << v;
112
}
113
};
114
115
}
// namespace adaptor
116
118
}
// MSGPACK_API_VERSION_NAMESPACE(v1)
120
121
}
// namespace msgpack
122
123
#endif
// MSGPACK_V1_TYPE_FLOAT_HPP
msgpack::packer
The class template that supports continuous packing.
Definition
pack.hpp:33
msgpack::packer::pack_double
packer< Stream > & pack_double(double d)
Packing double.
Definition
pack.hpp:1150
msgpack::packer::pack_float
packer< Stream > & pack_float(float d)
Packing float.
Definition
pack.hpp:1139
msgpack::type_error
Definition
object_fwd.hpp:234
msgpack::adaptor
Definition
adaptor_base.hpp:22
msgpack::type::FLOAT64
@ FLOAT64
Definition
object_fwd_decl.hpp:33
msgpack::type::POSITIVE_INTEGER
@ POSITIVE_INTEGER
Definition
object_fwd_decl.hpp:30
msgpack::type::NEGATIVE_INTEGER
@ NEGATIVE_INTEGER
Definition
object_fwd_decl.hpp:31
msgpack::type::FLOAT32
@ FLOAT32
Definition
object_fwd_decl.hpp:32
msgpack
Definition
adaptor_base.hpp:15
object_fwd.hpp
msgpack::adaptor::convert< double >::operator()
msgpack::object const & operator()(msgpack::object const &o, double &v) const
Definition
float.hpp:58
msgpack::adaptor::convert< float >::operator()
msgpack::object const & operator()(msgpack::object const &o, float &v) const
Definition
float.hpp:29
msgpack::adaptor::convert
Definition
adaptor_base.hpp:27
msgpack::adaptor::object< double >::operator()
void operator()(msgpack::object &o, double v) const
Definition
float.hpp:95
msgpack::adaptor::object< float >::operator()
void operator()(msgpack::object &o, float v) const
Definition
float.hpp:87
msgpack::adaptor::object_with_zone< double >::operator()
void operator()(msgpack::object::with_zone &o, double v) const
Definition
float.hpp:110
msgpack::adaptor::object_with_zone< float >::operator()
void operator()(msgpack::object::with_zone &o, float v) const
Definition
float.hpp:103
msgpack::adaptor::object_with_zone
Definition
adaptor_base.hpp:43
msgpack::adaptor::object
Definition
adaptor_base.hpp:38
msgpack::adaptor::pack< double >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const double &v) const
Definition
float.hpp:78
msgpack::adaptor::pack< float >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const float &v) const
Definition
float.hpp:49
msgpack::adaptor::pack
Definition
adaptor_base.hpp:32
msgpack::object
Object class that corresponding to MessagePack format object.
Definition
object_fwd.hpp:77
msgpack::object::via
union_type via
Definition
object_fwd.hpp:95
msgpack::object::type
msgpack::type::object_type type
Definition
object_fwd.hpp:94
msgpack::object::with_zone
object_with_zone_type with_zone
Definition
object_fwd.hpp:225
msgpack::object::union_type::u64
uint64_t u64
Definition
object_fwd.hpp:80
msgpack::object::union_type::i64
int64_t i64
Definition
object_fwd.hpp:81
msgpack::object::union_type::f64
double f64
Definition
object_fwd.hpp:86
MSGPACK_API_VERSION_NAMESPACE
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition
versioning.hpp:66
versioning.hpp
Generated by
1.17.0