float.hpp
Go to the documentation of this file.
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef MSGPACK_V1_TYPE_FLOAT_HPP
#define MSGPACK_V1_TYPE_FLOAT_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <vector>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
// FIXME check overflow, underflow
namespace adaptor {
template <>
struct convert<float> {
msgpack::object const& operator()(msgpack::object const& o, float& v) const {
if(o.type == msgpack::type::FLOAT32 || o.type == msgpack::type::FLOAT64) {
v = static_cast<float>(o.via.f64);
}
else if (o.type == msgpack::type::POSITIVE_INTEGER) {
v = static_cast<float>(o.via.u64);
}
else if (o.type == msgpack::type::NEGATIVE_INTEGER) {
v = static_cast<float>(o.via.i64);
}
else {
throw msgpack::type_error();
}
return o;
}
};
template <>
struct pack<float> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const float& v) const {
o.pack_float(v);
return o;
}
};
template <>
struct convert<double> {
msgpack::object const& operator()(msgpack::object const& o, double& v) const {
if(o.type == msgpack::type::FLOAT32 || o.type == msgpack::type::FLOAT64) {
v = o.via.f64;
}
else if (o.type == msgpack::type::POSITIVE_INTEGER) {
v = static_cast<double>(o.via.u64);
}
else if (o.type == msgpack::type::NEGATIVE_INTEGER) {
v = static_cast<double>(o.via.i64);
}
else {
throw msgpack::type_error();
}
return o;
}
};
template <>
struct pack<double> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const double& v) const {
o.pack_double(v);
return o;
}
};
template <>
struct object<float> {
void operator()(msgpack::object& o, float v) const {
o.type = msgpack::type::FLOAT32;
o.via.f64 = static_cast<double>(v);
}
};
template <>
struct object<double> {
void operator()(msgpack::object& o, double v) const {
o.type = msgpack::type::FLOAT64;
o.via.f64 = v;
}
};
template <>
struct object_with_zone<float> {
void operator()(msgpack::object::with_zone& o, float v) const {
static_cast<msgpack::object&>(o) << v;
}
};
template <>
struct object_with_zone<double> {
void operator()(msgpack::object::with_zone& o, double v) const {
static_cast<msgpack::object&>(o) << v;
}
};
} // namespace adaptor
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_V1_TYPE_FLOAT_HPP
msgpack::adaptor::object_with_zone< double >::operator()
void operator()(msgpack::object::with_zone &o, double v) const
Definition: float.hpp:110
msgpack::adaptor::object< float >::operator()
void operator()(msgpack::object &o, float v) const
Definition: float.hpp:87
msgpack::type::FLOAT32
Definition: object_fwd_decl.hpp:33
object_fwd.hpp
msgpack::adaptor::convert< double >::operator()
msgpack::object const & operator()(msgpack::object const &o, double &v) const
Definition: float.hpp:58
msgpack::object::via
union_type via
Definition: object_fwd.hpp:93
msgpack
Definition: adaptor_base.hpp:15
versioning.hpp
msgpack::object::with_zone
Definition: object.hpp:34
msgpack::object::union_type::i64
int64_t i64
Definition: object_fwd.hpp:79
msgpack::type::NEGATIVE_INTEGER
Definition: object_fwd_decl.hpp:32
msgpack::adaptor::object_with_zone
Definition: adaptor_base.hpp:43
msgpack::adaptor::object_with_zone< float >::operator()
void operator()(msgpack::object::with_zone &o, float v) const
Definition: float.hpp:103
msgpack::type_error
Definition: object_fwd.hpp:236
msgpack::adaptor::pack
Definition: adaptor_base.hpp:32
msgpack::object::union_type::f64
double f64
Definition: object_fwd.hpp:84
msgpack::object
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
msgpack::packer::pack_float
packer< Stream > & pack_float(float d)
Packing float.
Definition: pack.hpp:1104
msgpack::adaptor::convert< float >::operator()
msgpack::object const & operator()(msgpack::object const &o, float &v) const
Definition: float.hpp:29
msgpack::packer::pack_double
packer< Stream > & pack_double(double d)
Packing double.
Definition: pack.hpp:1115
msgpack::object::type
msgpack::type::object_type type
Definition: object_fwd.hpp:92
MSGPACK_API_VERSION_NAMESPACE
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
msgpack::adaptor::object< double >::operator()
void operator()(msgpack::object &o, double v) const
Definition: float.hpp:95
msgpack::type::FLOAT64
Definition: object_fwd_decl.hpp:34
msgpack::adaptor::pack< float >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const float &v) const
Definition: float.hpp:49
msgpack::adaptor::object
Definition: adaptor_base.hpp:38
msgpack::packer
The class template that supports continuous packing.
Definition: adaptor_base_decl.hpp:24
msgpack::adaptor::pack< double >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const double &v) const
Definition: float.hpp:78
msgpack::adaptor::convert
Definition: adaptor_base.hpp:27
msgpack::type::POSITIVE_INTEGER
Definition: object_fwd_decl.hpp:31
msgpack::object::union_type::u64
uint64_t u64
Definition: object_fwd.hpp:78