mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-04-16 06:56:39 +02:00
Re-organized tree to prepare for version 2.0.0.
See https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_versioning
This commit is contained in:
parent
cabd8a8a03
commit
54cb4350b3
52
.travis.yml
52
.travis.yml
@ -36,14 +36,15 @@ install:
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then unzip -q gtest-1.7.0.zip && cd gtest-1.7.0 && sudo cp -r include/gtest /usr/local/include && clang++ src/gtest-all.cc -I. -Iinclude -c && g++ src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mv *.a /usr/local/lib && cd ..; fi
|
||||
|
||||
env:
|
||||
- ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="unsigned"
|
||||
- ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="" BOOST_INC="" CHAR_SIGN="signed"
|
||||
- ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="signed"
|
||||
- ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="" BOOST_INC="" SHARED="OFF" CHAR_SIGN="unsigned"
|
||||
- ACTION="ci/build_autotools.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib" BOOST="" BOOST_INC="" CHAR_SIGN="signed"
|
||||
- ACTION="ci/build_autotools.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="unsigned"
|
||||
- ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib" BOOST="" BOOST_INC="" CHAR_SIGN="unsigned"
|
||||
- ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" SHARED="OFF" CHAR_SIGN="signed"
|
||||
- ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="unsigned" API_VERSION="1"
|
||||
- ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="" BOOST_INC="" CHAR_SIGN="signed" API_VERSION="2"
|
||||
- ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="signed" API_VERSION="2"
|
||||
- ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="" BOOST_INC="" SHARED="OFF" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
- ACTION="ci/build_autotools.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib" BOOST="" BOOST_INC="" CHAR_SIGN="signed" API_VERSION="2"
|
||||
- ACTION="ci/build_autotools.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
- ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib" BOOST="" BOOST_INC="" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
- ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" SHARED="OFF" CHAR_SIGN="signed" API_VERSION="1"
|
||||
- ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" SHARED="OFF" CHAR_SIGN="signed" API_VERSION="2"
|
||||
|
||||
before_script:
|
||||
- export PATH=/usr/local/bin:$PATH && rm -rf install
|
||||
@ -53,39 +54,50 @@ matrix:
|
||||
- os: osx
|
||||
compiler: gcc
|
||||
- os: osx
|
||||
env: ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="" BOOST_INC="" CHAR_SIGN="signed"
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" SHARED="OFF" CHAR_SIGN="signed" API_VERSION="1"
|
||||
- os: osx
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="" BOOST_INC="" SHARED="OFF" CHAR_SIGN="unsigned"
|
||||
env: ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="" BOOST_INC="" CHAR_SIGN="signed" API_VERSION="2"
|
||||
- os: osx
|
||||
env: ACTION="ci/build_autotools.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="unsigned"
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="" BOOST_INC="" SHARED="OFF" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
- os: osx
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" SHARED="OFF" CHAR_SIGN="signed"
|
||||
env: ACTION="ci/build_autotools.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
- os: osx
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" SHARED="OFF" CHAR_SIGN="signed" API_VERSION="2"
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="unsigned"
|
||||
env: ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="unsigned" API_VERSION="1"
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="" BOOST_INC="" CHAR_SIGN="signed"
|
||||
env: ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="signed"
|
||||
env: ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="" BOOST_INC="" CHAR_SIGN="signed" API_VERSION="2"
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="" BOOST_INC="" SHARED="OFF" CHAR_SIGN="unsigned"
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="signed" API_VERSION="2"
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="" BOOST_INC="" SHARED="OFF" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: ACTION="ci/build_autotools.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib" BOOST="" BOOST_INC="" CHAR_SIGN="signed"
|
||||
env: ACTION="ci/build_autotools.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib" BOOST="" BOOST_INC="" CHAR_SIGN="signed" API_VERSION="2"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: ACTION="ci/build_autotools.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="unsigned"
|
||||
env: ACTION="ci/build_autotools.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib" BOOST="" BOOST_INC="" CHAR_SIGN="unsigned"
|
||||
env: ACTION="ci/build_autotools.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" SHARED="OFF" CHAR_SIGN="signed"
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib" BOOST="" BOOST_INC="" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" SHARED="OFF" CHAR_SIGN="signed" API_VERSION="1"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" SHARED="OFF" CHAR_SIGN="signed" API_VERSION="2"
|
||||
|
||||
script:
|
||||
- git clean -xdf && CMAKE_LIBRARY_PATH=${LIBPATH} ${ACTION} ${VERSION} ${ARCH} ${BOOST} ${BOOST_INC} ${CHAR_SIGN}
|
||||
|
@ -89,6 +89,12 @@ IF (MSGPACK_CHAR_SIGN)
|
||||
SET (CMAKE_CXX_FLAGS "-f${MSGPACK_CHAR_SIGN}-char ${CMAKE_CXX_FLAGS}")
|
||||
ENDIF ()
|
||||
|
||||
IF (MSGPACK_DEFAULT_API_VERSION)
|
||||
SET (CMAKE_CXX_FLAGS "-DMSGPACK_DEFAULT_API_VERSION=${MSGPACK_DEFAULT_API_VERSION} ${CMAKE_CXX_FLAGS}")
|
||||
ELSE ()
|
||||
SET (CMAKE_CXX_FLAGS "-DMSGPACK_DEFAULT_API_VERSION=2 ${CMAKE_CXX_FLAGS}")
|
||||
ENDIF ()
|
||||
|
||||
FILE (GLOB_RECURSE PREDEF_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/external/boost/predef/include/boost ${CMAKE_CURRENT_SOURCE_DIR}/external/boost/predef/include/boost/*.h)
|
||||
FOREACH (F ${PREDEF_FILES})
|
||||
SET(M "Converting ${F}")
|
||||
|
@ -28,7 +28,7 @@ else
|
||||
boost=""
|
||||
fi
|
||||
|
||||
./configure CFLAGS="$bit32 -f${CHAR_SIGN}-char" CXXFLAGS="$bit32 -f${CHAR_SIGN}-char $cpp11 $boost -I$4"
|
||||
./configure CFLAGS="$bit32 -f${CHAR_SIGN}-char" CXXFLAGS="$bit32 -f${CHAR_SIGN}-char $cpp11 $boost -I$4 -DMSGPACK_DEFAULT_API_VERSION=${API_VERSION}"
|
||||
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
|
@ -51,7 +51,7 @@ else
|
||||
shared=""
|
||||
fi
|
||||
|
||||
cmake $cpp11 $bit32 $boost $boost_dir $shared -DMSGPACK_CHAR_SIGN=${CHAR_SIGN} ..
|
||||
cmake $cpp11 $bit32 $boost $boost_dir $shared -DMSGPACK_CHAR_SIGN=${CHAR_SIGN} -DMSGPACK_DEFAULT_API_VERSION=${API_VERSION} ..
|
||||
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
|
@ -1,91 +1,27 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP03_DEFINE_ARRAY_HPP
|
||||
#define MSGPACK_CPP03_DEFINE_ARRAY_HPP
|
||||
#ifndef MSGPACK_V1_CPP03_DEFINE_ARRAY_HPP
|
||||
#define MSGPACK_V1_CPP03_DEFINE_ARRAY_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/v1/adaptor/detail/cpp03_define_array_decl.hpp"
|
||||
#include "msgpack/adaptor/msgpack_tuple.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
#define MSGPACK_DEFINE_ARRAY(...) \
|
||||
template <typename Packer> \
|
||||
void msgpack_pack(Packer& pk) const \
|
||||
{ \
|
||||
msgpack::type::make_define_array(__VA_ARGS__).msgpack_pack(pk); \
|
||||
} \
|
||||
void msgpack_unpack(msgpack::object const& o) \
|
||||
{ \
|
||||
msgpack::type::make_define_array(__VA_ARGS__).msgpack_unpack(o); \
|
||||
}\
|
||||
template <typename MSGPACK_OBJECT> \
|
||||
void msgpack_object(MSGPACK_OBJECT* o, msgpack::zone& z) const \
|
||||
{ \
|
||||
msgpack::type::make_define_array(__VA_ARGS__).msgpack_object(o, z); \
|
||||
}
|
||||
|
||||
#define MSGPACK_BASE_ARRAY(base) (*const_cast<base *>(static_cast<base const*>(this)))
|
||||
|
||||
// MSGPACK_ADD_ENUM must be used in the global namespace.
|
||||
#define MSGPACK_ADD_ENUM(enum_name) \
|
||||
namespace msgpack { \
|
||||
/** @cond */ \
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) { \
|
||||
/** @endcond */ \
|
||||
namespace adaptor { \
|
||||
template<> \
|
||||
struct convert<enum_name> { \
|
||||
msgpack::object const& operator()(msgpack::object const& o, enum_name& v) const {\
|
||||
int tmp; \
|
||||
o >> tmp; \
|
||||
v = static_cast<enum_name>(tmp); \
|
||||
return o; \
|
||||
} \
|
||||
}; \
|
||||
template<> \
|
||||
struct object<enum_name> { \
|
||||
void operator()(msgpack::object& o, const enum_name& v) const {\
|
||||
o << static_cast<int>(v); \
|
||||
} \
|
||||
}; \
|
||||
template<> \
|
||||
struct object_with_zone<enum_name> { \
|
||||
void operator()(msgpack::object::with_zone& o, const enum_name& v) const { \
|
||||
o << static_cast<int>(v); \
|
||||
} \
|
||||
}; \
|
||||
template<> \
|
||||
struct pack<enum_name> { \
|
||||
template <typename Stream> \
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const enum_name& v) const { \
|
||||
return o << static_cast<int>(v); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
/** @cond */ \
|
||||
} \
|
||||
/** @endcond */ \
|
||||
}
|
||||
|
||||
namespace msgpack {
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
namespace type {
|
||||
|
||||
/// @cond
|
||||
<% GENERATION_LIMIT = 31 %>
|
||||
template <typename A0 = void<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%> = void<%}%>>
|
||||
struct define_array;
|
||||
/// @endcond
|
||||
|
||||
template <>
|
||||
struct define_array<> {
|
||||
typedef define_array<> value_type;
|
||||
@ -169,5 +105,4 @@ inline define_array<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_define_array(A0& a0
|
||||
/// @endcond
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
#endif // MSGPACK_CPP03_DEFINE_ARRAY_HPP
|
||||
#endif // MSGPACK_V1_CPP03_DEFINE_ARRAY_HPP
|
42
erb/v1/cpp03_define_array_decl.hpp.erb
Normal file
42
erb/v1/cpp03_define_array_decl.hpp.erb
Normal file
@ -0,0 +1,42 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP03_DEFINE_ARRAY_DECL_HPP
|
||||
#define MSGPACK_V1_CPP03_DEFINE_ARRAY_DECL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
namespace type {
|
||||
|
||||
/// @cond
|
||||
<% GENERATION_LIMIT = 31 %>
|
||||
template <typename A0 = void<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%> = void<%}%>>
|
||||
struct define_array;
|
||||
/// @endcond
|
||||
|
||||
define_array<> make_define_array();
|
||||
|
||||
/// @cond
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
inline define_array<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_define_array(A0& a0<%1.upto(i) {|j|%>, A<%=j%>& a<%=j%><%}%>);
|
||||
<%}%>
|
||||
/// @endcond
|
||||
|
||||
} // namespace type
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_CPP03_DEFINE_ARRAY_DECL_HPP
|
@ -1,83 +1,27 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
// Copyright (C) 2015-2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP03_DEFINE_MAP_HPP
|
||||
#define MSGPACK_CPP03_DEFINE_MAP_HPP
|
||||
#ifndef MSGPACK_V1_CPP03_DEFINE_MAP_HPP
|
||||
#define MSGPACK_V1_CPP03_DEFINE_MAP_HPP
|
||||
|
||||
// BOOST_PP_VARIADICS is defined in boost/preprocessor/config/config.hpp
|
||||
// http://www.boost.org/libs/preprocessor/doc/ref/variadics.html
|
||||
// However, supporting compiler detection is not complete. msgpack-c requires
|
||||
// variadic macro arguments support. So BOOST_PP_VARIADICS is defined here explicitly.
|
||||
#if !defined(MSGPACK_PP_VARIADICS)
|
||||
#define MSGPACK_PP_VARIADICS
|
||||
#endif
|
||||
|
||||
#include <msgpack/preprocessor.hpp>
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/v1/adaptor/detail/cpp03_define_map_decl.hpp"
|
||||
#include "msgpack/adaptor/msgpack_tuple.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
#define MSGPACK_DEFINE_MAP_EACH_PROC(r, data, elem) \
|
||||
MSGPACK_PP_IF( \
|
||||
MSGPACK_PP_IS_BEGIN_PARENS(elem), \
|
||||
elem, \
|
||||
(MSGPACK_PP_STRINGIZE(elem))(elem) \
|
||||
)
|
||||
|
||||
#define MSGPACK_DEFINE_MAP_IMPL(...) \
|
||||
MSGPACK_PP_SEQ_TO_TUPLE( \
|
||||
MSGPACK_PP_SEQ_FOR_EACH( \
|
||||
MSGPACK_DEFINE_MAP_EACH_PROC, \
|
||||
0, \
|
||||
MSGPACK_PP_VARIADIC_TO_SEQ(__VA_ARGS__) \
|
||||
) \
|
||||
)
|
||||
|
||||
#define MSGPACK_DEFINE_MAP(...) \
|
||||
template <typename Packer> \
|
||||
void msgpack_pack(Packer& pk) const \
|
||||
{ \
|
||||
msgpack::type::make_define_map \
|
||||
MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
|
||||
.msgpack_pack(pk); \
|
||||
} \
|
||||
void msgpack_unpack(msgpack::object const& o) \
|
||||
{ \
|
||||
msgpack::type::make_define_map \
|
||||
MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
|
||||
.msgpack_unpack(o); \
|
||||
}\
|
||||
template <typename MSGPACK_OBJECT> \
|
||||
void msgpack_object(MSGPACK_OBJECT* o, msgpack::zone& z) const \
|
||||
{ \
|
||||
msgpack::type::make_define_map \
|
||||
MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
|
||||
.msgpack_object(o, z); \
|
||||
}
|
||||
|
||||
#define MSGPACK_BASE_MAP(base) \
|
||||
(MSGPACK_PP_STRINGIZE(base))(*const_cast<base *>(static_cast<base const*>(this)))
|
||||
|
||||
namespace msgpack {
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
namespace type {
|
||||
|
||||
/// @cond
|
||||
<% GENERATION_LIMIT = 31 %>
|
||||
template <typename A0 = void<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%> = void<%}%>>
|
||||
struct define_map;
|
||||
/// @endcond
|
||||
|
||||
template <>
|
||||
struct define_map<> {
|
||||
template <typename Packer>
|
||||
@ -170,4 +114,4 @@ inline define_map<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_define_map(A0& a0<%1.
|
||||
/// @endcond
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP03_DEFINE_MAP_HPP
|
||||
#endif // MSGPACK_V1_CPP03_DEFINE_MAP_HPP
|
42
erb/v1/cpp03_define_map_decl.hpp.erb
Normal file
42
erb/v1/cpp03_define_map_decl.hpp.erb
Normal file
@ -0,0 +1,42 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015-2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP03_DEFINE_MAP_DECL_HPP
|
||||
#define MSGPACK_V1_CPP03_DEFINE_MAP_DECL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
namespace type {
|
||||
|
||||
/// @cond
|
||||
<% GENERATION_LIMIT = 31 %>
|
||||
template <typename A0 = void<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%> = void<%}%>>
|
||||
struct define_map;
|
||||
/// @endcond
|
||||
|
||||
define_map<> make_define_map();
|
||||
|
||||
/// @cond
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
define_map<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_define_map(A0& a0<%1.upto(i) {|j|%>, A<%=j%>& a<%=j%><%}%>);
|
||||
<%}%>
|
||||
/// @endcond
|
||||
|
||||
} // namespace type
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_CPP03_DEFINE_MAP_DECL_HPP
|
@ -1,18 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2013 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP03_MSGPACK_TUPLE_HPP
|
||||
#define MSGPACK_CPP03_MSGPACK_TUPLE_HPP
|
||||
#ifndef MSGPACK_V1_CPP03_MSGPACK_TUPLE_HPP
|
||||
#define MSGPACK_V1_CPP03_MSGPACK_TUPLE_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/v1/adaptor/msgpack_tuple_decl.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
@ -26,17 +24,6 @@ namespace type {
|
||||
// FIXME operator!=
|
||||
<% GENERATION_LIMIT = 31 %>
|
||||
|
||||
/// @cond
|
||||
template <typename A0 = void<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%> = void<%}%>>
|
||||
struct tuple;
|
||||
/// @endcond
|
||||
|
||||
template <typename Tuple, int N>
|
||||
struct tuple_element;
|
||||
|
||||
template <typename Tuple, int N>
|
||||
struct const_tuple_element;
|
||||
|
||||
template <typename T>
|
||||
struct tuple_type {
|
||||
typedef T type;
|
||||
@ -235,4 +222,4 @@ struct object_with_zone<type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> > {
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP03_MSGPACK_TUPLE_HPP
|
||||
#endif // MSGPACK_V1_CPP03_MSGPACK_TUPLE_HPP
|
69
erb/v1/cpp03_msgpack_tuple_decl.hpp.erb
Normal file
69
erb/v1/cpp03_msgpack_tuple_decl.hpp.erb
Normal file
@ -0,0 +1,69 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP03_MSGPACK_TUPLE_DECL_HPP
|
||||
#define MSGPACK_V1_CPP03_MSGPACK_TUPLE_DECL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
// FIXME operator==
|
||||
// FIXME operator!=
|
||||
<% GENERATION_LIMIT = 31 %>
|
||||
|
||||
/// @cond
|
||||
template <typename A0 = void<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%> = void<%}%>>
|
||||
struct tuple;
|
||||
/// @endcond
|
||||
|
||||
template <typename Tuple, int N>
|
||||
struct tuple_element;
|
||||
|
||||
template <typename Tuple, int N>
|
||||
struct const_tuple_element;
|
||||
|
||||
template <typename T>
|
||||
struct tuple_type;
|
||||
|
||||
/// @cond
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <int N, typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
typename type::tuple_element<type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>, N>::reference get(type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& t);
|
||||
template <int N, typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
typename type::const_tuple_element<type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>, N>::const_reference get(type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> const& t);
|
||||
<%}%>
|
||||
/// @endcond
|
||||
|
||||
tuple<> make_tuple();
|
||||
|
||||
/// @cond
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_tuple(typename tuple_type<A0>::transparent_reference a0<%1.upto(i) {|j|%>, typename tuple_type<A<%=j%>>::transparent_reference a<%=j%><%}%>);
|
||||
<%}%>
|
||||
/// @endcond
|
||||
|
||||
} // namespace type
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_CPP03_MSGPACK_TUPLE_DECL_HPP
|
@ -1,28 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ memory pool
|
||||
//
|
||||
// Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP03_ZONE_HPP
|
||||
#define MSGPACK_CPP03_ZONE_HPP
|
||||
#ifndef MSGPACK_V1_CPP03_ZONE_HPP
|
||||
#define MSGPACK_V1_CPP03_ZONE_HPP
|
||||
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
|
||||
#ifndef MSGPACK_ZONE_CHUNK_SIZE
|
||||
#define MSGPACK_ZONE_CHUNK_SIZE 8192
|
||||
#endif
|
||||
|
||||
#ifndef MSGPACK_ZONE_ALIGN
|
||||
#define MSGPACK_ZONE_ALIGN sizeof(void*)
|
||||
#endif
|
||||
#include "msgpack/zone_decl.hpp"
|
||||
|
||||
<% GENERATION_LIMIT = 15 %>
|
||||
namespace msgpack {
|
||||
@ -302,7 +290,7 @@ inline void zone::undo_allocate(size_t size)
|
||||
|
||||
inline std::size_t aligned_size(
|
||||
std::size_t size,
|
||||
std::size_t align = MSGPACK_ZONE_ALIGN) {
|
||||
std::size_t align) {
|
||||
return (size + align - 1) / align * align;
|
||||
}
|
||||
|
||||
@ -335,4 +323,4 @@ T* zone::allocate(<%=(1..i).map{|j|"A#{j} a#{j}"}.join(', ')%>)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP03_ZONE_HPP
|
||||
#endif // MSGPACK_V1_CPP03_ZONE_HPP
|
46
erb/v1/cpp03_zone_decl.hpp.erb
Normal file
46
erb/v1/cpp03_zone_decl.hpp.erb
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// MessagePack for C++ memory pool
|
||||
//
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP03_ZONE_DECL_HPP
|
||||
#define MSGPACK_V1_CPP03_ZONE_DECL_HPP
|
||||
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
|
||||
#ifndef MSGPACK_ZONE_CHUNK_SIZE
|
||||
#define MSGPACK_ZONE_CHUNK_SIZE 8192
|
||||
#endif
|
||||
|
||||
#ifndef MSGPACK_ZONE_ALIGN
|
||||
#define MSGPACK_ZONE_ALIGN sizeof(void*)
|
||||
#endif
|
||||
|
||||
<% GENERATION_LIMIT = 15 %>
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
class zone;
|
||||
|
||||
std::size_t aligned_size(
|
||||
std::size_t size,
|
||||
std::size_t align = MSGPACK_ZONE_ALIGN);
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_CPP03_ZONE_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
// Copyright (C) 2015-2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,75 +10,9 @@
|
||||
#ifndef MSGPACK_ADAPTOR_BASE_HPP
|
||||
#define MSGPACK_ADAPTOR_BASE_HPP
|
||||
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
template <typename Stream>
|
||||
class packer;
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
// Adaptor functors
|
||||
|
||||
template <typename T, typename Enabler = void>
|
||||
struct convert {
|
||||
msgpack::object const& operator()(msgpack::object const& o, T& v) const;
|
||||
};
|
||||
|
||||
template <typename T, typename Enabler = void>
|
||||
struct pack {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, T const& v) const;
|
||||
};
|
||||
|
||||
template <typename T, typename Enabler = void>
|
||||
struct object {
|
||||
void operator()(msgpack::object& o, T const& v) const;
|
||||
};
|
||||
|
||||
template <typename T, typename Enabler = void>
|
||||
struct object_with_zone {
|
||||
void operator()(msgpack::object::with_zone& o, T const& v) const;
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
// operators
|
||||
|
||||
template <typename T>
|
||||
inline
|
||||
msgpack::object const& operator>> (msgpack::object const& o, T& v) {
|
||||
return adaptor::convert<T>()(o, v);
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, T const& v) {
|
||||
return adaptor::pack<T>()(o, v);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline
|
||||
void operator<< (msgpack::object& o, T const& v) {
|
||||
adaptor::object<T>()(o, v);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline
|
||||
void operator<< (msgpack::object::with_zone& o, T const& v) {
|
||||
adaptor::object_with_zone<T>()(o, v);
|
||||
}
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/adaptor/adaptor_base_decl.hpp"
|
||||
|
||||
#include "msgpack/v1/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/v2/adaptor/adaptor_base.hpp"
|
||||
|
||||
#endif // MSGPACK_ADAPTOR_BASE_HPP
|
||||
|
16
include/msgpack/adaptor/adaptor_base_decl.hpp
Normal file
16
include/msgpack/adaptor/adaptor_base_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_ADAPTOR_BASE_DECL_HPP
|
||||
#define MSGPACK_ADAPTOR_BASE_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/adaptor_base_decl.hpp"
|
||||
#include "msgpack/v2/adaptor/adaptor_base_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_ADAPTOR_BASE_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,165 +10,8 @@
|
||||
#ifndef MSGPACK_TYPE_ARRAY_REF_HPP
|
||||
#define MSGPACK_TYPE_ARRAY_REF_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include "msgpack/adaptor/array_ref_decl.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
#include "msgpack/v1/adaptor/array_ref.hpp"
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
template <typename T>
|
||||
struct array_ref {
|
||||
array_ref() : data(nullptr) {}
|
||||
array_ref(T& t) : data(&t) {}
|
||||
|
||||
T* data;
|
||||
|
||||
template <typename U>
|
||||
bool operator==(array_ref<U> const& t) const {
|
||||
return *data == *t.data;
|
||||
}
|
||||
template <typename U>
|
||||
bool operator!=(array_ref<U> const& t) const {
|
||||
return !(*data == *t.data);
|
||||
}
|
||||
template <typename U>
|
||||
bool operator< (array_ref<U> const& t) const
|
||||
{
|
||||
return *data < *t.data;
|
||||
}
|
||||
template <typename U>
|
||||
bool operator> (array_ref<U> const& t) const
|
||||
{
|
||||
return *t.data < *data;
|
||||
}
|
||||
template <typename U>
|
||||
bool operator<= (array_ref<U> const& t) const
|
||||
{
|
||||
return !(*t.data < *data);
|
||||
}
|
||||
template <typename U>
|
||||
bool operator>= (array_ref<U> const& t) const
|
||||
{
|
||||
return !(*data < *t.data);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline array_ref<T const> make_array_ref(T const& t) {
|
||||
return array_ref<T const>(t);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline array_ref<T> make_array_ref(T& t) {
|
||||
return array_ref<T>(t);
|
||||
}
|
||||
|
||||
|
||||
} // namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T>
|
||||
struct convert<msgpack::type::array_ref<T> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, msgpack::type::array_ref<T>& v) const {
|
||||
if (!v.data) { throw msgpack::type_error(); }
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if (v.data->size() < o.via.bin.size) { throw msgpack::type_error(); }
|
||||
if (o.via.array.size > 0) {
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
typename T::iterator it = v.data->begin();
|
||||
do {
|
||||
p->convert(*it);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct convert<msgpack::type::array_ref<std::vector<T> > > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, msgpack::type::array_ref<std::vector<T> >& v) const {
|
||||
if (!v.data) { throw msgpack::type_error(); }
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
v.data->resize(o.via.bin.size);
|
||||
if (o.via.array.size > 0) {
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
typename std::vector<T>::iterator it = v.data->begin();
|
||||
do {
|
||||
p->convert(*it);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pack<msgpack::type::array_ref<T> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const msgpack::type::array_ref<T>& v) const {
|
||||
if (!v.data) { throw msgpack::type_error(); }
|
||||
uint32_t size = checked_get_container_size(v.data->size());
|
||||
o.pack_array(size);
|
||||
for (typename T::const_iterator it(v.data->begin()), it_end(v.data->end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object_with_zone<msgpack::type::array_ref<T> > {
|
||||
void operator()(msgpack::object::with_zone& o, const msgpack::type::array_ref<T>& v) const {
|
||||
if (!v.data) { throw msgpack::type_error(); }
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if (v.data->empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
}
|
||||
else {
|
||||
uint32_t size = checked_get_container_size(v.data->size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename T::const_iterator it(v.data->begin());
|
||||
do {
|
||||
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_ARRAY_REF_HPP
|
||||
#endif // MSGPACK_TYPE_ARRAY_REFL_HPP
|
||||
|
16
include/msgpack/adaptor/array_ref_decl.hpp
Normal file
16
include/msgpack/adaptor/array_ref_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// 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_TYPE_ARRAY_REF_DECL_HPP
|
||||
#define MSGPACK_TYPE_ARRAY_REF_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/array_ref_decl.hpp"
|
||||
#include "msgpack/v2/adaptor/array_ref_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_ARRAY_REF_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,57 +10,6 @@
|
||||
#ifndef MSGPACK_TYPE_BOOL_HPP
|
||||
#define MSGPACK_TYPE_BOOL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<bool> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, bool& v) const {
|
||||
if(o.type != msgpack::type::BOOLEAN) { throw msgpack::type_error(); }
|
||||
v = o.via.boolean;
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<bool> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const bool& v) const {
|
||||
if(v) { o.pack_true(); }
|
||||
else { o.pack_false(); }
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<bool> {
|
||||
void operator()(msgpack::object& o, bool v) const {
|
||||
o.type = msgpack::type::BOOLEAN;
|
||||
o.via.boolean = v;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<bool> {
|
||||
void operator()(msgpack::object::with_zone& o, bool v) const {
|
||||
static_cast<msgpack::object&>(o) << v;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/bool.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_BOOL_HPP
|
||||
|
@ -10,151 +10,6 @@
|
||||
#ifndef MSGPACK_TYPE_BOOST_FUSION_HPP
|
||||
#define MSGPACK_TYPE_BOOST_FUSION_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/meta.hpp"
|
||||
|
||||
#if !defined (MSGPACK_USE_CPP03)
|
||||
#include "msgpack/adaptor/cpp11/tuple.hpp"
|
||||
#endif // #if !defined (MSGPACK_USE_CPP03)
|
||||
|
||||
#include <boost/fusion/support/is_sequence.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/size.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/for_each.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/at.hpp>
|
||||
#include <boost/fusion/include/mpl.hpp>
|
||||
#include <boost/mpl/size.hpp>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
#if !defined (MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T>
|
||||
struct as<
|
||||
T,
|
||||
typename msgpack::enable_if<
|
||||
boost::fusion::traits::is_sequence<T>::value &&
|
||||
boost::mpl::fold<
|
||||
T,
|
||||
boost::mpl::bool_<true>,
|
||||
boost::mpl::if_ <
|
||||
boost::mpl::and_<
|
||||
boost::mpl::_1,
|
||||
msgpack::has_as<boost::mpl::_2>
|
||||
>,
|
||||
boost::mpl::bool_<true>,
|
||||
boost::mpl::bool_<false>
|
||||
>
|
||||
>::type::value
|
||||
>::type
|
||||
> {
|
||||
T operator()(msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if (o.via.array.size != checked_get_container_size(boost::mpl::size<T>::value)) {
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
using tuple_t = decltype(to_tuple(std::declval<T>(), gen_seq<boost::mpl::size<T>::value>()));
|
||||
return to_t(
|
||||
o.as<tuple_t>(),
|
||||
msgpack::gen_seq<boost::mpl::size<T>::value>());
|
||||
}
|
||||
template<std::size_t... Is, typename U>
|
||||
static std::tuple<
|
||||
typename std::remove_reference<
|
||||
typename boost::fusion::result_of::at_c<T, Is>::type
|
||||
>::type...>
|
||||
to_tuple(U const& u, seq<Is...>) {
|
||||
return std::make_tuple(boost::fusion::at_c<Is>(u)...);
|
||||
}
|
||||
template<std::size_t... Is, typename U>
|
||||
static T to_t(U const& u, seq<Is...>) {
|
||||
return T(std::get<Is>(u)...);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined (MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T>
|
||||
struct convert<T, typename msgpack::enable_if<boost::fusion::traits::is_sequence<T>::value>::type > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, T& v) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if (o.via.array.size != checked_get_container_size(boost::fusion::size(v))) {
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
uint32_t index = 0;
|
||||
boost::fusion::for_each(v, convert_imp(o, index));
|
||||
return o;
|
||||
}
|
||||
private:
|
||||
struct convert_imp {
|
||||
convert_imp(msgpack::object const& obj, uint32_t& index):obj_(obj), index_(index) {}
|
||||
template <typename U>
|
||||
void operator()(U& v) const {
|
||||
msgpack::adaptor::convert<U>()(obj_.via.array.ptr[index_++], v);
|
||||
}
|
||||
private:
|
||||
msgpack::object const& obj_;
|
||||
uint32_t& index_;
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pack<T, typename msgpack::enable_if<boost::fusion::traits::is_sequence<T>::value>::type > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const T& v) const {
|
||||
uint32_t size = checked_get_container_size(boost::fusion::size(v));
|
||||
o.pack_array(size);
|
||||
boost::fusion::for_each(v, pack_imp<Stream>(o));
|
||||
return o;
|
||||
}
|
||||
private:
|
||||
template <typename Stream>
|
||||
struct pack_imp {
|
||||
pack_imp(msgpack::packer<Stream>& stream):stream_(stream) {}
|
||||
template <typename U>
|
||||
void operator()(U const& v) const {
|
||||
stream_.pack(v);
|
||||
}
|
||||
private:
|
||||
msgpack::packer<Stream>& stream_;
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object_with_zone<T, typename msgpack::enable_if<boost::fusion::traits::is_sequence<T>::value>::type > {
|
||||
void operator()(msgpack::object::with_zone& o, const T& v) const {
|
||||
uint32_t size = checked_get_container_size(boost::fusion::size(v));
|
||||
o.type = msgpack::type::ARRAY;
|
||||
o.via.array.ptr = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
o.via.array.size = size;
|
||||
uint32_t count = 0;
|
||||
boost::fusion::for_each(v, with_zone_imp(o, count));
|
||||
}
|
||||
private:
|
||||
struct with_zone_imp {
|
||||
with_zone_imp(msgpack::object::with_zone const& obj, uint32_t& count):obj_(obj), count_(count) {}
|
||||
template <typename U>
|
||||
void operator()(U const& v) const {
|
||||
obj_.via.array.ptr[count_++] = msgpack::object(v, obj_.zone);
|
||||
}
|
||||
msgpack::object::with_zone const& obj_;
|
||||
uint32_t& count_;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/boost/fusion.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_BOOST_FUSION_HPP
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
// Copyright (C) 2015-2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,421 +10,9 @@
|
||||
#ifndef MSGPACK_TYPE_BOOST_MSGPACK_VARIANT_HPP
|
||||
#define MSGPACK_TYPE_BOOST_MSGPACK_VARIANT_HPP
|
||||
|
||||
#if defined(MSGPACK_USE_BOOST)
|
||||
#include "msgpack/adaptor/boost/msgpack_variant_decl.hpp"
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/adaptor/boost/string_ref.hpp"
|
||||
#include "msgpack/v1/adaptor/boost/msgpack_variant.hpp"
|
||||
//#include "msgpack/v2/adaptor/boost/msgpack_variant.hpp"
|
||||
|
||||
#include "msgpack/adaptor/nil.hpp"
|
||||
#include "msgpack/adaptor/bool.hpp"
|
||||
#include "msgpack/adaptor/int.hpp"
|
||||
#include "msgpack/adaptor/float.hpp"
|
||||
#include "msgpack/adaptor/string.hpp"
|
||||
#include "msgpack/adaptor/vector_char.hpp"
|
||||
#include "msgpack/adaptor/raw.hpp"
|
||||
#include "msgpack/adaptor/ext.hpp"
|
||||
#include "msgpack/adaptor/vector.hpp"
|
||||
#include "msgpack/adaptor/map.hpp"
|
||||
|
||||
#include <boost/variant.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
struct basic_variant :
|
||||
boost::variant<
|
||||
nil_t, // NIL
|
||||
bool, // BOOL
|
||||
int64_t, // NEGATIVE_INTEGER
|
||||
uint64_t, // POSITIVE_INTEGER
|
||||
double, // FLOAT
|
||||
std::string, // STR
|
||||
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
boost::string_ref, // STR
|
||||
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
std::vector<char>, // BIN
|
||||
msgpack::type::raw_ref, // BIN
|
||||
ext, // EXT
|
||||
ext_ref, // EXT
|
||||
boost::recursive_wrapper<std::vector<basic_variant<STR, BIN, EXT> > >, // ARRAY
|
||||
boost::recursive_wrapper<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >, // MAP
|
||||
boost::recursive_wrapper<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >// MAP
|
||||
>,
|
||||
private boost::totally_ordered<basic_variant<STR, BIN, EXT> > {
|
||||
typedef boost::variant<
|
||||
nil_t, // NIL
|
||||
bool, // BOOL
|
||||
int64_t, // NEGATIVE_INTEGER
|
||||
uint64_t, // POSITIVE_INTEGER
|
||||
double, // FLOAT
|
||||
std::string, // STR
|
||||
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
boost::string_ref, // STR
|
||||
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
std::vector<char>, // BIN
|
||||
msgpack::type::raw_ref, // BIN
|
||||
ext, // EXT
|
||||
ext_ref, // EXT
|
||||
boost::recursive_wrapper<std::vector<basic_variant<STR, BIN, EXT> > >, // ARRAY
|
||||
boost::recursive_wrapper<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >, // MAP
|
||||
boost::recursive_wrapper<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >// MAP
|
||||
> base;
|
||||
basic_variant() {}
|
||||
template <typename T>
|
||||
basic_variant(T const& t):base(t) {}
|
||||
basic_variant(char const* p):base(std::string(p)) {}
|
||||
basic_variant(char v) {
|
||||
int_init(v);
|
||||
}
|
||||
basic_variant(signed char v) {
|
||||
int_init(v);
|
||||
}
|
||||
basic_variant(unsigned char v):base(uint64_t(v)) {}
|
||||
basic_variant(signed int v) {
|
||||
int_init(v);
|
||||
}
|
||||
basic_variant(unsigned int v):base(uint64_t(v)) {}
|
||||
basic_variant(signed long v) {
|
||||
int_init(v);
|
||||
}
|
||||
basic_variant(unsigned long v):base(uint64_t(v)) {}
|
||||
basic_variant(signed long long v) {
|
||||
int_init(v);
|
||||
}
|
||||
basic_variant(unsigned long long v):base(uint64_t(v)) {}
|
||||
|
||||
bool is_nil() const {
|
||||
return boost::get<msgpack::type::nil_t>(this);
|
||||
}
|
||||
bool is_bool() const {
|
||||
return boost::get<bool>(this);
|
||||
}
|
||||
bool is_int64_t() const {
|
||||
return boost::get<int64_t>(this);
|
||||
}
|
||||
bool is_uint64_t() const {
|
||||
return boost::get<uint64_t>(this);
|
||||
}
|
||||
bool is_double() const {
|
||||
return boost::get<double>(this);
|
||||
}
|
||||
bool is_string() const {
|
||||
return boost::get<std::string>(this);
|
||||
}
|
||||
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
bool is_boost_string_ref() const {
|
||||
return boost::get<boost::string_ref>(this);
|
||||
}
|
||||
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
bool is_vector_char() const {
|
||||
return boost::get<std::vector<char> >(this);
|
||||
}
|
||||
bool is_vector_char() {
|
||||
return boost::get<std::vector<char> >(this);
|
||||
}
|
||||
bool is_raw_ref() const {
|
||||
return boost::get<raw_ref>(this);
|
||||
}
|
||||
bool is_ext() const {
|
||||
return boost::get<ext>(this);
|
||||
}
|
||||
bool is_ext_ref() const {
|
||||
return boost::get<ext_ref>(this);
|
||||
}
|
||||
bool is_vector() const {
|
||||
return boost::get<std::vector<basic_variant<STR, BIN, EXT> > >(this);
|
||||
}
|
||||
bool is_map() const {
|
||||
return boost::get<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(this);
|
||||
}
|
||||
bool is_multimap() const {
|
||||
return boost::get<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(this);
|
||||
}
|
||||
|
||||
bool as_bool() const {
|
||||
return boost::get<bool>(*this);
|
||||
}
|
||||
int64_t as_int64_t() const {
|
||||
return boost::get<int64_t>(*this);
|
||||
}
|
||||
int64_t& as_int64_t() {
|
||||
return boost::get<int64_t>(*this);
|
||||
}
|
||||
uint64_t as_uint64_t() const {
|
||||
return boost::get<uint64_t>(*this);
|
||||
}
|
||||
uint64_t& as_uint64_t() {
|
||||
return boost::get<uint64_t>(*this);
|
||||
}
|
||||
double as_double() const {
|
||||
return boost::get<double>(*this);
|
||||
}
|
||||
double& as_double() {
|
||||
return boost::get<double>(*this);
|
||||
}
|
||||
std::string const& as_string() const {
|
||||
return boost::get<std::string>(*this);
|
||||
}
|
||||
std::string& as_string() {
|
||||
return boost::get<std::string>(*this);
|
||||
}
|
||||
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
boost::string_ref const& as_boost_string_ref() const {
|
||||
return boost::get<boost::string_ref>(*this);
|
||||
}
|
||||
boost::string_ref& as_boost_string_ref() {
|
||||
return boost::get<boost::string_ref>(*this);
|
||||
}
|
||||
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
std::vector<char> const& as_vector_char() const {
|
||||
return boost::get<std::vector<char> >(*this);
|
||||
}
|
||||
std::vector<char>& as_vector_char() {
|
||||
return boost::get<std::vector<char> >(*this);
|
||||
}
|
||||
raw_ref const& as_raw_ref() const {
|
||||
return boost::get<raw_ref>(*this);
|
||||
}
|
||||
ext const& as_ext() const {
|
||||
return boost::get<ext>(*this);
|
||||
}
|
||||
ext& as_ext() {
|
||||
return boost::get<ext>(*this);
|
||||
}
|
||||
ext_ref const& as_ext_ref() const {
|
||||
return boost::get<ext_ref>(*this);
|
||||
}
|
||||
std::vector<basic_variant<STR, BIN, EXT> > const& as_vector() const {
|
||||
return boost::get<std::vector<basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
std::vector<basic_variant<STR, BIN, EXT> >& as_vector() {
|
||||
return boost::get<std::vector<basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > const& as_map() const {
|
||||
return boost::get<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> >& as_map() {
|
||||
return boost::get<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > const& as_multimap() const {
|
||||
return boost::get<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> >& as_multimap() {
|
||||
return boost::get<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
private:
|
||||
template <typename T>
|
||||
void int_init(T v) {
|
||||
if (v < 0) {
|
||||
static_cast<base&>(*this) = int64_t(v);
|
||||
}
|
||||
else {
|
||||
static_cast<base&>(*this) = uint64_t(v);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
inline bool operator<(basic_variant<STR, BIN, EXT> const& lhs, basic_variant<STR, BIN, EXT> const& rhs) {
|
||||
return
|
||||
static_cast<typename basic_variant<STR, BIN, EXT>::base const&>(lhs) <
|
||||
static_cast<typename basic_variant<STR, BIN, EXT>::base const&>(rhs);
|
||||
}
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
inline bool operator==(basic_variant<STR, BIN, EXT> const& lhs, basic_variant<STR, BIN, EXT> const& rhs) {
|
||||
return
|
||||
static_cast<typename basic_variant<STR, BIN, EXT>::base const&>(lhs) ==
|
||||
static_cast<typename basic_variant<STR, BIN, EXT>::base const&>(rhs);
|
||||
}
|
||||
|
||||
typedef basic_variant<std::string, std::vector<char>, ext> variant;
|
||||
typedef basic_variant<
|
||||
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
boost::string_ref,
|
||||
#else // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
std::string,
|
||||
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
raw_ref, ext_ref> variant_ref;
|
||||
|
||||
} // namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
#if !defined (MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
struct as<msgpack::type::basic_variant<STR, BIN, EXT> > {
|
||||
msgpack::type::basic_variant<STR, BIN, EXT> operator()(msgpack::object const& o) const {
|
||||
switch(o.type) {
|
||||
case type::NIL:
|
||||
return o.as<msgpack::type::nil_t>();
|
||||
case type::BOOLEAN:
|
||||
return o.as<bool>();
|
||||
case type::POSITIVE_INTEGER:
|
||||
return o.as<uint64_t>();
|
||||
case type::NEGATIVE_INTEGER:
|
||||
return o.as<int64_t>();
|
||||
case type::FLOAT:
|
||||
return o.as<double>();
|
||||
case type::STR:
|
||||
return o.as<STR>();
|
||||
case type::BIN:
|
||||
return o.as<BIN>();
|
||||
case type::EXT:
|
||||
return o.as<EXT>();
|
||||
case type::ARRAY:
|
||||
return o.as<std::vector<msgpack::type::basic_variant<STR, BIN, EXT> > >();
|
||||
case type::MAP:
|
||||
return o.as<std::multimap<msgpack::type::basic_variant<STR, BIN, EXT>, msgpack::type::basic_variant<STR, BIN, EXT> > >();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return msgpack::type::basic_variant<STR, BIN, EXT>();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined (MSGPACK_USE_CPP03)
|
||||
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
struct convert<msgpack::type::basic_variant<STR, BIN, EXT> > {
|
||||
msgpack::object const& operator()(
|
||||
msgpack::object const& o,
|
||||
msgpack::type::basic_variant<STR, BIN, EXT>& v) const {
|
||||
switch(o.type) {
|
||||
case type::NIL:
|
||||
v = o.as<msgpack::type::nil_t>();
|
||||
break;
|
||||
case type::BOOLEAN:
|
||||
v = o.as<bool>();
|
||||
break;
|
||||
case type::POSITIVE_INTEGER:
|
||||
v = o.as<uint64_t>();
|
||||
break;
|
||||
case type::NEGATIVE_INTEGER:
|
||||
v = o.as<int64_t>();
|
||||
break;
|
||||
case type::FLOAT:
|
||||
v = o.as<double>();
|
||||
break;
|
||||
case type::STR:
|
||||
v = o.as<STR>();
|
||||
break;
|
||||
case type::BIN:
|
||||
v = o.as<BIN>();
|
||||
break;
|
||||
case type::EXT:
|
||||
v = o.as<EXT>();
|
||||
break;
|
||||
case type::ARRAY:
|
||||
v = o.as<std::vector<msgpack::type::basic_variant<STR, BIN, EXT> > >();
|
||||
break;
|
||||
case type::MAP:
|
||||
v = o.as<std::multimap<msgpack::type::basic_variant<STR, BIN, EXT>, msgpack::type::basic_variant<STR, BIN, EXT> > >();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename Stream>
|
||||
struct pack_imp : boost::static_visitor<void> {
|
||||
template <typename T>
|
||||
void operator()(T const& value) const {
|
||||
pack<T>()(o_, value);
|
||||
}
|
||||
pack_imp(packer<Stream>& o):o_(o) {}
|
||||
packer<Stream>& o_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
struct pack<msgpack::type::basic_variant<STR, BIN, EXT> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const msgpack::type::basic_variant<STR, BIN, EXT>& v) const {
|
||||
boost::apply_visitor(detail::pack_imp<Stream>(o), v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct object_imp : boost::static_visitor<void> {
|
||||
void operator()(msgpack::type::nil_t const& v) const {
|
||||
object<msgpack::type::nil_t>()(o_, v);
|
||||
}
|
||||
void operator()(bool const& v) const {
|
||||
object<bool>()(o_, v);
|
||||
}
|
||||
void operator()(uint64_t const& v) const {
|
||||
object<uint64_t>()(o_, v);
|
||||
}
|
||||
void operator()(int64_t const& v) const {
|
||||
object<int64_t>()(o_, v);
|
||||
}
|
||||
void operator()(double const& v) const {
|
||||
object<double>()(o_, v);
|
||||
}
|
||||
template <typename T>
|
||||
void operator()(T const&) const {
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
object_imp(msgpack::object& o):o_(o) {}
|
||||
msgpack::object& o_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
struct object<msgpack::type::basic_variant<STR, BIN, EXT> > {
|
||||
void operator()(msgpack::object& o, const msgpack::type::basic_variant<STR, BIN, EXT>& v) const {
|
||||
boost::apply_visitor(detail::object_imp(o), v);
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct object_with_zone_imp : boost::static_visitor<void> {
|
||||
template <typename T>
|
||||
void operator()(T const& v) const {
|
||||
object_with_zone<T>()(o_, v);
|
||||
}
|
||||
object_with_zone_imp(msgpack::object::with_zone& o):o_(o) {}
|
||||
msgpack::object::with_zone& o_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
struct object_with_zone<msgpack::type::basic_variant<STR, BIN, EXT> > {
|
||||
void operator()(msgpack::object::with_zone& o, const msgpack::type::basic_variant<STR, BIN, EXT>& v) const {
|
||||
boost::apply_visitor(detail::object_with_zone_imp(o), v);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_USE_BOOST
|
||||
#endif // MSGPACK_TYPE_BOOST_MSGPACK_VARIANT_HPP
|
||||
|
16
include/msgpack/adaptor/boost/msgpack_variant_decl.hpp
Normal file
16
include/msgpack/adaptor/boost/msgpack_variant_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_TYPE_BOOST_MSGPACK_VARIANT_DECL_HPP
|
||||
#define MSGPACK_TYPE_BOOST_MSGPACK_VARIANT_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/boost/msgpack_variant_decl.hpp"
|
||||
#include "msgpack/v2/adaptor/boost/msgpack_variant_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_BOOST_MSGPACK_VARIANT_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,87 +10,6 @@
|
||||
#ifndef MSGPACK_TYPE_BOOST_OPTIONAL_HPP
|
||||
#define MSGPACK_TYPE_BOOST_OPTIONAL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
// To suppress warning on Boost.1.58.0
|
||||
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
#if !defined (MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T>
|
||||
struct as<boost::optional<T>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||
boost::optional<T> operator()(msgpack::object const& o) const {
|
||||
if(o.is_nil()) return boost::none;
|
||||
return o.as<T>();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined (MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T>
|
||||
struct convert<boost::optional<T> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, boost::optional<T>& v) const {
|
||||
if(o.is_nil()) v = boost::none;
|
||||
else {
|
||||
T t;
|
||||
msgpack::adaptor::convert<T>()(o, t);
|
||||
v = t;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pack<boost::optional<T> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const boost::optional<T>& v) const {
|
||||
if (v) o.pack(*v);
|
||||
else o.pack_nil();
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object<boost::optional<T> > {
|
||||
void operator()(msgpack::object& o, const boost::optional<T>& v) const {
|
||||
if (v) msgpack::adaptor::object<T>()(o, *v);
|
||||
else o.type = msgpack::type::NIL;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object_with_zone<boost::optional<T> > {
|
||||
void operator()(msgpack::object::with_zone& o, const boost::optional<T>& v) const {
|
||||
if (v) msgpack::adaptor::object_with_zone<T>()(o, *v);
|
||||
else o.type = msgpack::type::NIL;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/boost/optional.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_BOOST_OPTIONAL_HPP
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,78 +10,6 @@
|
||||
#ifndef MSGPACK_TYPE_BOOST_STRING_REF_HPP
|
||||
#define MSGPACK_TYPE_BOOST_STRING_REF_HPP
|
||||
|
||||
#include <boost/version.hpp>
|
||||
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<boost::string_ref> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, boost::string_ref& v) const {
|
||||
switch (o.type) {
|
||||
case msgpack::type::BIN:
|
||||
v = boost::string_ref(o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case msgpack::type::STR:
|
||||
v = boost::string_ref(o.via.str.ptr, o.via.str.size);
|
||||
break;
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<boost::string_ref> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const boost::string_ref& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_str(size);
|
||||
o.pack_str_body(v.data(), size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<boost::string_ref> {
|
||||
void operator()(msgpack::object& o, const boost::string_ref& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::STR;
|
||||
o.via.str.ptr = v.data();
|
||||
o.via.str.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<boost::string_ref> {
|
||||
void operator()(msgpack::object::with_zone& o, const boost::string_ref& v) const {
|
||||
static_cast<msgpack::object&>(o) << v;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
#include "msgpack/v1/adaptor/boost/string_ref.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_BOOST_STRING_REF_HPP
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,148 +10,6 @@
|
||||
#ifndef MSGPACK_TYPE_CHAR_PTR_HPP
|
||||
#define MSGPACK_TYPE_CHAR_PTR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct pack<const char*> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.pack_str(size);
|
||||
o.pack_str_body(v, size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<const char*> {
|
||||
void operator()(msgpack::object::with_zone& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.type = msgpack::type::STR;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.str.ptr = ptr;
|
||||
o.via.str.size = size;
|
||||
std::memcpy(ptr, v, size);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<const char*> {
|
||||
void operator()(msgpack::object& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.type = msgpack::type::STR;
|
||||
o.via.str.ptr = v;
|
||||
o.via.str.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct pack<char*> {
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator()(packer<Stream>& o, char* v) const {
|
||||
return o << static_cast<const char*>(v);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<char*> {
|
||||
void operator()(msgpack::object::with_zone& o, char* v) const {
|
||||
o << static_cast<const char*>(v);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<char*> {
|
||||
void operator()(msgpack::object& o, char* v) const {
|
||||
o << static_cast<const char*>(v);
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct pack<char[N]> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.pack_str(size);
|
||||
o.pack_str_body(v, size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object_with_zone<char[N]> {
|
||||
void operator()(msgpack::object::with_zone& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.type = msgpack::type::STR;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.str.ptr = ptr;
|
||||
o.via.str.size = size;
|
||||
std::memcpy(ptr, v, size);
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object<char[N]> {
|
||||
void operator()(msgpack::object& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.type = msgpack::type::STR;
|
||||
o.via.str.ptr = v;
|
||||
o.via.str.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct pack<const char[N]> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.pack_str(size);
|
||||
o.pack_str_body(v, size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object_with_zone<const char[N]> {
|
||||
void operator()(msgpack::object::with_zone& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.type = msgpack::type::STR;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.str.ptr = ptr;
|
||||
o.via.str.size = size;
|
||||
std::memcpy(ptr, v, size);
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object<const char[N]> {
|
||||
void operator()(msgpack::object& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.type = msgpack::type::STR;
|
||||
o.via.str.ptr = v;
|
||||
o.via.str.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/char_ptr.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_CHAR_PTR_HPP
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
// Copyright (C) 2015-2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,58 +10,8 @@
|
||||
#ifndef MSGPACK_CHECK_CONTAINER_SIZE_HPP
|
||||
#define MSGPACK_CHECK_CONTAINER_SIZE_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include <stdexcept>
|
||||
#include "msgpack/adaptor/check_container_size_decl.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
struct container_size_overflow : public std::runtime_error {
|
||||
explicit container_size_overflow(const std::string& msg)
|
||||
:std::runtime_error(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
explicit container_size_overflow(const char* msg):
|
||||
std::runtime_error(msg) {}
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <std::size_t N>
|
||||
inline void check_container_size(std::size_t size) {
|
||||
if (size > 0xffffffff) throw container_size_overflow("container size overflow");
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void check_container_size<4>(std::size_t /*size*/) {
|
||||
}
|
||||
|
||||
template <std::size_t N>
|
||||
inline void check_container_size_for_ext(std::size_t size) {
|
||||
if (size > 0xffffffff) throw container_size_overflow("container size overflow");
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void check_container_size_for_ext<4>(std::size_t size) {
|
||||
if (size > 0xfffffffe) throw container_size_overflow("container size overflow");
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename T>
|
||||
inline uint32_t checked_get_container_size(T size) {
|
||||
detail::check_container_size<sizeof(T)>(size);
|
||||
return static_cast<uint32_t>(size);
|
||||
}
|
||||
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/check_container_size.hpp"
|
||||
|
||||
#endif // MSGPACK_CHECK_CONTAINER_SIZE_HPP
|
||||
|
16
include/msgpack/adaptor/check_container_size_decl.hpp
Normal file
16
include/msgpack/adaptor/check_container_size_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_CHECK_CONTAINER_SIZE_DECL_HPP
|
||||
#define MSGPACK_CHECK_CONTAINER_SIZE_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/check_container_size_decl.hpp"
|
||||
#include "msgpack/v2/adaptor/check_container_size_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_CHECK_CONTAINER_SIZE_DECL_HPP
|
@ -1,138 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP11_ARRAY_HPP
|
||||
#define MSGPACK_CPP11_ARRAY_HPP
|
||||
#ifndef MSGPACK_TYPE_CPP11_ARRAY_HPP
|
||||
#define MSGPACK_TYPE_CPP11_ARRAY_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/meta.hpp"
|
||||
#include "msgpack/v1/adaptor/cpp11/array.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
namespace detail {
|
||||
|
||||
namespace array {
|
||||
|
||||
template<typename T, std::size_t N1, std::size_t... I1, std::size_t N2, std::size_t... I2>
|
||||
inline std::array<T, N1+N2> concat(
|
||||
std::array<T, N1>&& a1,
|
||||
std::array<T, N2>&& a2,
|
||||
msgpack::seq<I1...>,
|
||||
msgpack::seq<I2...>) {
|
||||
return {{ std::move(a1[I1])..., std::move(a2[I2])... }};
|
||||
}
|
||||
|
||||
template<typename T, std::size_t N1, std::size_t N2>
|
||||
inline std::array<T, N1+N2> concat(std::array<T, N1>&& a1, std::array<T, N2>&& a2) {
|
||||
return concat(std::move(a1), std::move(a2), msgpack::gen_seq<N1>(), msgpack::gen_seq<N2>());
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
struct as_impl {
|
||||
static std::array<T, N> as(msgpack::object const& o) {
|
||||
msgpack::object* p = o.via.array.ptr + N - 1;
|
||||
return concat(as_impl<T, N-1>::as(o), std::array<T, 1>{{p->as<T>()}});
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct as_impl<T, 1> {
|
||||
static std::array<T, 1> as(msgpack::object const& o) {
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
return std::array<T, 1>{{p->as<T>()}};
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct as_impl<T, 0> {
|
||||
static std::array<T, 0> as(msgpack::object const&) {
|
||||
return std::array<T, 0>();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace array
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
struct as<std::array<T, N>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||
std::array<T, N> operator()(msgpack::object const& o) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size != N) { throw msgpack::type_error(); }
|
||||
return detail::array::as_impl<T, N>::as(o);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
struct convert<std::array<T, N>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::array<T, N>& v) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size != N) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size > 0) {
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
T* it = &v[0];
|
||||
do {
|
||||
p->convert(*it);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
struct pack<std::array<T, N>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::array<T, N>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(auto const& e : v) o.pack(e);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
struct object_with_zone<std::array<T, N>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::array<T, N>& v) const {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
o.via.array.size = size;
|
||||
o.via.array.ptr = p;
|
||||
for (auto const& e : v) *p++ = msgpack::object(e, o.zone);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_ARRAY_HPP
|
||||
#endif // MSGPACK_TYPE_CPP11_ARRAY_HPP
|
||||
|
@ -1,89 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_TYPE_ARRAY_CHAR_HPP
|
||||
#define MSGPACK_TYPE_ARRAY_CHAR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#ifndef MSGPACK_TYPE_CPP11_ARRAY_CHAR_HPP
|
||||
#define MSGPACK_TYPE_CPP11_ARRAY_CHAR_HPP
|
||||
|
||||
#include <array>
|
||||
#include "msgpack/v1/adaptor/cpp11/array_char.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <std::size_t N>
|
||||
struct convert<std::array<char, N>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::array<char, N>& v) const {
|
||||
switch (o.type) {
|
||||
case msgpack::type::BIN:
|
||||
if(o.via.bin.size != N) { throw msgpack::type_error(); }
|
||||
std::memcpy(v.data(), o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case msgpack::type::STR:
|
||||
if(o.via.str.size != N) { throw msgpack::type_error(); }
|
||||
std::memcpy(v.data(), o.via.str.ptr, N);
|
||||
break;
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct pack<std::array<char, N>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::array<char, N>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_bin(size);
|
||||
o.pack_bin_body(v.data(), size);
|
||||
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object<std::array<char, N>> {
|
||||
void operator()(msgpack::object& o, const std::array<char, N>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
o.via.bin.ptr = v.data();
|
||||
o.via.bin.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object_with_zone<std::array<char, N>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::array<char, N>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.bin.ptr = ptr;
|
||||
o.via.bin.size = size;
|
||||
std::memcpy(ptr, v.data(), size);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_ARRAY_CHAR_HPP
|
||||
#endif // MSGPACK_TYPE_CPP11_ARRAY_CHAR_HPP
|
||||
|
@ -1,89 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_TYPE_ARRAY_UNSIGNED_CHAR_HPP
|
||||
#define MSGPACK_TYPE_ARRAY_UNSIGNED_CHAR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#ifndef MSGPACK_TYPE_CPP11_ARRAY_UNSIGNED_CHAR_HPP
|
||||
#define MSGPACK_TYPE_CPP11_ARRAY_UNSIGNED_CHAR_HPP
|
||||
|
||||
#include <array>
|
||||
#include "msgpack/v1/adaptor/cpp11/array_unsigned_char.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <std::size_t N>
|
||||
struct convert<std::array<unsigned char, N>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::array<unsigned char, N>& v) const {
|
||||
switch (o.type) {
|
||||
case msgpack::type::BIN:
|
||||
if(o.via.bin.size != N) { throw msgpack::type_error(); }
|
||||
std::memcpy(v.data(), o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case msgpack::type::STR:
|
||||
if(o.via.str.size != N) { throw msgpack::type_error(); }
|
||||
std::memcpy(v.data(), o.via.str.ptr, N);
|
||||
break;
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct pack<std::array<unsigned char, N>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::array<unsigned char, N>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_bin(size);
|
||||
o.pack_bin_body(reinterpret_cast<char const*>(v.data()), size);
|
||||
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object<std::array<unsigned char, N>> {
|
||||
void operator()(msgpack::object& o, const std::array<unsigned char, N>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
o.via.bin.ptr = reinterpret_cast<char const*>(v.data());
|
||||
o.via.bin.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object_with_zone<std::array<unsigned char, N>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::array<unsigned char, N>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.bin.ptr = ptr;
|
||||
o.via.bin.size = size;
|
||||
std::memcpy(ptr, v.data(), size);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_ARRAY_UNSIGNED_CHAR_HPP
|
||||
#endif // MSGPACK_TYPE_CPP11_ARRAY_UNSIGNED_CHAR_HPP
|
||||
|
@ -1,94 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO-2015 Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP11_FORWARD_LIST_HPP
|
||||
#define MSGPACK_CPP11_FORWARD_LIST_HPP
|
||||
#ifndef MSGPACK_TYPE_CPP11_FORWARD_LIST_HPP
|
||||
#define MSGPACK_TYPE_CPP11_FORWARD_LIST_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/v1/adaptor/cpp11/forward_list.hpp"
|
||||
|
||||
#include <forward_list>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct as<std::forward_list<T, Alloc>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||
std::forward_list<T, Alloc> operator()(msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
std::forward_list<T, Alloc> v;
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pend = o.via.array.ptr;
|
||||
while (p != pend) {
|
||||
--p;
|
||||
v.push_front(p->as<T>());
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct convert<std::forward_list<T, Alloc>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::forward_list<T, Alloc>& v) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
v.resize(o.via.array.size);
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
for (auto &e : v) {
|
||||
p->convert(e);
|
||||
++p;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct pack<std::forward_list<T, Alloc>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::forward_list<T, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(std::distance(v.begin(), v.end()));
|
||||
o.pack_array(size);
|
||||
for(auto const& e : v) o.pack(e);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct object_with_zone<std::forward_list<T, Alloc>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::forward_list<T, Alloc>& v) const {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(std::distance(v.begin(), v.end()));
|
||||
o.via.array.size = size;
|
||||
msgpack::object* p = static_cast<msgpack::object*>(
|
||||
o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
o.via.array.ptr = p;
|
||||
for(auto const& e : v) *p++ = msgpack::object(e, o.zone);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_FORWARD_LIST_HPP
|
||||
#endif // MSGPACK_TYPE_CPP11_FORWARD_LIST_HPP
|
||||
|
@ -1,68 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP11_REFERENCE_WRAPPER_HPP
|
||||
#define MSGPACK_CPP11_REFERENCE_WRAPPER_HPP
|
||||
#ifndef MSGPACK_TYPE_CPP11_REFERENCE_WRAPPER_HPP
|
||||
#define MSGPACK_TYPE_CPP11_REFERENCE_WRAPPER_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/v1/adaptor/cpp11/reference_wrapper.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T>
|
||||
struct convert<std::reference_wrapper<T>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::reference_wrapper<T>& v) const {
|
||||
msgpack::adaptor::convert<T>()(o, v.get());
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pack<std::reference_wrapper<T>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::reference_wrapper<T>& v) const {
|
||||
o.pack(v.get());
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object<std::reference_wrapper<T> > {
|
||||
void operator()(msgpack::object& o, const std::reference_wrapper<T>& v) const {
|
||||
msgpack::adaptor::object<typename std::remove_const<T>::type>()(o, v.get());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object_with_zone<std::reference_wrapper<T>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::reference_wrapper<T>& v) const {
|
||||
msgpack::adaptor::object_with_zone<typename std::remove_const<T>::type>()(o, v.get());
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_REFERENCE_WRAPPER_HPP
|
||||
#endif // MSGPACK_TYPE_CPP11_REFERENCE_WRAPPER_HPP
|
||||
|
@ -1,82 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP11_SHARED_PTR_HPP
|
||||
#define MSGPACK_CPP11_SHARED_PTR_HPP
|
||||
#ifndef MSGPACK_TYPE_CPP11_SHARED_PTR_HPP
|
||||
#define MSGPACK_TYPE_CPP11_SHARED_PTR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/v1/adaptor/cpp11/shared_ptr.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T>
|
||||
struct as<std::shared_ptr<T>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||
std::shared_ptr<T> operator()(msgpack::object const& o) const {
|
||||
if(o.is_nil()) return nullptr;
|
||||
return std::make_shared<T>(o.as<T>());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct convert<std::shared_ptr<T>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::shared_ptr<T>& v) const {
|
||||
if(o.is_nil()) v.reset();
|
||||
else {
|
||||
v = std::make_shared<T>();
|
||||
msgpack::adaptor::convert<T>()(o, *v);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pack<std::shared_ptr<T>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::shared_ptr<T>& v) const {
|
||||
if (v) o.pack(*v);
|
||||
else o.pack_nil();
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object<std::shared_ptr<T> > {
|
||||
void operator()(msgpack::object& o, const std::shared_ptr<T>& v) const {
|
||||
if (v) msgpack::adaptor::object<T>()(o, *v);
|
||||
else o.type = msgpack::type::NIL;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object_with_zone<std::shared_ptr<T>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::shared_ptr<T>& v) const {
|
||||
if (v) msgpack::adaptor::object_with_zone<T>()(o, *v);
|
||||
else o.type = msgpack::type::NIL;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_SHARED_PTR_HPP
|
||||
#endif // MSGPACK_TYPE_CPP11_SHARED_PTR_HPP
|
||||
|
@ -1,176 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP11_TUPLE_HPP
|
||||
#define MSGPACK_CPP11_TUPLE_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/meta.hpp"
|
||||
#ifndef MSGPACK_TYPE_CPP11_TUPLE_HPP
|
||||
#define MSGPACK_TYPE_CPP11_TUPLE_HPP
|
||||
|
||||
#include <tuple>
|
||||
#include "msgpack/v1/adaptor/cpp11/tuple.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
// --- Pack from tuple to packer stream ---
|
||||
template <typename Stream, typename Tuple, std::size_t N>
|
||||
struct StdTuplePacker {
|
||||
static void pack(
|
||||
msgpack::packer<Stream>& o,
|
||||
const Tuple& v) {
|
||||
StdTuplePacker<Stream, Tuple, N-1>::pack(o, v);
|
||||
o.pack(std::get<N-1>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename Tuple>
|
||||
struct StdTuplePacker<Stream, Tuple, 0> {
|
||||
static void pack (
|
||||
msgpack::packer<Stream>&,
|
||||
const Tuple&) {
|
||||
}
|
||||
};
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename... Args>
|
||||
struct pack<std::tuple<Args...>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(
|
||||
msgpack::packer<Stream>& o,
|
||||
const std::tuple<Args...>& v) const {
|
||||
uint32_t size = checked_get_container_size(sizeof...(Args));
|
||||
o.pack_array(size);
|
||||
StdTuplePacker<Stream, decltype(v), sizeof...(Args)>::pack(o, v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
// --- Convert from tuple to object ---
|
||||
|
||||
template <typename... Args>
|
||||
struct StdTupleAs;
|
||||
|
||||
template <typename T, typename... Args>
|
||||
struct StdTupleAsImpl {
|
||||
static std::tuple<T, Args...> as(msgpack::object const& o) {
|
||||
return std::tuple_cat(
|
||||
std::make_tuple(o.via.array.ptr[o.via.array.size - sizeof...(Args) - 1].as<T>()),
|
||||
StdTupleAs<Args...>::as(o));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Args>
|
||||
struct StdTupleAs {
|
||||
static std::tuple<Args...> as(msgpack::object const& o) {
|
||||
return StdTupleAsImpl<Args...>::as(o);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct StdTupleAs<> {
|
||||
static std::tuple<> as (msgpack::object const&) {
|
||||
return std::tuple<>();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tuple, std::size_t N>
|
||||
struct StdTupleConverter {
|
||||
static void convert(
|
||||
msgpack::object const& o,
|
||||
Tuple& v) {
|
||||
StdTupleConverter<Tuple, N-1>::convert(o, v);
|
||||
o.via.array.ptr[N-1].convert<typename std::remove_reference<decltype(std::get<N-1>(v))>::type>(std::get<N-1>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tuple>
|
||||
struct StdTupleConverter<Tuple, 0> {
|
||||
static void convert (
|
||||
msgpack::object const&,
|
||||
Tuple&) {
|
||||
}
|
||||
};
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename... Args>
|
||||
struct as<std::tuple<Args...>, typename std::enable_if<msgpack::all_of<msgpack::has_as, Args...>::value>::type> {
|
||||
std::tuple<Args...> operator()(
|
||||
msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if (o.via.array.size < sizeof...(Args)) { throw msgpack::type_error(); }
|
||||
return StdTupleAs<Args...>::as(o);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Args>
|
||||
struct convert<std::tuple<Args...>> {
|
||||
msgpack::object const& operator()(
|
||||
msgpack::object const& o,
|
||||
std::tuple<Args...>& v) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size < sizeof...(Args)) { throw msgpack::type_error(); }
|
||||
StdTupleConverter<decltype(v), sizeof...(Args)>::convert(o, v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
// --- Convert from tuple to object with zone ---
|
||||
template <typename Tuple, std::size_t N>
|
||||
struct StdTupleToObjectWithZone {
|
||||
static void convert(
|
||||
msgpack::object::with_zone& o,
|
||||
const Tuple& v) {
|
||||
StdTupleToObjectWithZone<Tuple, N-1>::convert(o, v);
|
||||
o.via.array.ptr[N-1] = msgpack::object(std::get<N-1>(v), o.zone);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tuple>
|
||||
struct StdTupleToObjectWithZone<Tuple, 0> {
|
||||
static void convert (
|
||||
msgpack::object::with_zone&,
|
||||
const Tuple&) {
|
||||
}
|
||||
};
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename... Args>
|
||||
struct object_with_zone<std::tuple<Args...>> {
|
||||
void operator()(
|
||||
msgpack::object::with_zone& o,
|
||||
std::tuple<Args...> const& v) const {
|
||||
uint32_t size = checked_get_container_size(sizeof...(Args));
|
||||
o.type = msgpack::type::ARRAY;
|
||||
o.via.array.ptr = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
o.via.array.size = size;
|
||||
StdTupleToObjectWithZone<decltype(v), sizeof...(Args)>::convert(o, v);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_TUPLE_HPP
|
||||
#endif // MSGPACK_TYPE_CPP11_TUPLE_HPP
|
||||
|
@ -1,82 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP11_UNIQUE_PTR_HPP
|
||||
#define MSGPACK_CPP11_UNIQUE_PTR_HPP
|
||||
#ifndef MSGPACK_TYPE_CPP11_UNIQUE_PTR_HPP
|
||||
#define MSGPACK_TYPE_CPP11_UNIQUE_PTR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/v1/adaptor/cpp11/unique_ptr.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T>
|
||||
struct as<std::unique_ptr<T>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||
std::unique_ptr<T> operator()(msgpack::object const& o) const {
|
||||
if(o.is_nil()) return nullptr;
|
||||
return std::unique_ptr<T>(new T(o.as<T>()));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct convert<std::unique_ptr<T>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::unique_ptr<T>& v) const {
|
||||
if(o.is_nil()) v.reset();
|
||||
else {
|
||||
v.reset(new T);
|
||||
msgpack::adaptor::convert<T>()(o, *v);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pack<std::unique_ptr<T>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unique_ptr<T>& v) const {
|
||||
if (v) o.pack(*v);
|
||||
else o.pack_nil();
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object<std::unique_ptr<T> > {
|
||||
void operator()(msgpack::object& o, const std::unique_ptr<T>& v) const {
|
||||
if (v) msgpack::adaptor::object<T>()(o, *v);
|
||||
else o.type = msgpack::type::NIL;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object_with_zone<std::unique_ptr<T>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::unique_ptr<T>& v) const {
|
||||
if (v) msgpack::adaptor::object_with_zone<T>()(o, *v);
|
||||
else o.type = msgpack::type::NIL;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_UNIQUE_PTR_HPP
|
||||
#endif // MSGPACK_TYPE_CPP11_UNIQUE_PTR_HPP
|
||||
|
@ -1,182 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_TYPE_UNORDERED_MAP_HPP
|
||||
#define MSGPACK_TYPE_UNORDERED_MAP_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#ifndef MSGPACK_TYPE_CPP11_UNORDERED_MAP_HPP
|
||||
#define MSGPACK_TYPE_CPP11_UNORDERED_MAP_HPP
|
||||
|
||||
#include <unordered_map>
|
||||
#include "msgpack/v1/adaptor/cpp11/unordered_map.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||
struct as<
|
||||
std::unordered_map<K, V, Hash, Compare, Alloc>,
|
||||
typename std::enable_if<msgpack::has_as<K>::value && msgpack::has_as<V>::value>::type> {
|
||||
std::unordered_map<K, V, Hash, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
std::unordered_map<K, V, Hash, Compare, Alloc> v;
|
||||
for (; p != pend; ++p) {
|
||||
v.emplace(p->key.as<K>(), p->val.as<V>());
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||
struct convert<std::unordered_map<K, V, Hash, Compare, Alloc>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::unordered_map<K, V, Hash, Compare, Alloc>& v) const {
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
std::unordered_map<K, V, Hash, Compare, Alloc> tmp;
|
||||
for(; p != pend; ++p) {
|
||||
K key;
|
||||
p->key.convert(key);
|
||||
p->val.convert(tmp[std::move(key)]);
|
||||
}
|
||||
v = std::move(tmp);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||
struct pack<std::unordered_map<K, V, Hash, Compare, Alloc>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_map<K, V, Hash, Compare, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_map(size);
|
||||
for(typename std::unordered_map<K, V, Hash, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||
struct object_with_zone<std::unordered_map<K, V, Hash, Compare, Alloc>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::unordered_map<K, V, Hash, Compare, Alloc>& v) const {
|
||||
o.type = msgpack::type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size));
|
||||
msgpack::object_kv* const pend = p + size;
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = size;
|
||||
typename std::unordered_map<K, V, Hash, Compare, Alloc>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = msgpack::object(it->first, o.zone);
|
||||
p->val = msgpack::object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||
struct as<
|
||||
std::unordered_multimap<K, V, Hash, Compare, Alloc>,
|
||||
typename std::enable_if<msgpack::has_as<K>::value && msgpack::has_as<V>::value>::type> {
|
||||
std::unordered_multimap<K, V, Hash, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
std::unordered_multimap<K, V, Hash, Compare, Alloc> v;
|
||||
for (; p != pend; ++p) {
|
||||
v.emplace(p->key.as<K>(), p->val.as<V>());
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||
struct convert<std::unordered_multimap<K, V, Hash, Compare, Alloc>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::unordered_multimap<K, V, Hash, Compare, Alloc>& v) const {
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
std::unordered_multimap<K, V, Hash, Compare, Alloc> tmp;
|
||||
for(; p != pend; ++p) {
|
||||
std::pair<K, V> value;
|
||||
p->key.convert(value.first);
|
||||
p->val.convert(value.second);
|
||||
tmp.insert(std::move(value));
|
||||
}
|
||||
v = std::move(tmp);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||
struct pack<std::unordered_multimap<K, V, Hash, Compare, Alloc>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_multimap<K, V, Hash, Compare, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_map(size);
|
||||
for(typename std::unordered_multimap<K, V, Hash, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||
struct object_with_zone<std::unordered_multimap<K, V, Hash, Compare, Alloc>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::unordered_multimap<K, V, Hash, Compare, Alloc>& v) const {
|
||||
o.type = msgpack::type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size));
|
||||
msgpack::object_kv* const pend = p + size;
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = size;
|
||||
typename std::unordered_multimap<K, V, Hash, Compare, Alloc>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = msgpack::object(it->first, o.zone);
|
||||
p->val = msgpack::object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
#endif // MSGPACK_TYPE_UNORDERED_MAP_HPP
|
||||
#endif // MSGPACK_TYPE_CPP11_UNORDERED_MAP_HPP
|
||||
|
@ -1,172 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_TYPE_UNORDERED_SET_HPP
|
||||
#define MSGPACK_TYPE_UNORDERED_SET_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#ifndef MSGPACK_TYPE_CPP11_UNORDERED_SET_HPP
|
||||
#define MSGPACK_TYPE_CPP11_UNORDERED_SET_HPP
|
||||
|
||||
#include <unordered_set>
|
||||
#include "msgpack/v1/adaptor/cpp11/unordered_set.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||
struct as<std::unordered_set<Key, Hash, Compare, Alloc>, typename std::enable_if<msgpack::has_as<Key>::value>::type> {
|
||||
std::unordered_set<Key, Hash, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pbegin = o.via.array.ptr;
|
||||
std::unordered_set<Key, Hash, Compare, Alloc> v;
|
||||
while (p > pbegin) {
|
||||
--p;
|
||||
v.insert(p->as<Key>());
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||
struct convert<std::unordered_set<Key, Hash, Compare, Alloc>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::unordered_set<Key, Hash, Compare, Alloc>& v) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pbegin = o.via.array.ptr;
|
||||
std::unordered_set<Key, Hash, Compare, Alloc> tmp;
|
||||
while(p > pbegin) {
|
||||
--p;
|
||||
tmp.insert(p->as<Key>());
|
||||
}
|
||||
v = std::move(tmp);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||
struct pack<std::unordered_set<Key, Hash, Compare, Alloc>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_set<Key, Hash, Compare, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(typename std::unordered_set<Key, Hash, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||
struct object_with_zone<std::unordered_set<Key, Hash, Compare, Alloc>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::unordered_set<Key, Hash, Compare, Alloc>& v) const {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename std::unordered_set<Key, Hash, Compare, Alloc>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||
struct as<std::unordered_multiset<Key, Hash, Compare, Alloc>, typename std::enable_if<msgpack::has_as<Key>::value>::type> {
|
||||
std::unordered_multiset<Key, Hash, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pbegin = o.via.array.ptr;
|
||||
std::unordered_multiset<Key, Hash, Compare, Alloc> v;
|
||||
while (p > pbegin) {
|
||||
--p;
|
||||
v.insert(p->as<Key>());
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||
struct convert<std::unordered_multiset<Key, Hash, Compare, Alloc>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::unordered_multiset<Key, Hash, Compare, Alloc>& v) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pbegin = o.via.array.ptr;
|
||||
std::unordered_multiset<Key, Hash, Compare, Alloc> tmp;
|
||||
while(p > pbegin) {
|
||||
--p;
|
||||
tmp.insert(p->as<Key>());
|
||||
}
|
||||
v = std::move(tmp);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||
struct pack<std::unordered_multiset<Key, Hash, Compare, Alloc>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_multiset<Key, Hash, Compare, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(typename std::unordered_multiset<Key, Hash, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||
struct object_with_zone<std::unordered_multiset<Key, Hash, Compare, Alloc>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::unordered_multiset<Key, Hash, Compare, Alloc>& v) const {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename std::unordered_multiset<Key, Hash, Compare, Alloc>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_UNORDERED_SET_HPP
|
||||
#endif // MSGPACK_TYPE_CPP11_UNORDERED_SET_HPP
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,22 +10,8 @@
|
||||
#ifndef MSGPACK_DEFINE_HPP
|
||||
#define MSGPACK_DEFINE_HPP
|
||||
|
||||
#include "msgpack/cpp_config.hpp"
|
||||
#include "msgpack/adaptor/define_decl.hpp"
|
||||
|
||||
#if defined(MSGPACK_USE_CPP03)
|
||||
#include "detail/cpp03_define_array.hpp"
|
||||
#include "detail/cpp03_define_map.hpp"
|
||||
#else // MSGPACK_USE_CPP03
|
||||
#include "detail/cpp11_define_array.hpp"
|
||||
#include "detail/cpp11_define_map.hpp"
|
||||
#endif // MSGPACK_USE_CPP03
|
||||
|
||||
#if defined(MSGPACK_USE_DEFINE_MAP)
|
||||
#define MSGPACK_DEFINE MSGPACK_DEFINE_MAP
|
||||
#define MSGPACK_BASE MSGPACK_BASE_MAP
|
||||
#else // defined(MSGPACK_USE_DEFINE_MAP)
|
||||
#define MSGPACK_DEFINE MSGPACK_DEFINE_ARRAY
|
||||
#define MSGPACK_BASE MSGPACK_BASE_ARRAY
|
||||
#endif // defined(MSGPACK_USE_DEFINE_MAP)
|
||||
#include "msgpack/v1/adaptor/define.hpp"
|
||||
|
||||
#endif // MSGPACK_DEFINE_HPP
|
||||
|
142
include/msgpack/adaptor/define_decl.hpp
Normal file
142
include/msgpack/adaptor/define_decl.hpp
Normal file
@ -0,0 +1,142 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_DEFINE_DECL_HPP
|
||||
#define MSGPACK_DEFINE_DECL_HPP
|
||||
|
||||
// BOOST_PP_VARIADICS is defined in boost/preprocessor/config/config.hpp
|
||||
// http://www.boost.org/libs/preprocessor/doc/ref/variadics.html
|
||||
// However, supporting compiler detection is not complete. msgpack-c requires
|
||||
// variadic macro arguments support. So BOOST_PP_VARIADICS is defined here explicitly.
|
||||
#if !defined(MSGPACK_PP_VARIADICS)
|
||||
#define MSGPACK_PP_VARIADICS
|
||||
#endif
|
||||
|
||||
#include <msgpack/preprocessor.hpp>
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
|
||||
// for MSGPACK_ADD_ENUM
|
||||
#include "msgpack/adaptor/int.hpp"
|
||||
|
||||
#define MSGPACK_DEFINE_ARRAY(...) \
|
||||
template <typename Packer> \
|
||||
void msgpack_pack(Packer& pk) const \
|
||||
{ \
|
||||
msgpack::type::make_define_array(__VA_ARGS__).msgpack_pack(pk); \
|
||||
} \
|
||||
void msgpack_unpack(msgpack::object const& o) \
|
||||
{ \
|
||||
msgpack::type::make_define_array(__VA_ARGS__).msgpack_unpack(o); \
|
||||
}\
|
||||
template <typename MSGPACK_OBJECT> \
|
||||
void msgpack_object(MSGPACK_OBJECT* o, msgpack::zone& z) const \
|
||||
{ \
|
||||
msgpack::type::make_define_array(__VA_ARGS__).msgpack_object(o, z); \
|
||||
}
|
||||
|
||||
#define MSGPACK_BASE_ARRAY(base) (*const_cast<base *>(static_cast<base const*>(this)))
|
||||
|
||||
#define MSGPACK_DEFINE_MAP_EACH_PROC(r, data, elem) \
|
||||
MSGPACK_PP_IF( \
|
||||
MSGPACK_PP_IS_BEGIN_PARENS(elem), \
|
||||
elem, \
|
||||
(MSGPACK_PP_STRINGIZE(elem))(elem) \
|
||||
)
|
||||
|
||||
#define MSGPACK_DEFINE_MAP_IMPL(...) \
|
||||
MSGPACK_PP_SEQ_TO_TUPLE( \
|
||||
MSGPACK_PP_SEQ_FOR_EACH( \
|
||||
MSGPACK_DEFINE_MAP_EACH_PROC, \
|
||||
0, \
|
||||
MSGPACK_PP_VARIADIC_TO_SEQ(__VA_ARGS__) \
|
||||
) \
|
||||
)
|
||||
|
||||
#define MSGPACK_DEFINE_MAP(...) \
|
||||
template <typename Packer> \
|
||||
void msgpack_pack(Packer& pk) const \
|
||||
{ \
|
||||
msgpack::type::make_define_map \
|
||||
MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
|
||||
.msgpack_pack(pk); \
|
||||
} \
|
||||
void msgpack_unpack(msgpack::object const& o) \
|
||||
{ \
|
||||
msgpack::type::make_define_map \
|
||||
MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
|
||||
.msgpack_unpack(o); \
|
||||
}\
|
||||
template <typename MSGPACK_OBJECT> \
|
||||
void msgpack_object(MSGPACK_OBJECT* o, msgpack::zone& z) const \
|
||||
{ \
|
||||
msgpack::type::make_define_map \
|
||||
MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
|
||||
.msgpack_object(o, z); \
|
||||
}
|
||||
|
||||
#define MSGPACK_BASE_MAP(base) \
|
||||
(MSGPACK_PP_STRINGIZE(base))(*const_cast<base *>(static_cast<base const*>(this)))
|
||||
|
||||
// MSGPACK_ADD_ENUM must be used in the global namespace.
|
||||
#define MSGPACK_ADD_ENUM(enum_name) \
|
||||
namespace msgpack { \
|
||||
/** @cond */ \
|
||||
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) { \
|
||||
/** @endcond */ \
|
||||
namespace adaptor { \
|
||||
template<> \
|
||||
struct convert<enum_name> { \
|
||||
msgpack::object const& operator()(msgpack::object const& o, enum_name& v) const { \
|
||||
msgpack::underlying_type<enum_name>::type tmp; \
|
||||
msgpack::operator>>(o, tmp); \
|
||||
v = static_cast<enum_name>(tmp); \
|
||||
return o; \
|
||||
} \
|
||||
}; \
|
||||
template<> \
|
||||
struct object<enum_name> { \
|
||||
void operator()(msgpack::object& o, const enum_name& v) const { \
|
||||
msgpack::underlying_type<enum_name>::type tmp = static_cast<msgpack::underlying_type<enum_name>::type>(v); \
|
||||
msgpack::operator<<(o, tmp); \
|
||||
} \
|
||||
}; \
|
||||
template<> \
|
||||
struct object_with_zone<enum_name> { \
|
||||
void operator()(msgpack::object::with_zone& o, const enum_name& v) const { \
|
||||
msgpack::underlying_type<enum_name>::type tmp = static_cast<msgpack::underlying_type<enum_name>::type>(v); \
|
||||
msgpack::operator<<(o, tmp); \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct pack<enum_name> { \
|
||||
template <typename Stream> \
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const enum_name& v) const { \
|
||||
return msgpack::operator<<(o, static_cast<msgpack::underlying_type<enum_name>::type>(v)); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
/** @cond */ \
|
||||
} \
|
||||
/** @endcond */ \
|
||||
}
|
||||
|
||||
#if defined(MSGPACK_USE_DEFINE_MAP)
|
||||
#define MSGPACK_DEFINE MSGPACK_DEFINE_MAP
|
||||
#define MSGPACK_BASE MSGPACK_BASE_MAP
|
||||
#else // defined(MSGPACK_USE_DEFINE_MAP)
|
||||
#define MSGPACK_DEFINE MSGPACK_DEFINE_ARRAY
|
||||
#define MSGPACK_BASE MSGPACK_BASE_ARRAY
|
||||
#endif // defined(MSGPACK_USE_DEFINE_MAP)
|
||||
|
||||
|
||||
#include "msgpack/v1/adaptor/define_decl.hpp"
|
||||
#include "msgpack/v2/adaptor/define_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_DEFINE_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,99 +10,6 @@
|
||||
#ifndef MSGPACK_TYPE_DEQUE_HPP
|
||||
#define MSGPACK_TYPE_DEQUE_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/v1/adaptor/deque.hpp"
|
||||
|
||||
#include <deque>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct as<std::deque<T, Alloc>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||
std::deque<T, Alloc> operator()(const msgpack::object& o) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
std::deque<T, Alloc> v;
|
||||
if (o.via.array.size > 0) {
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
do {
|
||||
v.push_back(p->as<T>());
|
||||
++p;
|
||||
} while (p < pend);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct convert<std::deque<T, Alloc> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::deque<T, Alloc>& v) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
v.resize(o.via.array.size);
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
typename std::deque<T, Alloc>::iterator it = v.begin();
|
||||
for(; p < pend; ++p, ++it) {
|
||||
p->convert(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct pack<std::deque<T, Alloc> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::deque<T, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(typename std::deque<T, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct object_with_zone<std::deque<T, Alloc> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::deque<T, Alloc>& v) const {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename std::deque<T, Alloc>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/type/deque.hpp */
|
||||
#endif // MSGPACK_TYPE_DEQUE_HPP
|
||||
|
@ -10,228 +10,8 @@
|
||||
#ifndef MSGPACK_TYPE_EXT_HPP
|
||||
#define MSGPACK_TYPE_EXT_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include "msgpack/adaptor/ext_decl.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
#include "msgpack/v1/adaptor/ext.hpp"
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
class ext_ref;
|
||||
|
||||
class ext {
|
||||
public:
|
||||
ext() : m_data(1, 0) {}
|
||||
ext(int8_t t, const char* p, uint32_t s) {
|
||||
detail::check_container_size_for_ext<sizeof(std::size_t)>(s);
|
||||
m_data.reserve(static_cast<std::size_t>(s) + 1);
|
||||
m_data.push_back(static_cast<char>(t));
|
||||
m_data.insert(m_data.end(), p, p + s);
|
||||
}
|
||||
ext(int8_t t, uint32_t s) {
|
||||
detail::check_container_size_for_ext<sizeof(std::size_t)>(s);
|
||||
m_data.resize(static_cast<std::size_t>(s) + 1);
|
||||
m_data[0] = static_cast<char>(t);
|
||||
}
|
||||
ext(ext_ref const&);
|
||||
int8_t type() const {
|
||||
return static_cast<int8_t>(m_data[0]);
|
||||
}
|
||||
const char* data() const {
|
||||
return &m_data[1];
|
||||
}
|
||||
char* data() {
|
||||
return &m_data[1];
|
||||
}
|
||||
uint32_t size() const {
|
||||
return static_cast<uint32_t>(m_data.size()) - 1;
|
||||
}
|
||||
bool operator== (const ext& x) const {
|
||||
return m_data == x.m_data;
|
||||
}
|
||||
|
||||
bool operator!= (const ext& x) const {
|
||||
return !(*this == x);
|
||||
}
|
||||
|
||||
bool operator< (const ext& x) const {
|
||||
return m_data < x.m_data;
|
||||
}
|
||||
|
||||
bool operator> (const ext& x) const {
|
||||
return m_data > x.m_data;
|
||||
}
|
||||
private:
|
||||
std::vector<char> m_data;
|
||||
friend class ext_ref;
|
||||
};
|
||||
|
||||
} // namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<msgpack::type::ext> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, msgpack::type::ext& v) const {
|
||||
if(o.type != msgpack::type::EXT) {
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
v = msgpack::type::ext(o.via.ext.type(), o.via.ext.data(), o.via.ext.size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<msgpack::type::ext> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const msgpack::type::ext& v) const {
|
||||
// size limit has already been checked at ext's constructor
|
||||
uint32_t size = v.size();
|
||||
o.pack_ext(size, v.type());
|
||||
o.pack_ext_body(v.data(), size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<msgpack::type::ext> {
|
||||
void operator()(msgpack::object::with_zone& o, const msgpack::type::ext& v) const {
|
||||
// size limit has already been checked at ext's constructor
|
||||
uint32_t size = v.size();
|
||||
o.type = msgpack::type::EXT;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size + 1));
|
||||
o.via.ext.ptr = ptr;
|
||||
o.via.ext.size = size;
|
||||
ptr[0] = static_cast<char>(v.type());
|
||||
std::memcpy(ptr + 1, v.data(), size);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
namespace type {
|
||||
|
||||
class ext_ref {
|
||||
public:
|
||||
// ext_ref should be default constructible to support 'convert'.
|
||||
// A default constructed ext_ref object::m_ptr doesn't have the buffer to point to.
|
||||
// In order to avoid nullptr checking branches, m_ptr points to m_size.
|
||||
// So type() returns unspecified but valid value. It might be a zero because m_size
|
||||
// is initialized as zero, but shouldn't assume that.
|
||||
ext_ref() : m_ptr(static_cast<char*>(static_cast<void*>(&m_size))), m_size(0) {}
|
||||
ext_ref(const char* p, uint32_t s) :
|
||||
m_ptr(s == 0 ? static_cast<char*>(static_cast<void*>(&m_size)) : p),
|
||||
m_size(s == 0 ? 0 : s - 1) {
|
||||
detail::check_container_size_for_ext<sizeof(std::size_t)>(s);
|
||||
}
|
||||
|
||||
// size limit has already been checked at ext's constructor
|
||||
ext_ref(ext const& x) : m_ptr(&x.m_data[0]), m_size(x.size()) {}
|
||||
|
||||
const char* data() const {
|
||||
return m_ptr + 1;
|
||||
}
|
||||
|
||||
uint32_t size() const {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
int8_t type() const {
|
||||
return static_cast<int8_t>(m_ptr[0]);
|
||||
}
|
||||
|
||||
std::string str() const {
|
||||
return std::string(m_ptr + 1, m_size);
|
||||
}
|
||||
|
||||
bool operator== (const ext_ref& x) const {
|
||||
return m_size == x.m_size && std::memcmp(m_ptr, x.m_ptr, m_size) == 0;
|
||||
}
|
||||
|
||||
bool operator!= (const ext_ref& x) const {
|
||||
return !(*this == x);
|
||||
}
|
||||
|
||||
bool operator< (const ext_ref& x) const {
|
||||
if (m_size < x.m_size) return true;
|
||||
if (m_size > x.m_size) return false;
|
||||
return std::memcmp(m_ptr, x.m_ptr, m_size) < 0;
|
||||
}
|
||||
|
||||
bool operator> (const ext_ref& x) const {
|
||||
if (m_size > x.m_size) return true;
|
||||
if (m_size < x.m_size) return false;
|
||||
return std::memcmp(m_ptr, x.m_ptr, m_size) > 0;
|
||||
}
|
||||
private:
|
||||
const char* m_ptr;
|
||||
uint32_t m_size;
|
||||
friend struct msgpack::adaptor::object<msgpack::type::ext_ref>;
|
||||
};
|
||||
|
||||
inline ext::ext(ext_ref const& x) {
|
||||
// size limit has already been checked at ext_ref's constructor
|
||||
m_data.reserve(x.size() + 1);
|
||||
|
||||
m_data.push_back(x.type());
|
||||
m_data.insert(m_data.end(), x.data(), x.data() + x.size());
|
||||
}
|
||||
|
||||
} // namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<msgpack::type::ext_ref> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, msgpack::type::ext_ref& v) const {
|
||||
if(o.type != msgpack::type::EXT) { throw msgpack::type_error(); }
|
||||
v = msgpack::type::ext_ref(o.via.ext.ptr, o.via.ext.size + 1);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<msgpack::type::ext_ref> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const msgpack::type::ext_ref& v) const {
|
||||
// size limit has already been checked at ext_ref's constructor
|
||||
uint32_t size = v.size();
|
||||
o.pack_ext(size, v.type());
|
||||
o.pack_ext_body(v.data(), size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<msgpack::type::ext_ref> {
|
||||
void operator()(msgpack::object& o, const msgpack::type::ext_ref& v) const {
|
||||
// size limit has already been checked at ext_ref's constructor
|
||||
uint32_t size = v.size();
|
||||
o.type = msgpack::type::EXT;
|
||||
o.via.ext.ptr = v.m_ptr;
|
||||
o.via.ext.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<msgpack::type::ext_ref> {
|
||||
void operator()(msgpack::object::with_zone& o, const msgpack::type::ext_ref& v) const {
|
||||
static_cast<msgpack::object&>(o) << v;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_EXT_HPP
|
||||
#endif // MSGPACK_TYPE_EXT_HPP
|
||||
|
16
include/msgpack/adaptor/ext_decl.hpp
Normal file
16
include/msgpack/adaptor/ext_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_TYPE_EXT_DECL_HPP
|
||||
#define MSGPACK_TYPE_EXT_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/ext_decl.hpp"
|
||||
#include "msgpack/v2/adaptor/ext_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_EXT_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2020 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,289 +10,8 @@
|
||||
#ifndef MSGPACK_TYPE_FIXINT_HPP
|
||||
#define MSGPACK_TYPE_FIXINT_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/int.hpp"
|
||||
#include "msgpack/adaptor/fixint_decl.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
#include "msgpack/v1/adaptor/fixint.hpp"
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct fix_int {
|
||||
fix_int() : value(0) { }
|
||||
fix_int(T value) : value(value) { }
|
||||
|
||||
operator T() const { return value; }
|
||||
|
||||
T get() const { return value; }
|
||||
|
||||
private:
|
||||
T value;
|
||||
};
|
||||
|
||||
|
||||
typedef fix_int<uint8_t> fix_uint8;
|
||||
typedef fix_int<uint16_t> fix_uint16;
|
||||
typedef fix_int<uint32_t> fix_uint32;
|
||||
typedef fix_int<uint64_t> fix_uint64;
|
||||
|
||||
typedef fix_int<int8_t> fix_int8;
|
||||
typedef fix_int<int16_t> fix_int16;
|
||||
typedef fix_int<int32_t> fix_int32;
|
||||
typedef fix_int<int64_t> fix_int64;
|
||||
|
||||
|
||||
} // namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<type::fix_int8> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_int8& v) const
|
||||
{ v = type::detail::convert_integer<int8_t>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<type::fix_int16> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_int16& v) const
|
||||
{ v = type::detail::convert_integer<int16_t>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<type::fix_int32> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_int32& v) const
|
||||
{ v = type::detail::convert_integer<int32_t>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<type::fix_int64> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_int64& v) const
|
||||
{ v = type::detail::convert_integer<int64_t>(o); return o; }
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct convert<type::fix_uint8> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_uint8& v) const
|
||||
{ v = type::detail::convert_integer<uint8_t>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<type::fix_uint16> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_uint16& v) const
|
||||
{ v = type::detail::convert_integer<uint16_t>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<type::fix_uint32> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_uint32& v) const
|
||||
{ v = type::detail::convert_integer<uint32_t>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<type::fix_uint64> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_uint64& v) const
|
||||
{ v = type::detail::convert_integer<uint64_t>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<type::fix_int8> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int8& v) const
|
||||
{ o.pack_fix_int8(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<type::fix_int16> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int16& v) const
|
||||
{ o.pack_fix_int16(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<type::fix_int32> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int32& v) const
|
||||
{ o.pack_fix_int32(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<type::fix_int64> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int64& v) const
|
||||
{ o.pack_fix_int64(v); return o; }
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct pack<type::fix_uint8> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint8& v) const
|
||||
{ o.pack_fix_uint8(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<type::fix_uint16> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint16& v) const
|
||||
{ o.pack_fix_uint16(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<type::fix_uint32> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint32& v) const
|
||||
{ o.pack_fix_uint32(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<type::fix_uint64> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint64& v) const
|
||||
{ o.pack_fix_uint64(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<type::fix_int8> {
|
||||
void operator()(msgpack::object& o, type::fix_int8 v) const {
|
||||
if (v.get() < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v.get();
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v.get();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<type::fix_int16> {
|
||||
void operator()(msgpack::object& o, type::fix_int16 v) const {
|
||||
if(v.get() < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v.get();
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v.get();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<type::fix_int32> {
|
||||
void operator()(msgpack::object& o, type::fix_int32 v) const {
|
||||
if (v.get() < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v.get();
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v.get();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<type::fix_int64> {
|
||||
void operator()(msgpack::object& o, type::fix_int64 v) const {
|
||||
if (v.get() < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v.get();
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v.get();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<type::fix_uint8> {
|
||||
void operator()(msgpack::object& o, type::fix_uint8 v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<type::fix_uint16> {
|
||||
void operator()(msgpack::object& o, type::fix_uint16 v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<type::fix_uint32> {
|
||||
void operator()(msgpack::object& o, type::fix_uint32 v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<type::fix_uint64> {
|
||||
void operator()(msgpack::object& o, type::fix_uint64 v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<type::fix_int8> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_int8 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<type::fix_int16> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_int16 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<type::fix_int32> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_int32 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<type::fix_int64> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_int64 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct object_with_zone<type::fix_uint8> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_uint8 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<type::fix_uint16> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_uint16 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<type::fix_uint32> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_uint32 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<type::fix_uint64> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_uint64 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/type/fixint.hpp */
|
||||
#endif // MSGPACK_TYPE_FIXINT_HPP
|
||||
|
16
include/msgpack/adaptor/fixint_decl.hpp
Normal file
16
include/msgpack/adaptor/fixint_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// 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_TYPE_FIXINT_DECL_HPP
|
||||
#define MSGPACK_TYPE_FIXINT_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/fixint_decl.hpp"
|
||||
#include "msgpack/v2/adaptor/fixint_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_FIXINT_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,114 +10,6 @@
|
||||
#ifndef MSGPACK_TYPE_FLOAT_HPP
|
||||
#define MSGPACK_TYPE_FLOAT_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
// 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::FLOAT) {
|
||||
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::FLOAT) {
|
||||
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::FLOAT;
|
||||
o.via.f64 = static_cast<double>(v);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<double> {
|
||||
void operator()(msgpack::object& o, double v) const {
|
||||
o.type = msgpack::type::FLOAT;
|
||||
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
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/float.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_FLOAT_HPP
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,421 +10,8 @@
|
||||
#ifndef MSGPACK_TYPE_INT_HPP
|
||||
#define MSGPACK_TYPE_INT_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include <limits>
|
||||
#include "msgpack/adaptor/int_decl.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
#include "msgpack/v1/adaptor/int.hpp"
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1){
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
namespace detail {
|
||||
template <typename T, bool Signed>
|
||||
struct convert_integer_sign;
|
||||
|
||||
template <typename T>
|
||||
struct convert_integer_sign<T, true> {
|
||||
static T convert(msgpack::object const& o) {
|
||||
if(o.type == msgpack::type::POSITIVE_INTEGER) {
|
||||
if(o.via.u64 > static_cast<uint64_t>(std::numeric_limits<T>::max()))
|
||||
{ throw msgpack::type_error(); }
|
||||
return static_cast<T>(o.via.u64);
|
||||
} else if(o.type == msgpack::type::NEGATIVE_INTEGER) {
|
||||
if(o.via.i64 < static_cast<int64_t>(std::numeric_limits<T>::min()))
|
||||
{ throw msgpack::type_error(); }
|
||||
return static_cast<T>(o.via.i64);
|
||||
}
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct convert_integer_sign<T, false> {
|
||||
static T convert(msgpack::object const& o) {
|
||||
if(o.type == msgpack::type::POSITIVE_INTEGER) {
|
||||
if(o.via.u64 > static_cast<uint64_t>(std::numeric_limits<T>::max()))
|
||||
{ throw msgpack::type_error(); }
|
||||
return static_cast<T>(o.via.u64);
|
||||
}
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct is_signed {
|
||||
static const bool value = std::numeric_limits<T>::is_signed;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
static inline T convert_integer(msgpack::object const& o)
|
||||
{
|
||||
return detail::convert_integer_sign<T, is_signed<T>::value>::convert(o);
|
||||
}
|
||||
|
||||
template <bool Signed>
|
||||
struct object_char_sign;
|
||||
|
||||
template <>
|
||||
struct object_char_sign<true> {
|
||||
template <typename T>
|
||||
static typename msgpack::enable_if<msgpack::is_same<T, char>::value>::type
|
||||
make(msgpack::object& o, T v) {
|
||||
if (v < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_char_sign<false> {
|
||||
static void make(msgpack::object& o, char v) {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v;
|
||||
}
|
||||
};
|
||||
|
||||
static inline void object_char(msgpack::object& o, char v) {
|
||||
return object_char_sign<is_signed<char>::value>::make(o, v);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<char> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, char& v) const
|
||||
{ v = type::detail::convert_integer<char>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<signed char> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, signed char& v) const
|
||||
{ v = type::detail::convert_integer<signed char>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<signed short> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, signed short& v) const
|
||||
{ v = type::detail::convert_integer<signed short>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<signed int> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, signed int& v) const
|
||||
{ v = type::detail::convert_integer<signed int>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<signed long> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, signed long& v) const
|
||||
{ v = type::detail::convert_integer<signed long>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<signed long long> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, signed long long& v) const
|
||||
{ v = type::detail::convert_integer<signed long long>(o); return o; }
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct convert<unsigned char> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, unsigned char& v) const
|
||||
{ v = type::detail::convert_integer<unsigned char>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<unsigned short> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, unsigned short& v) const
|
||||
{ v = type::detail::convert_integer<unsigned short>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<unsigned int> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, unsigned int& v) const
|
||||
{ v = type::detail::convert_integer<unsigned int>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<unsigned long> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, unsigned long& v) const
|
||||
{ v = type::detail::convert_integer<unsigned long>(o); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<unsigned long long> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, unsigned long long& v) const
|
||||
{ v = type::detail::convert_integer<unsigned long long>(o); return o; }
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct pack<char> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, char v) const
|
||||
{ o.pack_char(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<signed char> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, signed char v) const
|
||||
{ o.pack_signed_char(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<signed short> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, signed short v) const
|
||||
{ o.pack_short(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<signed int> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, signed int v) const
|
||||
{ o.pack_int(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<signed long> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, signed long v) const
|
||||
{ o.pack_long(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<signed long long> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, signed long long v) const
|
||||
{ o.pack_long_long(v); return o; }
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct pack<unsigned char> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, unsigned char v) const
|
||||
{ o.pack_unsigned_char(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<unsigned short> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, unsigned short v) const
|
||||
{ o.pack_unsigned_short(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<unsigned int> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, unsigned int v) const
|
||||
{ o.pack_unsigned_int(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<unsigned long> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, unsigned long v) const
|
||||
{ o.pack_unsigned_long(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<unsigned long long> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, unsigned long long v) const
|
||||
{ o.pack_unsigned_long_long(v); return o; }
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct object<char> {
|
||||
void operator()(msgpack::object& o, char v) const
|
||||
{ type::detail::object_char(o, v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<signed char> {
|
||||
void operator()(msgpack::object& o, signed char v) const {
|
||||
if (v < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<signed short> {
|
||||
void operator()(msgpack::object& o, signed short v) const {
|
||||
if (v < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<signed int> {
|
||||
void operator()(msgpack::object& o, signed int v) const {
|
||||
if (v < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<signed long> {
|
||||
void operator()(msgpack::object& o, signed long v) const {
|
||||
if (v < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<signed long long> {
|
||||
void operator()(msgpack::object& o, signed long long v) const {
|
||||
if (v < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else{
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<unsigned char> {
|
||||
void operator()(msgpack::object& o, unsigned char v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<unsigned short> {
|
||||
void operator()(msgpack::object& o, unsigned short v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<unsigned int> {
|
||||
void operator()(msgpack::object& o, unsigned int v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<unsigned long> {
|
||||
void operator()(msgpack::object& o, unsigned long v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<unsigned long long> {
|
||||
void operator()(msgpack::object& o, unsigned long long v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct object_with_zone<char> {
|
||||
void operator()(msgpack::object::with_zone& o, char v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<signed char> {
|
||||
void operator()(msgpack::object::with_zone& o, signed char v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<signed short> {
|
||||
void operator()(msgpack::object::with_zone& o, signed short v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<signed int> {
|
||||
void operator()(msgpack::object::with_zone& o, signed int v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<signed long> {
|
||||
void operator()(msgpack::object::with_zone& o, signed long v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<signed long long> {
|
||||
void operator()(msgpack::object::with_zone& o, const signed long long& v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<unsigned char> {
|
||||
void operator()(msgpack::object::with_zone& o, unsigned char v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<unsigned short> {
|
||||
void operator()(msgpack::object::with_zone& o, unsigned short v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<unsigned int> {
|
||||
void operator()(msgpack::object::with_zone& o, unsigned int v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<unsigned long> {
|
||||
void operator()(msgpack::object::with_zone& o, unsigned long v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<unsigned long long> {
|
||||
void operator()(msgpack::object::with_zone& o, const unsigned long long& v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/type/int.hpp */
|
||||
#endif // MSGPACK_TYPE_INT_HPP
|
||||
|
16
include/msgpack/adaptor/int_decl.hpp
Normal file
16
include/msgpack/adaptor/int_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_TYPE_INT_DECL_HPP
|
||||
#define MSGPACK_TYPE_INT_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/int_decl.hpp"
|
||||
#include "msgpack/v2/adaptor/int_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_INT_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,97 +10,6 @@
|
||||
#ifndef MSGPACK_TYPE_LIST_HPP
|
||||
#define MSGPACK_TYPE_LIST_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct as<std::list<T, Alloc>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||
std::list<T, Alloc> operator()(msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
std::list<T, Alloc> v;
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
for (; p < pend; ++p) {
|
||||
v.push_back(p->as<T>());
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct convert<std::list<T, Alloc> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::list<T, Alloc>& v) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
v.resize(o.via.array.size);
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
typename std::list<T, Alloc>::iterator it = v.begin();
|
||||
for (; p < pend; ++p, ++it) {
|
||||
p->convert(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct pack<std::list<T, Alloc> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::list<T, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for (typename std::list<T, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct object_with_zone<std::list<T, Alloc> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::list<T, Alloc>& v) const {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if (v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
}
|
||||
else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename std::list<T, Alloc>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/list.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_LIST_HPP
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,297 +10,9 @@
|
||||
#ifndef MSGPACK_TYPE_MAP_HPP
|
||||
#define MSGPACK_TYPE_MAP_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/adaptor/map_decl.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "msgpack/v1/adaptor/map.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
template <typename K, typename V, typename Compare = std::less<K>, typename Alloc = std::allocator<std::pair<K, V> > >
|
||||
class assoc_vector : public std::vector< std::pair<K, V>, Alloc > {
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
using std::vector<std::pair<K, V>, Alloc>::vector;
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
template <typename K, typename V, typename Compare, typename Alloc>
|
||||
struct pair_first_less {
|
||||
bool operator() (const std::pair<K, V>& x, const std::pair<K, V>& y) const
|
||||
{ return Compare()(x.first, y.first); }
|
||||
};
|
||||
}
|
||||
|
||||
} //namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename K, typename V, typename Compare, typename Alloc>
|
||||
struct as<
|
||||
type::assoc_vector<K, V, Compare, Alloc>,
|
||||
typename std::enable_if<msgpack::has_as<K>::value && msgpack::has_as<V>::value>::type> {
|
||||
type::assoc_vector<K, V, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
type::assoc_vector<K, V, Compare, Alloc> v;
|
||||
v.reserve(o.via.map.size);
|
||||
msgpack::object_kv* p = o.via.map.ptr;
|
||||
msgpack::object_kv* const pend = o.via.map.ptr + o.via.map.size;
|
||||
for (; p < pend; ++p) {
|
||||
v.emplace_back(p->key.as<K>(), p->val.as<V>());
|
||||
}
|
||||
std::sort(v.begin(), v.end(), type::detail::pair_first_less<K, V, Compare, Alloc>());
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename K, typename V, typename Compare, typename Alloc>
|
||||
struct convert<type::assoc_vector<K, V, Compare, Alloc> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::assoc_vector<K, V, Compare, Alloc>& v) const {
|
||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
v.resize(o.via.map.size);
|
||||
msgpack::object_kv* p = o.via.map.ptr;
|
||||
msgpack::object_kv* const pend = o.via.map.ptr + o.via.map.size;
|
||||
std::pair<K, V>* it(&v.front());
|
||||
for (; p < pend; ++p, ++it) {
|
||||
p->key.convert(it->first);
|
||||
p->val.convert(it->second);
|
||||
}
|
||||
std::sort(v.begin(), v.end(), type::detail::pair_first_less<K, V, Compare, Alloc>());
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V, typename Compare, typename Alloc>
|
||||
struct pack<type::assoc_vector<K, V, Compare, Alloc> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::assoc_vector<K, V, Compare, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_map(size);
|
||||
for (typename type::assoc_vector<K, V, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V, typename Compare, typename Alloc>
|
||||
struct object_with_zone<type::assoc_vector<K, V, Compare, Alloc> > {
|
||||
void operator()(msgpack::object::with_zone& o, const type::assoc_vector<K, V, Compare, Alloc>& v) const {
|
||||
o.type = msgpack::type::MAP;
|
||||
if (v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
}
|
||||
else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size));
|
||||
msgpack::object_kv* const pend = p + size;
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = size;
|
||||
typename type::assoc_vector<K, V, Compare, Alloc>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = msgpack::object(it->first, o.zone);
|
||||
p->val = msgpack::object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename K, typename V, typename Compare, typename Alloc>
|
||||
struct as<
|
||||
std::map<K, V, Compare, Alloc>,
|
||||
typename std::enable_if<msgpack::has_as<K>::value && msgpack::has_as<V>::value>::type> {
|
||||
std::map<K, V, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
std::map<K, V, Compare, Alloc> v;
|
||||
for (; p != pend; ++p) {
|
||||
v.emplace(p->key.as<K>(), p->val.as<V>());
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename K, typename V, typename Compare, typename Alloc>
|
||||
struct convert<std::map<K, V, Compare, Alloc> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::map<K, V, Compare, Alloc>& v) const {
|
||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
std::map<K, V, Compare, Alloc> tmp;
|
||||
for (; p != pend; ++p) {
|
||||
K key;
|
||||
p->key.convert(key);
|
||||
#if __cplusplus >= 201103L
|
||||
p->val.convert(tmp[std::move(key)]);
|
||||
#else
|
||||
p->val.convert(tmp[key]);
|
||||
#endif
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
v = std::move(tmp);
|
||||
#else
|
||||
tmp.swap(v);
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V, typename Compare, typename Alloc>
|
||||
struct pack<std::map<K, V, Compare, Alloc> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::map<K, V, Compare, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_map(size);
|
||||
for (typename std::map<K, V, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V, typename Compare, typename Alloc>
|
||||
struct object_with_zone<std::map<K, V, Compare, Alloc> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::map<K, V, Compare, Alloc>& v) const {
|
||||
o.type = msgpack::type::MAP;
|
||||
if (v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
}
|
||||
else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size));
|
||||
msgpack::object_kv* const pend = p + size;
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = size;
|
||||
typename std::map<K, V, Compare, Alloc>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = msgpack::object(it->first, o.zone);
|
||||
p->val = msgpack::object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename K, typename V, typename Compare, typename Alloc>
|
||||
struct as<
|
||||
std::multimap<K, V, Compare, Alloc>,
|
||||
typename std::enable_if<msgpack::has_as<K>::value && msgpack::has_as<V>::value>::type> {
|
||||
std::multimap<K, V, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
std::multimap<K, V, Compare, Alloc> v;
|
||||
for (; p != pend; ++p) {
|
||||
v.emplace(p->key.as<K>(), p->val.as<V>());
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename K, typename V, typename Compare, typename Alloc>
|
||||
struct convert<std::multimap<K, V, Compare, Alloc> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::multimap<K, V, Compare, Alloc>& v) const {
|
||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
std::multimap<K, V, Compare, Alloc> tmp;
|
||||
for (; p != pend; ++p) {
|
||||
std::pair<K, V> value;
|
||||
p->key.convert(value.first);
|
||||
p->val.convert(value.second);
|
||||
#if __cplusplus >= 201103L
|
||||
tmp.insert(std::move(value));
|
||||
#else
|
||||
tmp.insert(value);
|
||||
#endif
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
v = std::move(tmp);
|
||||
#else
|
||||
tmp.swap(v);
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V, typename Compare, typename Alloc>
|
||||
struct pack<std::multimap<K, V, Compare, Alloc> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::multimap<K, V, Compare, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_map(size);
|
||||
for (typename std::multimap<K, V, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V, typename Compare, typename Alloc>
|
||||
struct object_with_zone<std::multimap<K, V, Compare, Alloc> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::multimap<K, V, Compare, Alloc>& v) const {
|
||||
o.type = msgpack::type::MAP;
|
||||
if (v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
}
|
||||
else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size));
|
||||
msgpack::object_kv* const pend = p + size;
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = size;
|
||||
typename std::multimap<K, V, Compare, Alloc>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = msgpack::object(it->first, o.zone);
|
||||
p->val = msgpack::object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_MAP_HPP
|
||||
|
16
include/msgpack/adaptor/map_decl.hpp
Normal file
16
include/msgpack/adaptor/map_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// 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_TYPE_MAP_DECL_HPP
|
||||
#define MSGPACK_TYPE_MAP_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/map_decl.hpp"
|
||||
#include "msgpack/v2/adaptor/map_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_MAP_DECL_HPP
|
@ -10,12 +10,8 @@
|
||||
#ifndef MSGPACK_MSGPACK_TUPLE_HPP
|
||||
#define MSGPACK_MSGPACK_TUPLE_HPP
|
||||
|
||||
#include "msgpack/cpp_config.hpp"
|
||||
#include "msgpack/adaptor/msgpack_tuple_decl.hpp"
|
||||
|
||||
#if defined(MSGPACK_USE_CPP03)
|
||||
#include "detail/cpp03_msgpack_tuple.hpp"
|
||||
#else // MSGPACK_USE_CPP03
|
||||
#include "detail/cpp11_msgpack_tuple.hpp"
|
||||
#endif // MSGPACK_USE_CPP03
|
||||
#include "msgpack/v1/adaptor/msgpack_tuple.hpp"
|
||||
|
||||
#endif // MSGPACK_MSGPACK_TUPLE_HPP
|
||||
|
16
include/msgpack/adaptor/msgpack_tuple_decl.hpp
Normal file
16
include/msgpack/adaptor/msgpack_tuple_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_MSGPACK_TUPLE_DECL_HPP
|
||||
#define MSGPACK_MSGPACK_TUPLE_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/msgpack_tuple_decl.hpp"
|
||||
#include "msgpack/v2/adaptor/msgpack_tuple_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_MSGPACK_TUPLE_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,81 +10,8 @@
|
||||
#ifndef MSGPACK_TYPE_NIL_HPP
|
||||
#define MSGPACK_TYPE_NIL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/nil_decl.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
struct nil_t { };
|
||||
|
||||
#if !defined(MSGPACK_DISABLE_LEGACY_NIL)
|
||||
|
||||
typedef nil_t nil;
|
||||
|
||||
#endif // !defined(MSGPACK_DISABLE_LEGACY_NIL)
|
||||
|
||||
inline bool operator<(nil_t const& lhs, nil_t const& rhs) {
|
||||
return &lhs < &rhs;
|
||||
}
|
||||
|
||||
inline bool operator==(nil_t const& lhs, nil_t const& rhs) {
|
||||
return &lhs == &rhs;
|
||||
}
|
||||
|
||||
} // namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<type::nil_t> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::nil_t&) const {
|
||||
if(o.type != msgpack::type::NIL) { throw msgpack::type_error(); }
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<type::nil_t> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::nil_t&) const {
|
||||
o.pack_nil();
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<type::nil_t> {
|
||||
void operator()(msgpack::object& o, type::nil_t) const {
|
||||
o.type = msgpack::type::NIL;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<type::nil_t> {
|
||||
void operator()(msgpack::object::with_zone& o, type::nil_t v) const {
|
||||
static_cast<msgpack::object&>(o) << v;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
template <>
|
||||
inline void msgpack::object::as<void>() const
|
||||
{
|
||||
msgpack::type::nil_t v;
|
||||
convert(v);
|
||||
}
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/nil.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_NIL_HPP
|
||||
|
16
include/msgpack/adaptor/nil_decl.hpp
Normal file
16
include/msgpack/adaptor/nil_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_TYPE_NIL_DECL_HPP
|
||||
#define MSGPACK_TYPE_NIL_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/nil_decl.hpp"
|
||||
#include "msgpack/v2/adaptor/nil_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_NIL_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,74 +10,6 @@
|
||||
#ifndef MSGPACK_TYPE_PAIR_HPP
|
||||
#define MSGPACK_TYPE_PAIR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/meta.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T1, typename T2>
|
||||
struct as<std::pair<T1, T2>,
|
||||
typename std::enable_if<msgpack::all_of<msgpack::has_as, T1, T2>::value>::type> {
|
||||
std::pair<T1, T2> operator()(msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if (o.via.array.size != 2) { throw msgpack::type_error(); }
|
||||
return std::make_pair(o.via.array.ptr[0].as<T1>(), o.via.array.ptr[1].as<T2>());
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T1, typename T2>
|
||||
struct convert<std::pair<T1, T2> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::pair<T1, T2>& v) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size != 2) { throw msgpack::type_error(); }
|
||||
o.via.array.ptr[0].convert(v.first);
|
||||
o.via.array.ptr[1].convert(v.second);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T1, typename T2>
|
||||
struct pack<std::pair<T1, T2> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::pair<T1, T2>& v) const {
|
||||
o.pack_array(2);
|
||||
o.pack(v.first);
|
||||
o.pack(v.second);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T1, typename T2>
|
||||
struct object_with_zone<std::pair<T1, T2> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::pair<T1, T2>& v) const {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*2));
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = 2;
|
||||
p[0] = msgpack::object(v.first, o.zone);
|
||||
p[1] = msgpack::object(v.second, o.zone);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/pair.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_PAIR_HPP
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,97 +10,8 @@
|
||||
#ifndef MSGPACK_TYPE_RAW_HPP
|
||||
#define MSGPACK_TYPE_RAW_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include "msgpack/adaptor/raw_decl.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
struct raw_ref {
|
||||
raw_ref() : size(0), ptr(nullptr) {}
|
||||
raw_ref(const char* p, uint32_t s) : size(s), ptr(p) {}
|
||||
|
||||
uint32_t size;
|
||||
const char* ptr;
|
||||
|
||||
std::string str() const { return std::string(ptr, size); }
|
||||
|
||||
bool operator== (const raw_ref& x) const
|
||||
{
|
||||
return size == x.size && std::memcmp(ptr, x.ptr, size) == 0;
|
||||
}
|
||||
|
||||
bool operator!= (const raw_ref& x) const
|
||||
{
|
||||
return !(*this == x);
|
||||
}
|
||||
|
||||
bool operator< (const raw_ref& x) const
|
||||
{
|
||||
if(size == x.size) { return std::memcmp(ptr, x.ptr, size) < 0; }
|
||||
else { return size < x.size; }
|
||||
}
|
||||
|
||||
bool operator> (const raw_ref& x) const
|
||||
{
|
||||
if(size == x.size) { return std::memcmp(ptr, x.ptr, size) > 0; }
|
||||
else { return size > x.size; }
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<msgpack::type::raw_ref> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, msgpack::type::raw_ref& v) const {
|
||||
if(o.type != msgpack::type::BIN) { throw msgpack::type_error(); }
|
||||
v.ptr = o.via.bin.ptr;
|
||||
v.size = o.via.bin.size;
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<msgpack::type::raw_ref> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const msgpack::type::raw_ref& v) const {
|
||||
o.pack_bin(v.size);
|
||||
o.pack_bin_body(v.ptr, v.size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<msgpack::type::raw_ref> {
|
||||
void operator()(msgpack::object& o, const msgpack::type::raw_ref& v) const {
|
||||
o.type = msgpack::type::BIN;
|
||||
o.via.bin.ptr = v.ptr;
|
||||
o.via.bin.size = v.size;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<msgpack::type::raw_ref> {
|
||||
void operator()(msgpack::object::with_zone& o, const msgpack::type::raw_ref& v) const {
|
||||
static_cast<msgpack::object&>(o) << v;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/raw.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_RAW_HPP
|
||||
|
16
include/msgpack/adaptor/raw_decl.hpp
Normal file
16
include/msgpack/adaptor/raw_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_TYPE_RAW_DECL_HPP
|
||||
#define MSGPACK_TYPE_RAW_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/raw_decl.hpp"
|
||||
#include "msgpack/v2/adaptor/raw_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_RAW_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,179 +10,6 @@
|
||||
#ifndef MSGPACK_TYPE_SET_HPP
|
||||
#define MSGPACK_TYPE_SET_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T, typename Compare, typename Alloc>
|
||||
struct as<std::set<T, Compare, Alloc>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||
std::set<T, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pbegin = o.via.array.ptr;
|
||||
std::set<T, Compare, Alloc> v;
|
||||
while (p > pbegin) {
|
||||
--p;
|
||||
v.insert(p->as<T>());
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T, typename Compare, typename Alloc>
|
||||
struct convert<std::set<T, Compare, Alloc> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::set<T, Compare, Alloc>& v) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pbegin = o.via.array.ptr;
|
||||
std::set<T, Compare, Alloc> tmp;
|
||||
while (p > pbegin) {
|
||||
--p;
|
||||
tmp.insert(p->as<T>());
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
v = std::move(tmp);
|
||||
#else
|
||||
tmp.swap(v);
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Compare, typename Alloc>
|
||||
struct pack<std::set<T, Compare, Alloc> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::set<T, Compare, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for (typename std::set<T, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Compare, typename Alloc>
|
||||
struct object_with_zone<std::set<T, Compare, Alloc> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::set<T, Compare, Alloc>& v) const {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if (v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
}
|
||||
else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename std::set<T, Compare, Alloc>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T, typename Compare, typename Alloc>
|
||||
struct as<std::multiset<T, Compare, Alloc>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||
std::multiset<T, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pbegin = o.via.array.ptr;
|
||||
std::multiset<T, Compare, Alloc> v;
|
||||
while (p > pbegin) {
|
||||
--p;
|
||||
v.insert(p->as<T>());
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T, typename Compare, typename Alloc>
|
||||
struct convert<std::multiset<T, Compare, Alloc> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::multiset<T, Compare, Alloc>& v) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pbegin = o.via.array.ptr;
|
||||
std::multiset<T, Compare, Alloc> tmp;
|
||||
while (p > pbegin) {
|
||||
--p;
|
||||
tmp.insert(p->as<T>());
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
v = std::move(tmp);
|
||||
#else
|
||||
tmp.swap(v);
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Compare, typename Alloc>
|
||||
struct pack<std::multiset<T, Compare, Alloc> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::multiset<T, Compare, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for (typename std::multiset<T, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Compare, typename Alloc>
|
||||
struct object_with_zone<std::multiset<T, Compare, Alloc> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::multiset<T, Compare, Alloc>& v) const {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if (v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename std::multiset<T, Compare, Alloc>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/set.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_SET_HPP
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,77 +10,6 @@
|
||||
#ifndef MSGPACK_TYPE_STRING_HPP
|
||||
#define MSGPACK_TYPE_STRING_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<std::string> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::string& v) const {
|
||||
switch (o.type) {
|
||||
case msgpack::type::BIN:
|
||||
v.assign(o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case msgpack::type::STR:
|
||||
v.assign(o.via.str.ptr, o.via.str.size);
|
||||
break;
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<std::string> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::string& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_str(size);
|
||||
o.pack_str_body(v.data(), size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<std::string> {
|
||||
void operator()(msgpack::object& o, const std::string& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::STR;
|
||||
o.via.str.ptr = v.data();
|
||||
o.via.str.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<std::string> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::string& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::STR;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.str.ptr = ptr;
|
||||
o.via.str.size = size;
|
||||
std::memcpy(ptr, v.data(), v.size());
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/string.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_STRING_HPP
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,97 +10,8 @@
|
||||
#ifndef MSGPACK_TYPE_V4RAW_HPP
|
||||
#define MSGPACK_TYPE_V4RAW_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include "msgpack/adaptor/v4raw_decl.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
struct v4raw_ref {
|
||||
v4raw_ref() : size(0), ptr(nullptr) {}
|
||||
v4raw_ref(const char* p, uint32_t s) : size(s), ptr(p) {}
|
||||
|
||||
uint32_t size;
|
||||
const char* ptr;
|
||||
|
||||
std::string str() const { return std::string(ptr, size); }
|
||||
|
||||
bool operator== (const v4raw_ref& x) const
|
||||
{
|
||||
return size == x.size && std::memcmp(ptr, x.ptr, size) == 0;
|
||||
}
|
||||
|
||||
bool operator!= (const v4raw_ref& x) const
|
||||
{
|
||||
return !(*this == x);
|
||||
}
|
||||
|
||||
bool operator< (const v4raw_ref& x) const
|
||||
{
|
||||
if(size == x.size) { return std::memcmp(ptr, x.ptr, size) < 0; }
|
||||
else { return size < x.size; }
|
||||
}
|
||||
|
||||
bool operator> (const v4raw_ref& x) const
|
||||
{
|
||||
if(size == x.size) { return std::memcmp(ptr, x.ptr, size) > 0; }
|
||||
else { return size > x.size; }
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<msgpack::type::v4raw_ref> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, msgpack::type::v4raw_ref& v) const {
|
||||
if(o.type != msgpack::type::STR) { throw msgpack::type_error(); }
|
||||
v.ptr = o.via.str.ptr;
|
||||
v.size = o.via.str.size;
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<msgpack::type::v4raw_ref> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const msgpack::type::v4raw_ref& v) const {
|
||||
o.pack_v4raw(v.size);
|
||||
o.pack_v4raw_body(v.ptr, v.size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<msgpack::type::v4raw_ref> {
|
||||
void operator()(msgpack::object& o, const msgpack::type::v4raw_ref& v) const {
|
||||
o.type = msgpack::type::STR;
|
||||
o.via.str.ptr = v.ptr;
|
||||
o.via.str.size = v.size;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<msgpack::type::v4raw_ref> {
|
||||
void operator()(msgpack::object::with_zone& o, const msgpack::type::v4raw_ref& v) const {
|
||||
static_cast<msgpack::object&>(o) << v;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/v4raw.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_V4RAW_HPP
|
||||
|
16
include/msgpack/adaptor/v4raw_decl.hpp
Normal file
16
include/msgpack/adaptor/v4raw_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_TYPE_V4RAW_DECL_HPP
|
||||
#define MSGPACK_TYPE_V4RAW_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/v4raw_decl.hpp"
|
||||
#include "msgpack/v2/adaptor/v4raw_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_V4RAW_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,112 +10,6 @@
|
||||
#ifndef MSGPACK_TYPE_VECTOR_HPP
|
||||
#define MSGPACK_TYPE_VECTOR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct as<std::vector<T, Alloc>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||
std::vector<T, Alloc> operator()(const msgpack::object& o) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
std::vector<T, Alloc> v;
|
||||
v.reserve(o.via.array.size);
|
||||
if (o.via.array.size > 0) {
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
do {
|
||||
v.push_back(p->as<T>());
|
||||
++p;
|
||||
} while (p < pend);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct convert<std::vector<T, Alloc> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::vector<T, Alloc>& v) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
v.resize(o.via.array.size);
|
||||
if (o.via.array.size > 0) {
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
typename std::vector<T, Alloc>::iterator it = v.begin();
|
||||
do {
|
||||
p->convert(*it);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct pack<std::vector<T, Alloc> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<T, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for (typename std::vector<T, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct object_with_zone<std::vector<T, Alloc> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::vector<T, Alloc>& v) const {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if (v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
}
|
||||
else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename std::vector<T, Alloc>::const_iterator it(v.begin());
|
||||
do {
|
||||
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/vector.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_VECTOR_HPP
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,79 +10,6 @@
|
||||
#ifndef MSGPACK_TYPE_VECTOR_BOOL_HPP
|
||||
#define MSGPACK_TYPE_VECTOR_BOOL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename Alloc>
|
||||
struct convert<std::vector<bool, Alloc> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::vector<bool, Alloc>& v) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if (o.via.array.size > 0) {
|
||||
v.resize(o.via.array.size);
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
for (typename std::vector<bool, Alloc>::iterator it = v.begin(), end = v.end();
|
||||
it != end;
|
||||
++it) {
|
||||
*it = p->as<bool>();
|
||||
++p;
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Alloc>
|
||||
struct pack<std::vector<bool, Alloc> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<bool, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(typename std::vector<bool, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(static_cast<bool>(*it));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Alloc>
|
||||
struct object_with_zone<std::vector<bool, Alloc> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::vector<bool, Alloc>& v) const {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename std::vector<bool, Alloc>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(static_cast<bool>(*it), o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/vector_bool.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_VECTOR_BOOL_HPP
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,80 +10,6 @@
|
||||
#ifndef MSGPACK_TYPE_VECTOR_CHAR_HPP
|
||||
#define MSGPACK_TYPE_VECTOR_CHAR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename Alloc>
|
||||
struct convert<std::vector<char, Alloc> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::vector<char, Alloc>& v) const {
|
||||
switch (o.type) {
|
||||
case msgpack::type::BIN:
|
||||
v.resize(o.via.bin.size);
|
||||
std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case msgpack::type::STR:
|
||||
v.resize(o.via.str.size);
|
||||
std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size);
|
||||
break;
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Alloc>
|
||||
struct pack<std::vector<char, Alloc> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<char, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_bin(size);
|
||||
o.pack_bin_body(&v.front(), size);
|
||||
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Alloc>
|
||||
struct object<std::vector<char, Alloc> > {
|
||||
void operator()(msgpack::object& o, const std::vector<char, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
o.via.bin.ptr = &v.front();
|
||||
o.via.bin.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Alloc>
|
||||
struct object_with_zone<std::vector<char, Alloc> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::vector<char, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.bin.ptr = ptr;
|
||||
o.via.bin.size = size;
|
||||
std::memcpy(ptr, &v.front(), size);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/vector_char.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_VECTOR_CHAR_HPP
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,80 +10,6 @@
|
||||
#ifndef MSGPACK_TYPE_VECTOR_UNSIGNED_CHAR_HPP
|
||||
#define MSGPACK_TYPE_VECTOR_UNSIGNED_CHAR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename Alloc>
|
||||
struct convert<std::vector<unsigned char, Alloc> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::vector<unsigned char, Alloc>& v) const {
|
||||
switch (o.type) {
|
||||
case msgpack::type::BIN:
|
||||
v.resize(o.via.bin.size);
|
||||
std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case msgpack::type::STR:
|
||||
v.resize(o.via.str.size);
|
||||
std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size);
|
||||
break;
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Alloc>
|
||||
struct pack<std::vector<unsigned char, Alloc> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<unsigned char, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_bin(size);
|
||||
o.pack_bin_body(reinterpret_cast<char const*>(&v.front()), size);
|
||||
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Alloc>
|
||||
struct object<std::vector<unsigned char, Alloc> > {
|
||||
void operator()(msgpack::object& o, const std::vector<unsigned char, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
o.via.bin.ptr = reinterpret_cast<char const*>(&v.front());
|
||||
o.via.bin.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Alloc>
|
||||
struct object_with_zone<std::vector<unsigned char, Alloc> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::vector<unsigned char, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.bin.ptr = ptr;
|
||||
o.via.bin.size = size;
|
||||
std::memcpy(ptr, &v.front(), size);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/adaptor/vector_unsigned_char.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_VECTOR_UNSIGNED_CHAR_HPP
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ C++03/C++11 Adaptation
|
||||
//
|
||||
// Copyright (C) 2013 KONDO Takatoshi
|
||||
// Copyright (C) 2013-2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,115 +10,8 @@
|
||||
#ifndef MSGPACK_CPP_CONFIG_HPP
|
||||
#define MSGPACK_CPP_CONFIG_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/cpp_config_decl.hpp"
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
# if defined(_MSC_VER)
|
||||
# if _MSC_VER < 1900
|
||||
# define MSGPACK_USE_CPP03
|
||||
# endif
|
||||
# elif (__cplusplus < 201103L)
|
||||
# define MSGPACK_USE_CPP03
|
||||
# endif
|
||||
#endif // MSGPACK_USE_CPP03
|
||||
#include "msgpack/v1/cpp_config.hpp"
|
||||
|
||||
|
||||
|
||||
#if defined(MSGPACK_USE_CPP03)
|
||||
|
||||
#if !defined(nullptr)
|
||||
# if _MSC_VER < 1600
|
||||
# define nullptr (0)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
template <typename T>
|
||||
struct unique_ptr : std::auto_ptr<T> {
|
||||
explicit unique_ptr(T* p = 0) throw() : std::auto_ptr<T>(p) {}
|
||||
unique_ptr(unique_ptr& a) throw() : std::auto_ptr<T>(a) {}
|
||||
template<class Y>
|
||||
unique_ptr (unique_ptr<Y>& a) throw() : std::auto_ptr<T>(a) {}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
T& move(T& t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T const& move(T const& t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
template <bool P, typename T = void>
|
||||
struct enable_if {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct enable_if<false, T> {
|
||||
};
|
||||
|
||||
template<typename T, T val>
|
||||
struct integral_constant {
|
||||
static T const value = val;
|
||||
typedef T value_type;
|
||||
typedef integral_constant<T, val> type;
|
||||
};
|
||||
|
||||
typedef integral_constant<bool, true> true_type;
|
||||
typedef integral_constant<bool, false> false_type;
|
||||
|
||||
template<class T, class U>
|
||||
struct is_same : false_type {};
|
||||
|
||||
template<class T>
|
||||
struct is_same<T, T> : true_type {};
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
#else // MSGPACK_USE_CPP03
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
||||
namespace msgpack {
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
// unique_ptr
|
||||
using std::unique_ptr;
|
||||
// using std::make_unique; // since C++14
|
||||
using std::hash;
|
||||
|
||||
// utility
|
||||
using std::move;
|
||||
using std::swap;
|
||||
using std::enable_if;
|
||||
using std::is_same;
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
#endif // MSGPACK_USE_CPP03
|
||||
|
||||
#endif /* msgpack/cpp_config.hpp */
|
||||
#endif // MSGPACK_CPP_CONFIG_HPP
|
||||
|
16
include/msgpack/cpp_config_decl.hpp
Normal file
16
include/msgpack/cpp_config_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ C++03/C++11 Adaptation
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP_CONFIG_DECL_HPP
|
||||
#define MSGPACK_CPP_CONFIG_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/cpp_config_decl.hpp"
|
||||
#include "msgpack/v2/cpp_config_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_CPP_CONFIG_DECL_HPP
|
@ -7,54 +7,11 @@
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#ifndef MSGPACK_FBUFFER_HPP__
|
||||
#define MSGPACK_FBUFFER_HPP__
|
||||
#ifndef MSGPACK_FBUFFER_HPP
|
||||
#define MSGPACK_FBUFFER_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/fbuffer_decl.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <stdexcept>
|
||||
#include "msgpack/v1/fbuffer.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
class fbuffer {
|
||||
public:
|
||||
explicit fbuffer(FILE* file) : m_file(file) { }
|
||||
|
||||
public:
|
||||
void write(const char* buf, unsigned int len)
|
||||
{
|
||||
if (1 != fwrite(buf, len, 1, m_file)) {
|
||||
throw std::runtime_error("fwrite() failed");
|
||||
}
|
||||
}
|
||||
|
||||
FILE* file() const
|
||||
{
|
||||
return m_file;
|
||||
}
|
||||
|
||||
#if defined(MSGPACK_USE_CPP03)
|
||||
private:
|
||||
fbuffer(const fbuffer&);
|
||||
fbuffer& operator=(const fbuffer&);
|
||||
#else // defined(MSGPACK_USE_CPP03)
|
||||
fbuffer(const fbuffer&) = delete;
|
||||
fbuffer& operator=(const fbuffer&) = delete;
|
||||
#endif // defined(MSGPACK_USE_CPP03)
|
||||
|
||||
private:
|
||||
FILE* m_file;
|
||||
};
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/fbuffer.hpp */
|
||||
#endif // MSGPACK_FBUFFER_HPP
|
||||
|
16
include/msgpack/fbuffer_decl.hpp
Normal file
16
include/msgpack/fbuffer_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ FILE* buffer adaptor
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_FBUFFER_DECL_HPP
|
||||
#define MSGPACK_FBUFFER_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/fbuffer_decl.hpp"
|
||||
#include "msgpack/v2/fbuffer_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_FBUFFER_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 MIZUKI Hirata
|
||||
// Copyright (C) 2015-2016 MIZUKI Hirata
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,29 +10,9 @@
|
||||
|
||||
#ifndef MSGPACK_ITERATOR_HPP
|
||||
#define MSGPACK_ITERATOR_HPP
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
#include <msgpack/object_fwd.hpp>
|
||||
#include <msgpack/iterator_decl.hpp>
|
||||
|
||||
namespace msgpack
|
||||
{
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
|
||||
{
|
||||
/// @endcond
|
||||
inline object_kv* begin(object_map &map) { return map.ptr; }
|
||||
inline const object_kv* begin(const object_map &map) { return map.ptr; }
|
||||
inline object_kv* end(object_map &map) { return map.ptr + map.size; }
|
||||
inline const object_kv* end(const object_map &map) { return map.ptr + map.size; }
|
||||
#include <msgpack/v1/iterator.hpp>
|
||||
|
||||
inline object* begin(object_array &array) { return array.ptr; }
|
||||
inline const object* begin(const object_array &array) { return array.ptr; }
|
||||
inline object* end(object_array &array) { return array.ptr + array.size; }
|
||||
inline const object* end(const object_array &array) { return array.ptr + array.size; }
|
||||
/// @cond
|
||||
}
|
||||
/// @endcond
|
||||
}
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
#endif // MSGPACK_ITERATOR_HPP
|
||||
|
17
include/msgpack/iterator_decl.hpp
Normal file
17
include/msgpack/iterator_decl.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_ITERATOR_DECL_HPP
|
||||
#define MSGPACK_ITERATOR_DECL_HPP
|
||||
|
||||
#include <msgpack/v1/iterator_decl.hpp>
|
||||
#include <msgpack/v2/iterator_decl.hpp>
|
||||
|
||||
#endif // MSGPACK_V1_ITERATOR_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
// Copyright (C) 2015-2016 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -11,41 +11,8 @@
|
||||
#ifndef MSGPACK_META_HPP
|
||||
#define MSGPACK_META_HPP
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
#include "msgpack/meta_decl.hpp"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace detail {
|
||||
template<bool...> struct bool_pack;
|
||||
|
||||
template<bool...values> struct all_of_imp
|
||||
: std::is_same<bool_pack<values..., true>, bool_pack<true, values...>>{};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<template <class> class T, class... U>
|
||||
using all_of = detail::all_of_imp<T<U>::value...>;
|
||||
|
||||
template<std::size_t... Is> struct seq {};
|
||||
|
||||
template<std::size_t N, std::size_t... Is>
|
||||
struct gen_seq : gen_seq<N-1, N-1, Is...> {};
|
||||
|
||||
template<std::size_t... Is>
|
||||
struct gen_seq<0, Is...> : seq<Is...> {};
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
#include "msgpack/v1/meta.hpp"
|
||||
|
||||
#endif // MSGPACK_META_HPP
|
||||
|
17
include/msgpack/meta_decl.hpp
Normal file
17
include/msgpack/meta_decl.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015-2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_META_DECL_HPP
|
||||
#define MSGPACK_META_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/meta_decl.hpp"
|
||||
#include "msgpack/v2/meta_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_META_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,832 +10,8 @@
|
||||
#ifndef MSGPACK_OBJECT_HPP
|
||||
#define MSGPACK_OBJECT_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/pack.hpp"
|
||||
#include "msgpack/zone.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object_decl.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <typeinfo>
|
||||
#include <limits>
|
||||
#include <ostream>
|
||||
#include <typeinfo>
|
||||
#include <iomanip>
|
||||
#include "msgpack/v1/object.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
/// The class holds object and zone
|
||||
class object_handle {
|
||||
public:
|
||||
/// Constructor that creates nil object and null zone.
|
||||
object_handle() {}
|
||||
|
||||
/// Constructor that creates an object_handle holding object `obj` and zone `z`.
|
||||
/**
|
||||
* @param obj object
|
||||
* @param z zone
|
||||
*/
|
||||
object_handle(msgpack::object const& obj, msgpack::unique_ptr<msgpack::zone> z) :
|
||||
m_obj(obj), m_zone(msgpack::move(z)) { }
|
||||
|
||||
// obsolete
|
||||
void set(msgpack::object const& obj)
|
||||
{ m_obj = obj; }
|
||||
|
||||
/// Get object reference
|
||||
/**
|
||||
* @return object
|
||||
*/
|
||||
const msgpack::object& get() const
|
||||
{ return m_obj; }
|
||||
|
||||
/// Get unique_ptr reference of zone.
|
||||
/**
|
||||
* @return unique_ptr reference of zone
|
||||
*/
|
||||
msgpack::unique_ptr<msgpack::zone>& zone()
|
||||
{ return m_zone; }
|
||||
|
||||
/// Get unique_ptr const reference of zone.
|
||||
/**
|
||||
* @return unique_ptr const reference of zone
|
||||
*/
|
||||
const msgpack::unique_ptr<msgpack::zone>& zone() const
|
||||
{ return m_zone; }
|
||||
|
||||
#if defined(MSGPACK_USE_CPP03)
|
||||
struct object_handle_ref {
|
||||
object_handle_ref(object_handle* oh):m_oh(oh) {}
|
||||
object_handle* m_oh;
|
||||
};
|
||||
|
||||
object_handle(object_handle& other):
|
||||
m_obj(other.m_obj),
|
||||
m_zone(msgpack::move(other.m_zone)) {
|
||||
}
|
||||
|
||||
object_handle(object_handle_ref ref):
|
||||
m_obj(ref.m_oh->m_obj),
|
||||
m_zone(msgpack::move(ref.m_oh->m_zone)) {
|
||||
}
|
||||
|
||||
object_handle& operator=(object_handle& other) {
|
||||
m_obj = other.m_obj;
|
||||
m_zone = msgpack::move(other.m_zone);
|
||||
return *this;
|
||||
}
|
||||
|
||||
object_handle& operator=(object_handle_ref ref) {
|
||||
m_obj = ref.m_oh->m_obj;
|
||||
m_zone = msgpack::move(ref.m_oh->m_zone);
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator object_handle_ref() {
|
||||
return object_handle_ref(this);
|
||||
}
|
||||
#endif // defined(MSGPACK_USE_CPP03)
|
||||
|
||||
private:
|
||||
msgpack::object m_obj;
|
||||
msgpack::unique_ptr<msgpack::zone> m_zone;
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <std::size_t N>
|
||||
inline std::size_t add_ext_type_size(std::size_t size) {
|
||||
return size + 1;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline std::size_t add_ext_type_size<4>(std::size_t size) {
|
||||
return size == 0xffffffff ? size : size + 1;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
inline std::size_t aligned_zone_size(msgpack::object const& obj) {
|
||||
std::size_t s = 0;
|
||||
switch (obj.type) {
|
||||
case msgpack::type::ARRAY:
|
||||
s += sizeof(msgpack::object) * obj.via.array.size;
|
||||
for (uint32_t i = 0; i < obj.via.array.size; ++i) {
|
||||
s += msgpack::aligned_zone_size(obj.via.array.ptr[i]);
|
||||
}
|
||||
break;
|
||||
case msgpack::type::MAP:
|
||||
s += sizeof(msgpack::object_kv) * obj.via.map.size;
|
||||
for (uint32_t i = 0; i < obj.via.map.size; ++i) {
|
||||
s += msgpack::aligned_zone_size(obj.via.map.ptr[i].key);
|
||||
s += msgpack::aligned_zone_size(obj.via.map.ptr[i].val);
|
||||
}
|
||||
break;
|
||||
case msgpack::type::EXT:
|
||||
s += msgpack::aligned_size(
|
||||
detail::add_ext_type_size<sizeof(std::size_t)>(obj.via.ext.size));
|
||||
break;
|
||||
case msgpack::type::STR:
|
||||
s += msgpack::aligned_size(obj.via.str.size);
|
||||
break;
|
||||
case msgpack::type::BIN:
|
||||
s += msgpack::aligned_size(obj.via.bin.size);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/// clone object
|
||||
/**
|
||||
* Clone (deep copy) object.
|
||||
* The copied object is located on newly allocated zone.
|
||||
* @param obj copy source object
|
||||
*
|
||||
* @return object_handle that holds deep copied object and zone.
|
||||
*/
|
||||
inline object_handle clone(msgpack::object const& obj) {
|
||||
std::size_t size = msgpack::aligned_zone_size(obj);
|
||||
msgpack::unique_ptr<msgpack::zone> z(size == 0 ? nullptr : new msgpack::zone(size));
|
||||
msgpack::object newobj = z.get() ? msgpack::object(obj, *z) : obj;
|
||||
return object_handle(newobj, msgpack::move(z));
|
||||
}
|
||||
|
||||
struct object::implicit_type {
|
||||
implicit_type(object const& o) : obj(o) { }
|
||||
~implicit_type() { }
|
||||
|
||||
template <typename T>
|
||||
operator T() { return obj.as<T>(); }
|
||||
|
||||
private:
|
||||
msgpack::object const& obj;
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
template <typename Stream, typename T>
|
||||
struct packer_serializer {
|
||||
static msgpack::packer<Stream>& pack(msgpack::packer<Stream>& o, const T& v) {
|
||||
v.msgpack_pack(o);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
// Adaptor functors' member functions definitions.
|
||||
template <typename T, typename Enabler>
|
||||
inline
|
||||
msgpack::object const&
|
||||
msgpack::adaptor::convert<T, Enabler>::operator()(msgpack::object const& o, T& v) const {
|
||||
v.msgpack_unpack(o.convert());
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T, typename Enabler>
|
||||
template <typename Stream>
|
||||
inline
|
||||
msgpack::packer<Stream>&
|
||||
msgpack::adaptor::pack<T, Enabler>::operator()(msgpack::packer<Stream>& o, T const& v) const {
|
||||
return msgpack::detail::packer_serializer<Stream, T>::pack(o, v);
|
||||
}
|
||||
|
||||
template <typename T, typename Enabler>
|
||||
inline
|
||||
void
|
||||
msgpack::adaptor::object_with_zone<T, Enabler>::operator()(msgpack::object::with_zone& o, T const& v) const {
|
||||
v.msgpack_object(static_cast<msgpack::object*>(&o), o.zone);
|
||||
}
|
||||
|
||||
// Adaptor functor specialization to object
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<msgpack::object> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, msgpack::object& v) const {
|
||||
v = o;
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<msgpack::object> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, msgpack::object const& v) const {
|
||||
switch(v.type) {
|
||||
case msgpack::type::NIL:
|
||||
o.pack_nil();
|
||||
return o;
|
||||
|
||||
case msgpack::type::BOOLEAN:
|
||||
if(v.via.boolean) {
|
||||
o.pack_true();
|
||||
} else {
|
||||
o.pack_false();
|
||||
}
|
||||
return o;
|
||||
|
||||
case msgpack::type::POSITIVE_INTEGER:
|
||||
o.pack_uint64(v.via.u64);
|
||||
return o;
|
||||
|
||||
case msgpack::type::NEGATIVE_INTEGER:
|
||||
o.pack_int64(v.via.i64);
|
||||
return o;
|
||||
|
||||
case msgpack::type::FLOAT:
|
||||
o.pack_double(v.via.f64);
|
||||
return o;
|
||||
|
||||
case msgpack::type::STR:
|
||||
o.pack_str(v.via.str.size);
|
||||
o.pack_str_body(v.via.str.ptr, v.via.str.size);
|
||||
return o;
|
||||
|
||||
case msgpack::type::BIN:
|
||||
o.pack_bin(v.via.bin.size);
|
||||
o.pack_bin_body(v.via.bin.ptr, v.via.bin.size);
|
||||
return o;
|
||||
|
||||
case msgpack::type::EXT:
|
||||
o.pack_ext(v.via.ext.size, v.via.ext.type());
|
||||
o.pack_ext_body(v.via.ext.data(), v.via.ext.size);
|
||||
return o;
|
||||
|
||||
case msgpack::type::ARRAY:
|
||||
o.pack_array(v.via.array.size);
|
||||
for(msgpack::object* p(v.via.array.ptr),
|
||||
* const pend(v.via.array.ptr + v.via.array.size);
|
||||
p < pend; ++p) {
|
||||
msgpack::operator<<(o, *p);
|
||||
}
|
||||
return o;
|
||||
|
||||
case msgpack::type::MAP:
|
||||
o.pack_map(v.via.map.size);
|
||||
for(msgpack::object_kv* p(v.via.map.ptr),
|
||||
* const pend(v.via.map.ptr + v.via.map.size);
|
||||
p < pend; ++p) {
|
||||
msgpack::operator<<(o, p->key);
|
||||
msgpack::operator<<(o, p->val);
|
||||
}
|
||||
return o;
|
||||
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<msgpack::object> {
|
||||
void operator()(msgpack::object::with_zone& o, msgpack::object const& v) const {
|
||||
o.type = v.type;
|
||||
|
||||
switch(v.type) {
|
||||
case msgpack::type::NIL:
|
||||
case msgpack::type::BOOLEAN:
|
||||
case msgpack::type::POSITIVE_INTEGER:
|
||||
case msgpack::type::NEGATIVE_INTEGER:
|
||||
case msgpack::type::FLOAT:
|
||||
std::memcpy(&o.via, &v.via, sizeof(v.via));
|
||||
return;
|
||||
|
||||
case msgpack::type::STR: {
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(v.via.str.size));
|
||||
o.via.str.ptr = ptr;
|
||||
o.via.str.size = v.via.str.size;
|
||||
std::memcpy(ptr, v.via.str.ptr, v.via.str.size);
|
||||
return;
|
||||
}
|
||||
|
||||
case msgpack::type::BIN: {
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(v.via.bin.size));
|
||||
o.via.bin.ptr = ptr;
|
||||
o.via.bin.size = v.via.bin.size;
|
||||
std::memcpy(ptr, v.via.bin.ptr, v.via.bin.size);
|
||||
return;
|
||||
}
|
||||
|
||||
case msgpack::type::EXT: {
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(v.via.ext.size + 1));
|
||||
o.via.ext.ptr = ptr;
|
||||
o.via.ext.size = v.via.ext.size;
|
||||
std::memcpy(ptr, v.via.ext.ptr, v.via.ext.size + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
case msgpack::type::ARRAY:
|
||||
o.via.array.ptr = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object) * v.via.array.size));
|
||||
o.via.array.size = v.via.array.size;
|
||||
for (msgpack::object
|
||||
* po(o.via.array.ptr),
|
||||
* pv(v.via.array.ptr),
|
||||
* const pvend(v.via.array.ptr + v.via.array.size);
|
||||
pv < pvend;
|
||||
++po, ++pv) {
|
||||
new (po) msgpack::object(*pv, o.zone);
|
||||
}
|
||||
return;
|
||||
|
||||
case msgpack::type::MAP:
|
||||
o.via.map.ptr = (msgpack::object_kv*)o.zone.allocate_align(sizeof(msgpack::object_kv) * v.via.map.size);
|
||||
o.via.map.size = v.via.map.size;
|
||||
for(msgpack::object_kv
|
||||
* po(o.via.map.ptr),
|
||||
* pv(v.via.map.ptr),
|
||||
* const pvend(v.via.map.ptr + v.via.map.size);
|
||||
pv < pvend;
|
||||
++po, ++pv) {
|
||||
msgpack::object_kv* kv = new (po) msgpack::object_kv;
|
||||
new (&kv->key) msgpack::object(pv->key, o.zone);
|
||||
new (&kv->val) msgpack::object(pv->val, o.zone);
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Adaptor functor specialization to object::with_zone
|
||||
|
||||
template <>
|
||||
struct object_with_zone<msgpack::object::with_zone> {
|
||||
void operator()(
|
||||
msgpack::object::with_zone& o,
|
||||
msgpack::object::with_zone const& v) const {
|
||||
o << static_cast<msgpack::object const&>(v);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
|
||||
// obsolete
|
||||
template <typename Type>
|
||||
class define : public Type {
|
||||
public:
|
||||
typedef Type msgpack_type;
|
||||
typedef define<Type> define_type;
|
||||
|
||||
define() {}
|
||||
define(const msgpack_type& v) : msgpack_type(v) {}
|
||||
|
||||
template <typename Packer>
|
||||
void msgpack_pack(Packer& o) const
|
||||
{
|
||||
msgpack::operator<<(o, static_cast<const msgpack_type&>(*this));
|
||||
}
|
||||
|
||||
void msgpack_unpack(object const& o)
|
||||
{
|
||||
msgpack::operator>>(o, static_cast<msgpack_type&>(*this));
|
||||
}
|
||||
};
|
||||
|
||||
// deconvert operator
|
||||
|
||||
template <typename Stream>
|
||||
template <typename T>
|
||||
inline msgpack::packer<Stream>& packer<Stream>::pack(const T& v)
|
||||
{
|
||||
msgpack::operator<<(*this, v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool operator==(const msgpack::object& x, const msgpack::object& y)
|
||||
{
|
||||
if(x.type != y.type) { return false; }
|
||||
|
||||
switch(x.type) {
|
||||
case msgpack::type::NIL:
|
||||
return true;
|
||||
|
||||
case msgpack::type::BOOLEAN:
|
||||
return x.via.boolean == y.via.boolean;
|
||||
|
||||
case msgpack::type::POSITIVE_INTEGER:
|
||||
return x.via.u64 == y.via.u64;
|
||||
|
||||
case msgpack::type::NEGATIVE_INTEGER:
|
||||
return x.via.i64 == y.via.i64;
|
||||
|
||||
case msgpack::type::FLOAT:
|
||||
return x.via.f64 == y.via.f64;
|
||||
|
||||
case msgpack::type::STR:
|
||||
return x.via.str.size == y.via.str.size &&
|
||||
std::memcmp(x.via.str.ptr, y.via.str.ptr, x.via.str.size) == 0;
|
||||
|
||||
case msgpack::type::BIN:
|
||||
return x.via.bin.size == y.via.bin.size &&
|
||||
std::memcmp(x.via.bin.ptr, y.via.bin.ptr, x.via.bin.size) == 0;
|
||||
|
||||
case msgpack::type::EXT:
|
||||
return x.via.ext.size == y.via.ext.size &&
|
||||
std::memcmp(x.via.ext.ptr, y.via.ext.ptr, x.via.ext.size) == 0;
|
||||
|
||||
case msgpack::type::ARRAY:
|
||||
if(x.via.array.size != y.via.array.size) {
|
||||
return false;
|
||||
} else if(x.via.array.size == 0) {
|
||||
return true;
|
||||
} else {
|
||||
msgpack::object* px = x.via.array.ptr;
|
||||
msgpack::object* const pxend = x.via.array.ptr + x.via.array.size;
|
||||
msgpack::object* py = y.via.array.ptr;
|
||||
do {
|
||||
if(!(*px == *py)) {
|
||||
return false;
|
||||
}
|
||||
++px;
|
||||
++py;
|
||||
} while(px < pxend);
|
||||
return true;
|
||||
}
|
||||
|
||||
case msgpack::type::MAP:
|
||||
if(x.via.map.size != y.via.map.size) {
|
||||
return false;
|
||||
} else if(x.via.map.size == 0) {
|
||||
return true;
|
||||
} else {
|
||||
msgpack::object_kv* px = x.via.map.ptr;
|
||||
msgpack::object_kv* const pxend = x.via.map.ptr + x.via.map.size;
|
||||
msgpack::object_kv* py = y.via.map.ptr;
|
||||
do {
|
||||
if(!(px->key == py->key) || !(px->val == py->val)) {
|
||||
return false;
|
||||
}
|
||||
++px;
|
||||
++py;
|
||||
} while(px < pxend);
|
||||
return true;
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator==(const msgpack::object& x, const T& y)
|
||||
try {
|
||||
return x == msgpack::object(y);
|
||||
} catch (msgpack::type_error&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool operator!=(const msgpack::object& x, const msgpack::object& y)
|
||||
{ return !(x == y); }
|
||||
|
||||
template <typename T>
|
||||
inline bool operator==(const T& y, const msgpack::object& x)
|
||||
{ return x == y; }
|
||||
|
||||
template <typename T>
|
||||
inline bool operator!=(const msgpack::object& x, const T& y)
|
||||
{ return !(x == y); }
|
||||
|
||||
template <typename T>
|
||||
inline bool operator!=(const T& y, const msgpack::object& x)
|
||||
{ return x != y; }
|
||||
|
||||
|
||||
inline msgpack::object::implicit_type object::convert() const
|
||||
{
|
||||
return msgpack::object::implicit_type(*this);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T& object::convert(T& v) const
|
||||
{
|
||||
msgpack::operator>>(*this, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
#if !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
|
||||
template <typename T>
|
||||
inline T* object::convert(T* v) const
|
||||
{
|
||||
convert(*v);
|
||||
return v;
|
||||
}
|
||||
#endif // !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
|
||||
|
||||
template <typename T>
|
||||
inline bool object::convert_if_not_nil(T& v) const
|
||||
{
|
||||
if (is_nil()) {
|
||||
return false;
|
||||
}
|
||||
convert(v);
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T>
|
||||
inline T object::as() const
|
||||
{
|
||||
T v;
|
||||
convert(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
#else // defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T>
|
||||
inline typename std::enable_if<msgpack::has_as<T>::value, T>::type object::as() const {
|
||||
return msgpack::adaptor::as<T>()(*this);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline typename std::enable_if<!msgpack::has_as<T>::value, T>::type object::as() const {
|
||||
T v;
|
||||
convert(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif // defined(MSGPACK_USE_CPP03)
|
||||
|
||||
inline object::object()
|
||||
{
|
||||
type = msgpack::type::NIL;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline object::object(const T& v)
|
||||
{
|
||||
msgpack::operator<<(*this, v);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline object& object::operator=(const T& v)
|
||||
{
|
||||
*this = object(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
object::object(const T& v, msgpack::zone& z)
|
||||
{
|
||||
with_zone oz(z);
|
||||
msgpack::operator<<(oz, v);
|
||||
type = oz.type;
|
||||
via = oz.via;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
object::object(const T& v, msgpack::zone* z)
|
||||
{
|
||||
with_zone oz(*z);
|
||||
msgpack::operator<<(oz, v);
|
||||
type = oz.type;
|
||||
via = oz.via;
|
||||
}
|
||||
|
||||
|
||||
inline object::object(const msgpack_object& o)
|
||||
{
|
||||
// FIXME beter way?
|
||||
std::memcpy(this, &o, sizeof(o));
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, const msgpack_object& v)
|
||||
{
|
||||
// FIXME beter way?
|
||||
std::memcpy(&o, &v, sizeof(v));
|
||||
}
|
||||
|
||||
inline object::operator msgpack_object() const
|
||||
{
|
||||
// FIXME beter way?
|
||||
msgpack_object obj;
|
||||
std::memcpy(&obj, this, sizeof(obj));
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
// obsolete
|
||||
template <typename T>
|
||||
inline void convert(T& v, msgpack::object const& o)
|
||||
{
|
||||
o.convert(v);
|
||||
}
|
||||
|
||||
// obsolete
|
||||
template <typename Stream, typename T>
|
||||
inline void pack(msgpack::packer<Stream>& o, const T& v)
|
||||
{
|
||||
o.pack(v);
|
||||
}
|
||||
|
||||
// obsolete
|
||||
template <typename Stream, typename T>
|
||||
inline void pack_copy(msgpack::packer<Stream>& o, T v)
|
||||
{
|
||||
pack(o, v);
|
||||
}
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const msgpack::object& v)
|
||||
{
|
||||
switch(v.type) {
|
||||
case msgpack::type::NIL:
|
||||
o.pack_nil();
|
||||
return o;
|
||||
|
||||
case msgpack::type::BOOLEAN:
|
||||
if(v.via.boolean) {
|
||||
o.pack_true();
|
||||
} else {
|
||||
o.pack_false();
|
||||
}
|
||||
return o;
|
||||
|
||||
case msgpack::type::POSITIVE_INTEGER:
|
||||
o.pack_uint64(v.via.u64);
|
||||
return o;
|
||||
|
||||
case msgpack::type::NEGATIVE_INTEGER:
|
||||
o.pack_int64(v.via.i64);
|
||||
return o;
|
||||
|
||||
case msgpack::type::FLOAT:
|
||||
o.pack_double(v.via.f64);
|
||||
return o;
|
||||
|
||||
case msgpack::type::STR:
|
||||
o.pack_str(v.via.str.size);
|
||||
o.pack_str_body(v.via.str.ptr, v.via.str.size);
|
||||
return o;
|
||||
|
||||
case msgpack::type::BIN:
|
||||
o.pack_bin(v.via.bin.size);
|
||||
o.pack_bin_body(v.via.bin.ptr, v.via.bin.size);
|
||||
return o;
|
||||
|
||||
case msgpack::type::EXT:
|
||||
o.pack_ext(v.via.ext.size, v.via.ext.type());
|
||||
o.pack_ext_body(v.via.ext.data(), v.via.ext.size);
|
||||
return o;
|
||||
|
||||
case msgpack::type::ARRAY:
|
||||
o.pack_array(v.via.array.size);
|
||||
for(msgpack::object* p(v.via.array.ptr),
|
||||
* const pend(v.via.array.ptr + v.via.array.size);
|
||||
p < pend; ++p) {
|
||||
msgpack::operator<<(o, *p);
|
||||
}
|
||||
return o;
|
||||
|
||||
case msgpack::type::MAP:
|
||||
o.pack_map(v.via.map.size);
|
||||
for(msgpack::object_kv* p(v.via.map.ptr),
|
||||
* const pend(v.via.map.ptr + v.via.map.size);
|
||||
p < pend; ++p) {
|
||||
msgpack::operator<<(o, p->key);
|
||||
msgpack::operator<<(o, p->val);
|
||||
}
|
||||
return o;
|
||||
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const msgpack::object::with_zone& v)
|
||||
{
|
||||
return o << static_cast<msgpack::object>(v);
|
||||
}
|
||||
|
||||
inline std::ostream& operator<< (std::ostream& s, const msgpack::object& o)
|
||||
{
|
||||
switch(o.type) {
|
||||
case msgpack::type::NIL:
|
||||
s << "nil";
|
||||
break;
|
||||
|
||||
case msgpack::type::BOOLEAN:
|
||||
s << (o.via.boolean ? "true" : "false");
|
||||
break;
|
||||
|
||||
case msgpack::type::POSITIVE_INTEGER:
|
||||
s << o.via.u64;
|
||||
break;
|
||||
|
||||
case msgpack::type::NEGATIVE_INTEGER:
|
||||
s << o.via.i64;
|
||||
break;
|
||||
|
||||
case msgpack::type::FLOAT:
|
||||
s << o.via.f64;
|
||||
break;
|
||||
|
||||
case msgpack::type::STR:
|
||||
s << '"';
|
||||
for (uint32_t i = 0; i < o.via.str.size; ++i) {
|
||||
char c = o.via.str.ptr[i];
|
||||
switch (c) {
|
||||
case '\\':
|
||||
s << "\\\\";
|
||||
break;
|
||||
case '"':
|
||||
s << "\\\"";
|
||||
break;
|
||||
case '/':
|
||||
s << "\\/";
|
||||
break;
|
||||
case '\b':
|
||||
s << "\\b";
|
||||
break;
|
||||
case '\f':
|
||||
s << "\\f";
|
||||
break;
|
||||
case '\n':
|
||||
s << "\\n";
|
||||
break;
|
||||
case '\r':
|
||||
s << "\\r";
|
||||
break;
|
||||
case '\t':
|
||||
s << "\\t";
|
||||
break;
|
||||
default: {
|
||||
unsigned int code = static_cast<unsigned int>(c);
|
||||
if (code < 0x20 || code == 0x7f) {
|
||||
s << "\\u" << std::hex << std::setw(4) << std::setfill('0') << (code & 0xff);
|
||||
}
|
||||
else {
|
||||
s << c;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
s << '"';
|
||||
break;
|
||||
|
||||
case msgpack::type::BIN:
|
||||
(s << '"').write(o.via.bin.ptr, o.via.bin.size) << '"';
|
||||
break;
|
||||
|
||||
case msgpack::type::EXT:
|
||||
s << "EXT";
|
||||
break;
|
||||
|
||||
case msgpack::type::ARRAY:
|
||||
s << "[";
|
||||
if(o.via.array.size != 0) {
|
||||
msgpack::object* p(o.via.array.ptr);
|
||||
s << *p;
|
||||
++p;
|
||||
for(msgpack::object* const pend(o.via.array.ptr + o.via.array.size);
|
||||
p < pend; ++p) {
|
||||
s << ", " << *p;
|
||||
}
|
||||
}
|
||||
s << "]";
|
||||
break;
|
||||
|
||||
case msgpack::type::MAP:
|
||||
s << "{";
|
||||
if(o.via.map.size != 0) {
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
s << p->key << ':' << p->val;
|
||||
++p;
|
||||
for(msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
p < pend; ++p) {
|
||||
s << ", " << p->key << ':' << p->val;
|
||||
}
|
||||
}
|
||||
s << "}";
|
||||
break;
|
||||
|
||||
default:
|
||||
// FIXME
|
||||
s << "#<UNKNOWN " << static_cast<uint16_t>(o.type) << ">";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#include "msgpack/type.hpp"
|
||||
|
||||
#endif /* msgpack/object.hpp */
|
||||
#endif // MSGPACK_OBJECT_HPP
|
||||
|
17
include/msgpack/object_decl.hpp
Normal file
17
include/msgpack/object_decl.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_OBJECT_DECL_HPP
|
||||
#define MSGPACK_OBJECT_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/object_decl.hpp"
|
||||
#include "msgpack/v2/object_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_OBJECT_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -11,263 +11,9 @@
|
||||
#ifndef MSGPACK_OBJECT_FWD_HPP
|
||||
#define MSGPACK_OBJECT_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/zone.hpp"
|
||||
#include "msgpack/object.h"
|
||||
#include "msgpack/object_fwd_decl.hpp"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
|
||||
namespace type {
|
||||
enum object_type {
|
||||
NIL = MSGPACK_OBJECT_NIL,
|
||||
BOOLEAN = MSGPACK_OBJECT_BOOLEAN,
|
||||
POSITIVE_INTEGER = MSGPACK_OBJECT_POSITIVE_INTEGER,
|
||||
NEGATIVE_INTEGER = MSGPACK_OBJECT_NEGATIVE_INTEGER,
|
||||
FLOAT = MSGPACK_OBJECT_FLOAT,
|
||||
#if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT)
|
||||
DOUBLE = MSGPACK_OBJECT_DOUBLE, // obsolete
|
||||
#endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT
|
||||
STR = MSGPACK_OBJECT_STR,
|
||||
BIN = MSGPACK_OBJECT_BIN,
|
||||
ARRAY = MSGPACK_OBJECT_ARRAY,
|
||||
MAP = MSGPACK_OBJECT_MAP,
|
||||
EXT = MSGPACK_OBJECT_EXT
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
struct object;
|
||||
struct object_kv;
|
||||
|
||||
struct object_array {
|
||||
uint32_t size;
|
||||
msgpack::object* ptr;
|
||||
};
|
||||
|
||||
struct object_map {
|
||||
uint32_t size;
|
||||
msgpack::object_kv* ptr;
|
||||
};
|
||||
|
||||
struct object_str {
|
||||
uint32_t size;
|
||||
const char* ptr;
|
||||
};
|
||||
|
||||
struct object_bin {
|
||||
uint32_t size;
|
||||
const char* ptr;
|
||||
};
|
||||
|
||||
struct object_ext {
|
||||
int8_t type() const { return ptr[0]; }
|
||||
const char* data() const { return &ptr[1]; }
|
||||
uint32_t size;
|
||||
const char* ptr;
|
||||
};
|
||||
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
struct object;
|
||||
|
||||
namespace adaptor {
|
||||
template <typename T, typename Enabler = void>
|
||||
struct as;
|
||||
} // namespace adaptor
|
||||
|
||||
template <typename T>
|
||||
struct has_as {
|
||||
private:
|
||||
template <typename U>
|
||||
static auto check(U*) ->
|
||||
typename std::is_same<
|
||||
decltype(msgpack::adaptor::as<U>()(std::declval<msgpack::object>())),
|
||||
T>::type;
|
||||
template <typename>
|
||||
static std::false_type check(...);
|
||||
public:
|
||||
using type = decltype(check<T>(nullptr));
|
||||
static constexpr bool value = type::value;
|
||||
};
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
/// Object class that corresponding to MessagePack format object
|
||||
/**
|
||||
* See https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_object
|
||||
*/
|
||||
struct object {
|
||||
union union_type {
|
||||
bool boolean;
|
||||
uint64_t u64;
|
||||
int64_t i64;
|
||||
#if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT)
|
||||
double dec; // obsolete
|
||||
#endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT
|
||||
double f64;
|
||||
msgpack::object_array array;
|
||||
msgpack::object_map map;
|
||||
msgpack::object_str str;
|
||||
msgpack::object_bin bin;
|
||||
msgpack::object_ext ext;
|
||||
};
|
||||
|
||||
msgpack::type::object_type type;
|
||||
union_type via;
|
||||
|
||||
/// Cheking nil
|
||||
/**
|
||||
* @return If the object is nil, then return true, else return false.
|
||||
*/
|
||||
bool is_nil() const { return type == msgpack::type::NIL; }
|
||||
|
||||
#if defined(MSGPACK_USE_CPP03)
|
||||
|
||||
/// Get value as T
|
||||
/**
|
||||
* If the object can't be converted to T, msgpack::type_error would be thrown.
|
||||
* @tparam T The type you want to get.
|
||||
* @return The converted object.
|
||||
*/
|
||||
template <typename T>
|
||||
T as() const;
|
||||
|
||||
#else // defined(MSGPACK_USE_CPP03)
|
||||
|
||||
/// Get value as T
|
||||
/**
|
||||
* If the object can't be converted to T, msgpack::type_error would be thrown.
|
||||
* @tparam T The type you want to get.
|
||||
* @return The converted object.
|
||||
*/
|
||||
template <typename T>
|
||||
typename std::enable_if<msgpack::has_as<T>::value, T>::type as() const;
|
||||
|
||||
/// Get value as T
|
||||
/**
|
||||
* If the object can't be converted to T, msgpack::type_error would be thrown.
|
||||
* @tparam T The type you want to get.
|
||||
* @return The converted object.
|
||||
*/
|
||||
template <typename T>
|
||||
typename std::enable_if<!msgpack::has_as<T>::value, T>::type as() const;
|
||||
|
||||
#endif // defined(MSGPACK_USE_CPP03)
|
||||
|
||||
/// Convert the object
|
||||
/**
|
||||
* If the object can't be converted to T, msgpack::type_error would be thrown.
|
||||
* @tparam T The type of v.
|
||||
* @param v The value you want to get. `v` is output parameter. `v` is overwritten by converted value from the object.
|
||||
* @return The reference of `v`.
|
||||
*/
|
||||
template <typename T>
|
||||
T& convert(T& v) const;
|
||||
|
||||
|
||||
#if !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
|
||||
/// Convert the object (obsolete)
|
||||
/**
|
||||
* If the object can't be converted to T, msgpack::type_error would be thrown.
|
||||
* @tparam T The type of v.
|
||||
* @param v The pointer of the value you want to get. `v` is output parameter. `*v` is overwritten by converted value from the object.
|
||||
* @return The pointer of `v`.
|
||||
*/
|
||||
template <typename T>
|
||||
T* convert(T* v) const;
|
||||
#endif // !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
|
||||
|
||||
/// Convert the object if not nil
|
||||
/**
|
||||
* If the object is not nil and can't be converted to T, msgpack::type_error would be thrown.
|
||||
* @tparam T The type of v.
|
||||
* @param v The value you want to get. `v` is output parameter. `v` is overwritten by converted value from the object if the object is not nil.
|
||||
* @return If the object is nil, then return false, else return true.
|
||||
*/
|
||||
template <typename T>
|
||||
bool convert_if_not_nil(T& v) const;
|
||||
|
||||
/// Default constructor. The object is set to nil.
|
||||
object();
|
||||
|
||||
/// Copy constructor. Object is shallow copied.
|
||||
object(const msgpack_object& o);
|
||||
|
||||
/// Construct object from T
|
||||
/**
|
||||
* If `v` is the type that is corresponding to MessegePack format str, bin, ext, array, or map,
|
||||
* you need to call `object(const T& v, msgpack::zone& z)` instead of this constructor.
|
||||
*
|
||||
* @tparam T The type of `v`.
|
||||
* @param v The value you want to convert.
|
||||
*/
|
||||
template <typename T>
|
||||
explicit object(const T& v);
|
||||
|
||||
/// Construct object from T
|
||||
/**
|
||||
* The object is constructed on the zone `z`.
|
||||
* See https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_object
|
||||
*
|
||||
* @tparam T The type of `v`.
|
||||
* @param v The value you want to convert.
|
||||
* @param z The zone that is used by the object.
|
||||
*/
|
||||
template <typename T>
|
||||
object(const T& v, msgpack::zone& z);
|
||||
|
||||
/// Construct object from T (obsolete)
|
||||
/**
|
||||
* The object is constructed on the zone `z`.
|
||||
* Use `object(const T& v, msgpack::zone& z)` instead of this constructor.
|
||||
* See https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_object
|
||||
*
|
||||
* @tparam T The type of `v`.
|
||||
* @param v The value you want to convert.
|
||||
* @param z The pointer to the zone that is used by the object.
|
||||
*/
|
||||
template <typename T>
|
||||
object(const T& v, msgpack::zone* z);
|
||||
|
||||
template <typename T>
|
||||
object& operator=(const T& v);
|
||||
|
||||
operator msgpack_object() const;
|
||||
|
||||
struct with_zone;
|
||||
|
||||
private:
|
||||
struct implicit_type;
|
||||
|
||||
public:
|
||||
implicit_type convert() const;
|
||||
};
|
||||
|
||||
class type_error : public std::bad_cast { };
|
||||
|
||||
struct object_kv {
|
||||
msgpack::object key;
|
||||
msgpack::object val;
|
||||
};
|
||||
|
||||
struct object::with_zone : object {
|
||||
with_zone(msgpack::zone& z) : zone(z) { }
|
||||
msgpack::zone& zone;
|
||||
private:
|
||||
with_zone();
|
||||
};
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
#include "msgpack/v1/object_fwd.hpp"
|
||||
#include "msgpack/v2/object_fwd.hpp"
|
||||
|
||||
#endif // MSGPACK_OBJECT_FWD_HPP
|
||||
|
17
include/msgpack/object_fwd_decl.hpp
Normal file
17
include/msgpack/object_fwd_decl.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_OBJECT_FWD_DECL_HPP
|
||||
#define MSGPACK_OBJECT_FWD_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/object_fwd_decl.hpp"
|
||||
#include "msgpack/v2/object_fwd_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_OBJECT_FWD_DECL_HPP
|
File diff suppressed because it is too large
Load Diff
16
include/msgpack/pack_decl.hpp
Normal file
16
include/msgpack/pack_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ serializing routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_PACK_DECL_HPP
|
||||
#define MSGPACK_PACK_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/pack_decl.hpp"
|
||||
#include "msgpack/v2/pack_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_PACK_DECL_HPP
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ simple buffer implementation
|
||||
//
|
||||
// Copyright (C) 2008-2013 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -10,143 +10,8 @@
|
||||
#ifndef MSGPACK_SBUFFER_HPP
|
||||
#define MSGPACK_SBUFFER_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/sbuffer_decl.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include "msgpack/v1/sbuffer.hpp"
|
||||
|
||||
#ifndef MSGPACK_SBUFFER_INIT_SIZE
|
||||
#define MSGPACK_SBUFFER_INIT_SIZE 8192
|
||||
#endif
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
class sbuffer {
|
||||
public:
|
||||
sbuffer(size_t initsz = MSGPACK_SBUFFER_INIT_SIZE):m_size(0), m_alloc(initsz)
|
||||
{
|
||||
if(initsz == 0) {
|
||||
m_data = nullptr;
|
||||
} else {
|
||||
m_data = (char*)::malloc(initsz);
|
||||
if(!m_data) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~sbuffer()
|
||||
{
|
||||
::free(m_data);
|
||||
}
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
sbuffer(const sbuffer&) = delete;
|
||||
sbuffer& operator=(const sbuffer&) = delete;
|
||||
|
||||
sbuffer(sbuffer&& other) :
|
||||
m_size(other.m_size), m_data(other.m_data), m_alloc(other.m_alloc)
|
||||
{
|
||||
other.m_size = other.m_alloc = 0;
|
||||
other.m_data = nullptr;
|
||||
}
|
||||
|
||||
sbuffer& operator=(sbuffer&& other)
|
||||
{
|
||||
::free(m_data);
|
||||
|
||||
m_size = other.m_size;
|
||||
m_alloc = other.m_alloc;
|
||||
m_data = other.m_data;
|
||||
|
||||
other.m_size = other.m_alloc = 0;
|
||||
other.m_data = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
void write(const char* buf, size_t len)
|
||||
{
|
||||
if(m_alloc - m_size < len) {
|
||||
expand_buffer(len);
|
||||
}
|
||||
std::memcpy(m_data + m_size, buf, len);
|
||||
m_size += len;
|
||||
}
|
||||
|
||||
char* data()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
const char* data() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
char* release()
|
||||
{
|
||||
char* tmp = m_data;
|
||||
m_size = 0;
|
||||
m_data = nullptr;
|
||||
m_alloc = 0;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
void expand_buffer(size_t len)
|
||||
{
|
||||
size_t nsize = (m_alloc > 0) ?
|
||||
m_alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE;
|
||||
|
||||
while(nsize < m_size + len) {
|
||||
size_t tmp_nsize = nsize * 2;
|
||||
if (tmp_nsize <= nsize) {
|
||||
nsize = m_size + len;
|
||||
break;
|
||||
}
|
||||
nsize = tmp_nsize;
|
||||
}
|
||||
|
||||
void* tmp = ::realloc(m_data, nsize);
|
||||
if(!tmp) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
m_data = static_cast<char*>(tmp);
|
||||
m_alloc = nsize;
|
||||
}
|
||||
|
||||
#if defined(MSGPACK_USE_CPP03)
|
||||
private:
|
||||
sbuffer(const sbuffer&);
|
||||
sbuffer& operator=(const sbuffer&);
|
||||
#endif // defined(MSGPACK_USE_CPP03)
|
||||
|
||||
private:
|
||||
size_t m_size;
|
||||
char* m_data;
|
||||
size_t m_alloc;
|
||||
};
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/sbuffer.hpp */
|
||||
#endif // MSGPACK_SBUFFER_HPP
|
||||
|
17
include/msgpack/sbuffer_decl.hpp
Normal file
17
include/msgpack/sbuffer_decl.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// MessagePack for C++ simple buffer implementation
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_SBUFFER_DECL_HPP
|
||||
#define MSGPACK_SBUFFER_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/sbuffer_decl.hpp"
|
||||
#include "msgpack/v2/sbuffer_decl.hpp"
|
||||
|
||||
|
||||
#endif // MSGPACK_SBUFFER_DECL_HPP
|
File diff suppressed because it is too large
Load Diff
16
include/msgpack/unpack_decl.hpp
Normal file
16
include/msgpack/unpack_decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ deserializing routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_UNPACK_DECL_HPP
|
||||
#define MSGPACK_UNPACK_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/unpack_decl.hpp"
|
||||
#include "msgpack/v2/unpack_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_UNPACK_DECL_HPP
|
82
include/msgpack/v1/adaptor/adaptor_base.hpp
Normal file
82
include/msgpack/v1/adaptor/adaptor_base.hpp
Normal file
@ -0,0 +1,82 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015-2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_ADAPTOR_BASE_HPP
|
||||
#define MSGPACK_V1_ADAPTOR_BASE_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/adaptor_base_decl.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
// Adaptor functors
|
||||
|
||||
template <typename T, typename Enabler>
|
||||
struct convert {
|
||||
msgpack::object const& operator()(msgpack::object const& o, T& v) const;
|
||||
};
|
||||
|
||||
template <typename T, typename Enabler>
|
||||
struct pack {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, T const& v) const;
|
||||
};
|
||||
|
||||
template <typename T, typename Enabler>
|
||||
struct object {
|
||||
void operator()(msgpack::object& o, T const& v) const;
|
||||
};
|
||||
|
||||
template <typename T, typename Enabler>
|
||||
struct object_with_zone {
|
||||
void operator()(msgpack::object::with_zone& o, T const& v) const;
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
// operators
|
||||
|
||||
template <typename T>
|
||||
inline
|
||||
msgpack::object const& operator>> (msgpack::object const& o, T& v) {
|
||||
return adaptor::convert<T>()(o, v);
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, T const& v) {
|
||||
return adaptor::pack<T>()(o, v);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline
|
||||
void operator<< (msgpack::object& o, T const& v) {
|
||||
adaptor::object<T>()(o, v);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline
|
||||
void operator<< (msgpack::object::with_zone& o, T const& v) {
|
||||
adaptor::object_with_zone<T>()(o, v);
|
||||
}
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
#endif // MSGPACK_V1_ADAPTOR_BASE_HPP
|
63
include/msgpack/v1/adaptor/adaptor_base_decl.hpp
Normal file
63
include/msgpack/v1/adaptor/adaptor_base_decl.hpp
Normal file
@ -0,0 +1,63 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_ADAPTOR_BASE_DECL_HPP
|
||||
#define MSGPACK_V1_ADAPTOR_BASE_DECL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
template <typename Stream>
|
||||
class packer;
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
// Adaptor functors
|
||||
|
||||
template <typename T, typename Enabler = void>
|
||||
struct convert;
|
||||
|
||||
template <typename T, typename Enabler = void>
|
||||
struct pack;
|
||||
|
||||
template <typename T, typename Enabler = void>
|
||||
struct object;
|
||||
|
||||
template <typename T, typename Enabler = void>
|
||||
struct object_with_zone;
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
// operators
|
||||
|
||||
template <typename T>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, T& v);
|
||||
|
||||
template <typename Stream, typename T>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, T const& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (msgpack::object& o, T const& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (msgpack::object::with_zone& o, T const& v);
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_ADAPTOR_BASE_DECL_HPP
|
173
include/msgpack/v1/adaptor/array_ref.hpp
Normal file
173
include/msgpack/v1/adaptor/array_ref.hpp
Normal file
@ -0,0 +1,173 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2016 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_ARRAY_REF_HPP
|
||||
#define MSGPACK_V1_TYPE_ARRAY_REF_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/array_ref.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
template <typename T>
|
||||
struct array_ref {
|
||||
array_ref() : data(nullptr) {}
|
||||
array_ref(T& t) : data(&t) {}
|
||||
|
||||
T* data;
|
||||
|
||||
template <typename U>
|
||||
bool operator==(array_ref<U> const& t) const {
|
||||
return *data == *t.data;
|
||||
}
|
||||
template <typename U>
|
||||
bool operator!=(array_ref<U> const& t) const {
|
||||
return !(*data == *t.data);
|
||||
}
|
||||
template <typename U>
|
||||
bool operator< (array_ref<U> const& t) const
|
||||
{
|
||||
return *data < *t.data;
|
||||
}
|
||||
template <typename U>
|
||||
bool operator> (array_ref<U> const& t) const
|
||||
{
|
||||
return *t.data < *data;
|
||||
}
|
||||
template <typename U>
|
||||
bool operator<= (array_ref<U> const& t) const
|
||||
{
|
||||
return !(*t.data < *data);
|
||||
}
|
||||
template <typename U>
|
||||
bool operator>= (array_ref<U> const& t) const
|
||||
{
|
||||
return !(*data < *t.data);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline array_ref<T const> make_array_ref(T const& t) {
|
||||
return array_ref<T const>(t);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline array_ref<T> make_array_ref(T& t) {
|
||||
return array_ref<T>(t);
|
||||
}
|
||||
|
||||
|
||||
} // namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T>
|
||||
struct convert<msgpack::type::array_ref<T> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, msgpack::type::array_ref<T>& v) const {
|
||||
if (!v.data) { throw msgpack::type_error(); }
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if (v.data->size() < o.via.bin.size) { throw msgpack::type_error(); }
|
||||
if (o.via.array.size > 0) {
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
typename T::iterator it = v.data->begin();
|
||||
do {
|
||||
p->convert(*it);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct convert<msgpack::type::array_ref<std::vector<T> > > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, msgpack::type::array_ref<std::vector<T> >& v) const {
|
||||
if (!v.data) { throw msgpack::type_error(); }
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
v.data->resize(o.via.bin.size);
|
||||
if (o.via.array.size > 0) {
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
typename std::vector<T>::iterator it = v.data->begin();
|
||||
do {
|
||||
p->convert(*it);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pack<msgpack::type::array_ref<T> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const msgpack::type::array_ref<T>& v) const {
|
||||
if (!v.data) { throw msgpack::type_error(); }
|
||||
uint32_t size = checked_get_container_size(v.data->size());
|
||||
o.pack_array(size);
|
||||
for (typename T::const_iterator it(v.data->begin()), it_end(v.data->end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object_with_zone<msgpack::type::array_ref<T> > {
|
||||
void operator()(msgpack::object::with_zone& o, const msgpack::type::array_ref<T>& v) const {
|
||||
if (!v.data) { throw msgpack::type_error(); }
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if (v.data->empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
}
|
||||
else {
|
||||
uint32_t size = checked_get_container_size(v.data->size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename T::const_iterator it(v.data->begin());
|
||||
do {
|
||||
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_TYPE_ARRAY_REF_HPP
|
41
include/msgpack/v1/adaptor/array_ref_decl.hpp
Normal file
41
include/msgpack/v1/adaptor/array_ref_decl.hpp
Normal file
@ -0,0 +1,41 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// 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_ARRAY_REF_DECL_HPP
|
||||
#define MSGPACK_V1_TYPE_ARRAY_REF_DECL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
template <typename T>
|
||||
struct array_ref;
|
||||
|
||||
template <typename T>
|
||||
array_ref<T const> make_array_ref(T const& t);
|
||||
|
||||
template <typename T>
|
||||
array_ref<T> make_array_ref(T& t);
|
||||
|
||||
} // namespace type
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_TYPE_ARRAY_REF_DECL_HPP
|
66
include/msgpack/v1/adaptor/bool.hpp
Normal file
66
include/msgpack/v1/adaptor/bool.hpp
Normal file
@ -0,0 +1,66 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2016 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_BOOL_HPP
|
||||
#define MSGPACK_V1_TYPE_BOOL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<bool> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, bool& v) const {
|
||||
if(o.type != msgpack::type::BOOLEAN) { throw msgpack::type_error(); }
|
||||
v = o.via.boolean;
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<bool> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const bool& v) const {
|
||||
if(v) { o.pack_true(); }
|
||||
else { o.pack_false(); }
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<bool> {
|
||||
void operator()(msgpack::object& o, bool v) const {
|
||||
o.type = msgpack::type::BOOLEAN;
|
||||
o.via.boolean = v;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<bool> {
|
||||
void operator()(msgpack::object::with_zone& o, bool v) const {
|
||||
static_cast<msgpack::object&>(o) << v;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_TYPE_BOOL_HPP
|
160
include/msgpack/v1/adaptor/boost/fusion.hpp
Normal file
160
include/msgpack/v1/adaptor/boost/fusion.hpp
Normal file
@ -0,0 +1,160 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015-2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_BOOST_FUSION_HPP
|
||||
#define MSGPACK_V1_TYPE_BOOST_FUSION_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/meta.hpp"
|
||||
|
||||
#if !defined (MSGPACK_USE_CPP03)
|
||||
#include "msgpack/adaptor/cpp11/tuple.hpp"
|
||||
#endif // #if !defined (MSGPACK_USE_CPP03)
|
||||
|
||||
#include <boost/fusion/support/is_sequence.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/size.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/for_each.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/at.hpp>
|
||||
#include <boost/fusion/include/mpl.hpp>
|
||||
#include <boost/mpl/size.hpp>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
#if !defined (MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T>
|
||||
struct as<
|
||||
T,
|
||||
typename msgpack::enable_if<
|
||||
boost::fusion::traits::is_sequence<T>::value &&
|
||||
boost::mpl::fold<
|
||||
T,
|
||||
boost::mpl::bool_<true>,
|
||||
boost::mpl::if_ <
|
||||
boost::mpl::and_<
|
||||
boost::mpl::_1,
|
||||
msgpack::has_as<boost::mpl::_2>
|
||||
>,
|
||||
boost::mpl::bool_<true>,
|
||||
boost::mpl::bool_<false>
|
||||
>
|
||||
>::type::value
|
||||
>::type
|
||||
> {
|
||||
T operator()(msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if (o.via.array.size != checked_get_container_size(boost::mpl::size<T>::value)) {
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
using tuple_t = decltype(to_tuple(std::declval<T>(), gen_seq<boost::mpl::size<T>::value>()));
|
||||
return to_t(
|
||||
o.as<tuple_t>(),
|
||||
msgpack::gen_seq<boost::mpl::size<T>::value>());
|
||||
}
|
||||
template<std::size_t... Is, typename U>
|
||||
static std::tuple<
|
||||
typename std::remove_reference<
|
||||
typename boost::fusion::result_of::at_c<T, Is>::type
|
||||
>::type...>
|
||||
to_tuple(U const& u, seq<Is...>) {
|
||||
return std::make_tuple(boost::fusion::at_c<Is>(u)...);
|
||||
}
|
||||
template<std::size_t... Is, typename U>
|
||||
static T to_t(U const& u, seq<Is...>) {
|
||||
return T(std::get<Is>(u)...);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined (MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T>
|
||||
struct convert<T, typename msgpack::enable_if<boost::fusion::traits::is_sequence<T>::value>::type > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, T& v) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if (o.via.array.size != checked_get_container_size(boost::fusion::size(v))) {
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
uint32_t index = 0;
|
||||
boost::fusion::for_each(v, convert_imp(o, index));
|
||||
return o;
|
||||
}
|
||||
private:
|
||||
struct convert_imp {
|
||||
convert_imp(msgpack::object const& obj, uint32_t& index):obj_(obj), index_(index) {}
|
||||
template <typename U>
|
||||
void operator()(U& v) const {
|
||||
msgpack::adaptor::convert<U>()(obj_.via.array.ptr[index_++], v);
|
||||
}
|
||||
private:
|
||||
msgpack::object const& obj_;
|
||||
uint32_t& index_;
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pack<T, typename msgpack::enable_if<boost::fusion::traits::is_sequence<T>::value>::type > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const T& v) const {
|
||||
uint32_t size = checked_get_container_size(boost::fusion::size(v));
|
||||
o.pack_array(size);
|
||||
boost::fusion::for_each(v, pack_imp<Stream>(o));
|
||||
return o;
|
||||
}
|
||||
private:
|
||||
template <typename Stream>
|
||||
struct pack_imp {
|
||||
pack_imp(msgpack::packer<Stream>& stream):stream_(stream) {}
|
||||
template <typename U>
|
||||
void operator()(U const& v) const {
|
||||
stream_.pack(v);
|
||||
}
|
||||
private:
|
||||
msgpack::packer<Stream>& stream_;
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object_with_zone<T, typename msgpack::enable_if<boost::fusion::traits::is_sequence<T>::value>::type > {
|
||||
void operator()(msgpack::object::with_zone& o, const T& v) const {
|
||||
uint32_t size = checked_get_container_size(boost::fusion::size(v));
|
||||
o.type = msgpack::type::ARRAY;
|
||||
o.via.array.ptr = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
o.via.array.size = size;
|
||||
uint32_t count = 0;
|
||||
boost::fusion::for_each(v, with_zone_imp(o, count));
|
||||
}
|
||||
private:
|
||||
struct with_zone_imp {
|
||||
with_zone_imp(msgpack::object::with_zone const& obj, uint32_t& count):obj_(obj), count_(count) {}
|
||||
template <typename U>
|
||||
void operator()(U const& v) const {
|
||||
obj_.via.array.ptr[count_++] = msgpack::object(v, obj_.zone);
|
||||
}
|
||||
msgpack::object::with_zone const& obj_;
|
||||
uint32_t& count_;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_TYPE_BOOST_FUSION_HPP
|
430
include/msgpack/v1/adaptor/boost/msgpack_variant.hpp
Normal file
430
include/msgpack/v1/adaptor/boost/msgpack_variant.hpp
Normal file
@ -0,0 +1,430 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015-2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_BOOST_MSGPACK_VARIANT_HPP
|
||||
#define MSGPACK_V1_TYPE_BOOST_MSGPACK_VARIANT_HPP
|
||||
|
||||
#if defined(MSGPACK_USE_BOOST)
|
||||
|
||||
#include "msgpack/v1/adaptor/boost/msgpack_variant_decl.hpp"
|
||||
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/adaptor/boost/string_ref.hpp"
|
||||
|
||||
#include "msgpack/adaptor/nil.hpp"
|
||||
#include "msgpack/adaptor/bool.hpp"
|
||||
#include "msgpack/adaptor/int.hpp"
|
||||
#include "msgpack/adaptor/float.hpp"
|
||||
#include "msgpack/adaptor/string.hpp"
|
||||
#include "msgpack/adaptor/vector_char.hpp"
|
||||
#include "msgpack/adaptor/raw.hpp"
|
||||
#include "msgpack/adaptor/ext.hpp"
|
||||
#include "msgpack/adaptor/vector.hpp"
|
||||
#include "msgpack/adaptor/map.hpp"
|
||||
|
||||
#include <boost/variant.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
struct basic_variant :
|
||||
boost::variant<
|
||||
nil_t, // NIL
|
||||
bool, // BOOL
|
||||
int64_t, // NEGATIVE_INTEGER
|
||||
uint64_t, // POSITIVE_INTEGER
|
||||
double, // FLOAT
|
||||
std::string, // STR
|
||||
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
boost::string_ref, // STR
|
||||
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
std::vector<char>, // BIN
|
||||
msgpack::type::raw_ref, // BIN
|
||||
msgpack::type::ext, // EXT
|
||||
msgpack::type::ext_ref, // EXT
|
||||
boost::recursive_wrapper<std::vector<basic_variant<STR, BIN, EXT> > >, // ARRAY
|
||||
boost::recursive_wrapper<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >, // MAP
|
||||
boost::recursive_wrapper<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >// MAP
|
||||
>,
|
||||
private boost::totally_ordered<basic_variant<STR, BIN, EXT> > {
|
||||
typedef boost::variant<
|
||||
nil_t, // NIL
|
||||
bool, // BOOL
|
||||
int64_t, // NEGATIVE_INTEGER
|
||||
uint64_t, // POSITIVE_INTEGER
|
||||
double, // FLOAT
|
||||
std::string, // STR
|
||||
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
boost::string_ref, // STR
|
||||
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
std::vector<char>, // BIN
|
||||
msgpack::type::raw_ref, // BIN
|
||||
msgpack::type::ext, // EXT
|
||||
msgpack::type::ext_ref, // EXT
|
||||
boost::recursive_wrapper<std::vector<basic_variant<STR, BIN, EXT> > >, // ARRAY
|
||||
boost::recursive_wrapper<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >, // MAP
|
||||
boost::recursive_wrapper<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >// MAP
|
||||
> base;
|
||||
basic_variant() {}
|
||||
template <typename T>
|
||||
basic_variant(T const& t):base(t) {}
|
||||
basic_variant(char const* p):base(std::string(p)) {}
|
||||
basic_variant(char v) {
|
||||
int_init(v);
|
||||
}
|
||||
basic_variant(signed char v) {
|
||||
int_init(v);
|
||||
}
|
||||
basic_variant(unsigned char v):base(uint64_t(v)) {}
|
||||
basic_variant(signed int v) {
|
||||
int_init(v);
|
||||
}
|
||||
basic_variant(unsigned int v):base(uint64_t(v)) {}
|
||||
basic_variant(signed long v) {
|
||||
int_init(v);
|
||||
}
|
||||
basic_variant(unsigned long v):base(uint64_t(v)) {}
|
||||
basic_variant(signed long long v) {
|
||||
int_init(v);
|
||||
}
|
||||
basic_variant(unsigned long long v):base(uint64_t(v)) {}
|
||||
|
||||
bool is_nil() const {
|
||||
return boost::get<msgpack::type::nil_t>(this);
|
||||
}
|
||||
bool is_bool() const {
|
||||
return boost::get<bool>(this);
|
||||
}
|
||||
bool is_int64_t() const {
|
||||
return boost::get<int64_t>(this);
|
||||
}
|
||||
bool is_uint64_t() const {
|
||||
return boost::get<uint64_t>(this);
|
||||
}
|
||||
bool is_double() const {
|
||||
return boost::get<double>(this);
|
||||
}
|
||||
bool is_string() const {
|
||||
return boost::get<std::string>(this);
|
||||
}
|
||||
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
bool is_boost_string_ref() const {
|
||||
return boost::get<boost::string_ref>(this);
|
||||
}
|
||||
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
bool is_vector_char() const {
|
||||
return boost::get<std::vector<char> >(this);
|
||||
}
|
||||
bool is_vector_char() {
|
||||
return boost::get<std::vector<char> >(this);
|
||||
}
|
||||
bool is_raw_ref() const {
|
||||
return boost::get<raw_ref>(this);
|
||||
}
|
||||
bool is_ext() const {
|
||||
return boost::get<ext>(this);
|
||||
}
|
||||
bool is_ext_ref() const {
|
||||
return boost::get<ext_ref>(this);
|
||||
}
|
||||
bool is_vector() const {
|
||||
return boost::get<std::vector<basic_variant<STR, BIN, EXT> > >(this);
|
||||
}
|
||||
bool is_map() const {
|
||||
return boost::get<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(this);
|
||||
}
|
||||
bool is_multimap() const {
|
||||
return boost::get<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(this);
|
||||
}
|
||||
|
||||
bool as_bool() const {
|
||||
return boost::get<bool>(*this);
|
||||
}
|
||||
int64_t as_int64_t() const {
|
||||
return boost::get<int64_t>(*this);
|
||||
}
|
||||
int64_t& as_int64_t() {
|
||||
return boost::get<int64_t>(*this);
|
||||
}
|
||||
uint64_t as_uint64_t() const {
|
||||
return boost::get<uint64_t>(*this);
|
||||
}
|
||||
uint64_t& as_uint64_t() {
|
||||
return boost::get<uint64_t>(*this);
|
||||
}
|
||||
double as_double() const {
|
||||
return boost::get<double>(*this);
|
||||
}
|
||||
double& as_double() {
|
||||
return boost::get<double>(*this);
|
||||
}
|
||||
std::string const& as_string() const {
|
||||
return boost::get<std::string>(*this);
|
||||
}
|
||||
std::string& as_string() {
|
||||
return boost::get<std::string>(*this);
|
||||
}
|
||||
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
boost::string_ref const& as_boost_string_ref() const {
|
||||
return boost::get<boost::string_ref>(*this);
|
||||
}
|
||||
boost::string_ref& as_boost_string_ref() {
|
||||
return boost::get<boost::string_ref>(*this);
|
||||
}
|
||||
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
std::vector<char> const& as_vector_char() const {
|
||||
return boost::get<std::vector<char> >(*this);
|
||||
}
|
||||
std::vector<char>& as_vector_char() {
|
||||
return boost::get<std::vector<char> >(*this);
|
||||
}
|
||||
raw_ref const& as_raw_ref() const {
|
||||
return boost::get<raw_ref>(*this);
|
||||
}
|
||||
ext const& as_ext() const {
|
||||
return boost::get<ext>(*this);
|
||||
}
|
||||
ext& as_ext() {
|
||||
return boost::get<ext>(*this);
|
||||
}
|
||||
ext_ref const& as_ext_ref() const {
|
||||
return boost::get<ext_ref>(*this);
|
||||
}
|
||||
std::vector<basic_variant<STR, BIN, EXT> > const& as_vector() const {
|
||||
return boost::get<std::vector<basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
std::vector<basic_variant<STR, BIN, EXT> >& as_vector() {
|
||||
return boost::get<std::vector<basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > const& as_map() const {
|
||||
return boost::get<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> >& as_map() {
|
||||
return boost::get<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > const& as_multimap() const {
|
||||
return boost::get<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> >& as_multimap() {
|
||||
return boost::get<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
private:
|
||||
template <typename T>
|
||||
void int_init(T v) {
|
||||
if (v < 0) {
|
||||
static_cast<base&>(*this) = int64_t(v);
|
||||
}
|
||||
else {
|
||||
static_cast<base&>(*this) = uint64_t(v);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
inline bool operator<(basic_variant<STR, BIN, EXT> const& lhs, basic_variant<STR, BIN, EXT> const& rhs) {
|
||||
return
|
||||
static_cast<typename basic_variant<STR, BIN, EXT>::base const&>(lhs) <
|
||||
static_cast<typename basic_variant<STR, BIN, EXT>::base const&>(rhs);
|
||||
}
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
inline bool operator==(basic_variant<STR, BIN, EXT> const& lhs, basic_variant<STR, BIN, EXT> const& rhs) {
|
||||
return
|
||||
static_cast<typename basic_variant<STR, BIN, EXT>::base const&>(lhs) ==
|
||||
static_cast<typename basic_variant<STR, BIN, EXT>::base const&>(rhs);
|
||||
}
|
||||
|
||||
typedef basic_variant<std::string, std::vector<char>, ext> variant;
|
||||
typedef basic_variant<
|
||||
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
boost::string_ref,
|
||||
#else // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
std::string,
|
||||
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
raw_ref, ext_ref> variant_ref;
|
||||
|
||||
} // namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
#if !defined (MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
struct as<type::basic_variant<STR, BIN, EXT> > {
|
||||
type::basic_variant<STR, BIN, EXT> operator()(msgpack::object const& o) const {
|
||||
switch(o.type) {
|
||||
case type::NIL:
|
||||
return o.as<msgpack::type::nil_t>();
|
||||
case type::BOOLEAN:
|
||||
return o.as<bool>();
|
||||
case type::POSITIVE_INTEGER:
|
||||
return o.as<uint64_t>();
|
||||
case type::NEGATIVE_INTEGER:
|
||||
return o.as<int64_t>();
|
||||
case type::FLOAT:
|
||||
return o.as<double>();
|
||||
case type::STR:
|
||||
return o.as<STR>();
|
||||
case type::BIN:
|
||||
return o.as<BIN>();
|
||||
case type::EXT:
|
||||
return o.as<EXT>();
|
||||
case type::ARRAY:
|
||||
return o.as<std::vector<type::basic_variant<STR, BIN, EXT> > >();
|
||||
case type::MAP:
|
||||
return o.as<std::multimap<type::basic_variant<STR, BIN, EXT>, type::basic_variant<STR, BIN, EXT> > >();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return type::basic_variant<STR, BIN, EXT>();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined (MSGPACK_USE_CPP03)
|
||||
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
struct convert<type::basic_variant<STR, BIN, EXT> > {
|
||||
msgpack::object const& operator()(
|
||||
msgpack::object const& o,
|
||||
type::basic_variant<STR, BIN, EXT>& v) const {
|
||||
switch(o.type) {
|
||||
case type::NIL:
|
||||
v = o.as<msgpack::type::nil_t>();
|
||||
break;
|
||||
case type::BOOLEAN:
|
||||
v = o.as<bool>();
|
||||
break;
|
||||
case type::POSITIVE_INTEGER:
|
||||
v = o.as<uint64_t>();
|
||||
break;
|
||||
case type::NEGATIVE_INTEGER:
|
||||
v = o.as<int64_t>();
|
||||
break;
|
||||
case type::FLOAT:
|
||||
v = o.as<double>();
|
||||
break;
|
||||
case type::STR:
|
||||
v = o.as<STR>();
|
||||
break;
|
||||
case type::BIN:
|
||||
v = o.as<BIN>();
|
||||
break;
|
||||
case type::EXT:
|
||||
v = o.as<EXT>();
|
||||
break;
|
||||
case type::ARRAY:
|
||||
v = o.as<std::vector<type::basic_variant<STR, BIN, EXT> > >();
|
||||
break;
|
||||
case type::MAP:
|
||||
v = o.as<std::multimap<type::basic_variant<STR, BIN, EXT>, type::basic_variant<STR, BIN, EXT> > >();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename Stream>
|
||||
struct pack_imp : boost::static_visitor<void> {
|
||||
template <typename T>
|
||||
void operator()(T const& value) const {
|
||||
pack<T>()(o_, value);
|
||||
}
|
||||
pack_imp(packer<Stream>& o):o_(o) {}
|
||||
packer<Stream>& o_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
struct pack<type::basic_variant<STR, BIN, EXT> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::basic_variant<STR, BIN, EXT>& v) const {
|
||||
boost::apply_visitor(detail::pack_imp<Stream>(o), v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct object_imp : boost::static_visitor<void> {
|
||||
void operator()(msgpack::type::nil_t const& v) const {
|
||||
object<msgpack::type::nil_t>()(o_, v);
|
||||
}
|
||||
void operator()(bool const& v) const {
|
||||
object<bool>()(o_, v);
|
||||
}
|
||||
void operator()(uint64_t const& v) const {
|
||||
object<uint64_t>()(o_, v);
|
||||
}
|
||||
void operator()(int64_t const& v) const {
|
||||
object<int64_t>()(o_, v);
|
||||
}
|
||||
void operator()(double const& v) const {
|
||||
object<double>()(o_, v);
|
||||
}
|
||||
template <typename T>
|
||||
void operator()(T const&) const {
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
object_imp(msgpack::object& o):o_(o) {}
|
||||
msgpack::object& o_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
struct object<type::basic_variant<STR, BIN, EXT> > {
|
||||
void operator()(msgpack::object& o, const type::basic_variant<STR, BIN, EXT>& v) const {
|
||||
boost::apply_visitor(detail::object_imp(o), v);
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct object_with_zone_imp : boost::static_visitor<void> {
|
||||
template <typename T>
|
||||
void operator()(T const& v) const {
|
||||
object_with_zone<T>()(o_, v);
|
||||
}
|
||||
object_with_zone_imp(msgpack::object::with_zone& o):o_(o) {}
|
||||
msgpack::object::with_zone& o_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
struct object_with_zone<type::basic_variant<STR, BIN, EXT> > {
|
||||
void operator()(msgpack::object::with_zone& o, const type::basic_variant<STR, BIN, EXT>& v) const {
|
||||
boost::apply_visitor(detail::object_with_zone_imp(o), v);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_USE_BOOST
|
||||
#endif // MSGPACK_V1_TYPE_BOOST_MSGPACK_VARIANT_HPP
|
62
include/msgpack/v1/adaptor/boost/msgpack_variant_decl.hpp
Normal file
62
include/msgpack/v1/adaptor/boost/msgpack_variant_decl.hpp
Normal file
@ -0,0 +1,62 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015-2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_BOOST_MSGPACK_VARIANT_DECL_HPP
|
||||
#define MSGPACK_V1_TYPE_BOOST_MSGPACK_VARIANT_DECL_HPP
|
||||
|
||||
#if defined(MSGPACK_USE_BOOST)
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/adaptor/boost/string_ref.hpp"
|
||||
#include "msgpack/adaptor/ext.hpp"
|
||||
#include "msgpack/adaptor/raw.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
struct basic_variant;
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
bool operator<(basic_variant<STR, BIN, EXT> const& lhs, basic_variant<STR, BIN, EXT> const& rhs);
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
bool operator==(basic_variant<STR, BIN, EXT> const& lhs, basic_variant<STR, BIN, EXT> const& rhs);
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
bool operator!=(basic_variant<STR, BIN, EXT> const& lhs, basic_variant<STR, BIN, EXT> const& rhs);
|
||||
|
||||
typedef basic_variant<std::string, std::vector<char>, msgpack::type::ext> variant;
|
||||
typedef basic_variant<
|
||||
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
boost::string_ref,
|
||||
#else // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
std::string,
|
||||
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
msgpack::type::raw_ref, msgpack::type::ext_ref> variant_ref;
|
||||
|
||||
} // namespace type
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_USE_BOOST
|
||||
#endif // MSGPACK_V1_TYPE_BOOST_MSGPACK_VARIANT_DECL_HPP
|
96
include/msgpack/v1/adaptor/boost/optional.hpp
Normal file
96
include/msgpack/v1/adaptor/boost/optional.hpp
Normal file
@ -0,0 +1,96 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
//
|
||||
// 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_BOOST_OPTIONAL_HPP
|
||||
#define MSGPACK_V1_TYPE_BOOST_OPTIONAL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
// To suppress warning on Boost.1.58.0
|
||||
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
#if !defined (MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T>
|
||||
struct as<boost::optional<T>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||
boost::optional<T> operator()(msgpack::object const& o) const {
|
||||
if(o.is_nil()) return boost::none;
|
||||
return o.as<T>();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined (MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename T>
|
||||
struct convert<boost::optional<T> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, boost::optional<T>& v) const {
|
||||
if(o.is_nil()) v = boost::none;
|
||||
else {
|
||||
T t;
|
||||
msgpack::adaptor::convert<T>()(o, t);
|
||||
v = t;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pack<boost::optional<T> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const boost::optional<T>& v) const {
|
||||
if (v) o.pack(*v);
|
||||
else o.pack_nil();
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object<boost::optional<T> > {
|
||||
void operator()(msgpack::object& o, const boost::optional<T>& v) const {
|
||||
if (v) msgpack::adaptor::object<T>()(o, *v);
|
||||
else o.type = msgpack::type::NIL;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object_with_zone<boost::optional<T> > {
|
||||
void operator()(msgpack::object::with_zone& o, const boost::optional<T>& v) const {
|
||||
if (v) msgpack::adaptor::object_with_zone<T>()(o, *v);
|
||||
else o.type = msgpack::type::NIL;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_TYPE_BOOST_OPTIONAL_HPP
|
87
include/msgpack/v1/adaptor/boost/string_ref.hpp
Normal file
87
include/msgpack/v1/adaptor/boost/string_ref.hpp
Normal file
@ -0,0 +1,87 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
//
|
||||
// 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_BOOST_STRING_REF_HPP
|
||||
#define MSGPACK_V1_TYPE_BOOST_STRING_REF_HPP
|
||||
|
||||
#include <boost/version.hpp>
|
||||
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<boost::string_ref> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, boost::string_ref& v) const {
|
||||
switch (o.type) {
|
||||
case msgpack::type::BIN:
|
||||
v = boost::string_ref(o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case msgpack::type::STR:
|
||||
v = boost::string_ref(o.via.str.ptr, o.via.str.size);
|
||||
break;
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<boost::string_ref> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const boost::string_ref& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_str(size);
|
||||
o.pack_str_body(v.data(), size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<boost::string_ref> {
|
||||
void operator()(msgpack::object& o, const boost::string_ref& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::STR;
|
||||
o.via.str.ptr = v.data();
|
||||
o.via.str.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<boost::string_ref> {
|
||||
void operator()(msgpack::object::with_zone& o, const boost::string_ref& v) const {
|
||||
static_cast<msgpack::object&>(o) << v;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
|
||||
#endif // MSGPACK_V1_TYPE_BOOST_STRING_REF_HPP
|
158
include/msgpack/v1/adaptor/char_ptr.hpp
Normal file
158
include/msgpack/v1/adaptor/char_ptr.hpp
Normal file
@ -0,0 +1,158 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
//
|
||||
// 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_CHAR_PTR_HPP
|
||||
#define MSGPACK_V1_TYPE_CHAR_PTR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct pack<const char*> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.pack_str(size);
|
||||
o.pack_str_body(v, size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<const char*> {
|
||||
void operator()(msgpack::object::with_zone& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.type = msgpack::type::STR;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.str.ptr = ptr;
|
||||
o.via.str.size = size;
|
||||
std::memcpy(ptr, v, size);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<const char*> {
|
||||
void operator()(msgpack::object& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.type = msgpack::type::STR;
|
||||
o.via.str.ptr = v;
|
||||
o.via.str.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct pack<char*> {
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator()(packer<Stream>& o, char* v) const {
|
||||
return o << static_cast<const char*>(v);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<char*> {
|
||||
void operator()(msgpack::object::with_zone& o, char* v) const {
|
||||
o << static_cast<const char*>(v);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<char*> {
|
||||
void operator()(msgpack::object& o, char* v) const {
|
||||
o << static_cast<const char*>(v);
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct pack<char[N]> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.pack_str(size);
|
||||
o.pack_str_body(v, size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object_with_zone<char[N]> {
|
||||
void operator()(msgpack::object::with_zone& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.type = msgpack::type::STR;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.str.ptr = ptr;
|
||||
o.via.str.size = size;
|
||||
std::memcpy(ptr, v, size);
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object<char[N]> {
|
||||
void operator()(msgpack::object& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.type = msgpack::type::STR;
|
||||
o.via.str.ptr = v;
|
||||
o.via.str.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct pack<const char[N]> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.pack_str(size);
|
||||
o.pack_str_body(v, size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object_with_zone<const char[N]> {
|
||||
void operator()(msgpack::object::with_zone& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.type = msgpack::type::STR;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.str.ptr = ptr;
|
||||
o.via.str.size = size;
|
||||
std::memcpy(ptr, v, size);
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object<const char[N]> {
|
||||
void operator()(msgpack::object& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.type = msgpack::type::STR;
|
||||
o.via.str.ptr = v;
|
||||
o.via.str.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_TYPE_CHAR_PTR_HPP
|
67
include/msgpack/v1/adaptor/check_container_size.hpp
Normal file
67
include/msgpack/v1/adaptor/check_container_size.hpp
Normal file
@ -0,0 +1,67 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
//
|
||||
// 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_CHECK_CONTAINER_SIZE_HPP
|
||||
#define MSGPACK_V1_CHECK_CONTAINER_SIZE_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/check_container_size_decl.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
struct container_size_overflow : public std::runtime_error {
|
||||
explicit container_size_overflow(const std::string& msg)
|
||||
:std::runtime_error(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
explicit container_size_overflow(const char* msg):
|
||||
std::runtime_error(msg) {}
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <std::size_t N>
|
||||
inline void check_container_size(std::size_t size) {
|
||||
if (size > 0xffffffff) throw container_size_overflow("container size overflow");
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void check_container_size<4>(std::size_t /*size*/) {
|
||||
}
|
||||
|
||||
template <std::size_t N>
|
||||
inline void check_container_size_for_ext(std::size_t size) {
|
||||
if (size > 0xffffffff) throw container_size_overflow("container size overflow");
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void check_container_size_for_ext<4>(std::size_t size) {
|
||||
if (size > 0xfffffffe) throw container_size_overflow("container size overflow");
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename T>
|
||||
inline uint32_t checked_get_container_size(T size) {
|
||||
detail::check_container_size<sizeof(T)>(size);
|
||||
return static_cast<uint32_t>(size);
|
||||
}
|
||||
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_CHECK_CONTAINER_SIZE_HPP
|
44
include/msgpack/v1/adaptor/check_container_size_decl.hpp
Normal file
44
include/msgpack/v1/adaptor/check_container_size_decl.hpp
Normal file
@ -0,0 +1,44 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015-2016 KONDO Takatoshi
|
||||
//
|
||||
// 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_CHECK_CONTAINER_SIZE_DECL_HPP
|
||||
#define MSGPACK_V1_CHECK_CONTAINER_SIZE_DECL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
struct container_size_overflow;
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <std::size_t N>
|
||||
inline void check_container_size(std::size_t size);
|
||||
|
||||
template <std::size_t N>
|
||||
inline void check_container_size_for_ext(std::size_t size);
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename T>
|
||||
inline uint32_t checked_get_container_size(T size);
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_CHECK_CONTAINER_SIZE_DECL_HPP
|
138
include/msgpack/v1/adaptor/cpp11/array.hpp
Normal file
138
include/msgpack/v1/adaptor/cpp11/array.hpp
Normal file
@ -0,0 +1,138 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP11_ARRAY_HPP
|
||||
#define MSGPACK_V1_TYPE_CPP11_ARRAY_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/meta.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
namespace detail {
|
||||
|
||||
namespace array {
|
||||
|
||||
template<typename T, std::size_t N1, std::size_t... I1, std::size_t N2, std::size_t... I2>
|
||||
inline std::array<T, N1+N2> concat(
|
||||
std::array<T, N1>&& a1,
|
||||
std::array<T, N2>&& a2,
|
||||
msgpack::seq<I1...>,
|
||||
msgpack::seq<I2...>) {
|
||||
return {{ std::move(a1[I1])..., std::move(a2[I2])... }};
|
||||
}
|
||||
|
||||
template<typename T, std::size_t N1, std::size_t N2>
|
||||
inline std::array<T, N1+N2> concat(std::array<T, N1>&& a1, std::array<T, N2>&& a2) {
|
||||
return concat(std::move(a1), std::move(a2), msgpack::gen_seq<N1>(), msgpack::gen_seq<N2>());
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
struct as_impl {
|
||||
static std::array<T, N> as(msgpack::object const& o) {
|
||||
msgpack::object* p = o.via.array.ptr + N - 1;
|
||||
return concat(as_impl<T, N-1>::as(o), std::array<T, 1>{{p->as<T>()}});
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct as_impl<T, 1> {
|
||||
static std::array<T, 1> as(msgpack::object const& o) {
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
return std::array<T, 1>{{p->as<T>()}};
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct as_impl<T, 0> {
|
||||
static std::array<T, 0> as(msgpack::object const&) {
|
||||
return std::array<T, 0>();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace array
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
struct as<std::array<T, N>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||
std::array<T, N> operator()(msgpack::object const& o) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size != N) { throw msgpack::type_error(); }
|
||||
return detail::array::as_impl<T, N>::as(o);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
struct convert<std::array<T, N>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::array<T, N>& v) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size != N) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size > 0) {
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
T* it = &v[0];
|
||||
do {
|
||||
p->convert(*it);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
struct pack<std::array<T, N>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::array<T, N>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(auto const& e : v) o.pack(e);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
struct object_with_zone<std::array<T, N>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::array<T, N>& v) const {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
o.via.array.size = size;
|
||||
o.via.array.ptr = p;
|
||||
for (auto const& e : v) *p++ = msgpack::object(e, o.zone);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_TYPE_CPP11_ARRAY_HPP
|
90
include/msgpack/v1/adaptor/cpp11/array_char.hpp
Normal file
90
include/msgpack/v1/adaptor/cpp11/array_char.hpp
Normal file
@ -0,0 +1,90 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP11_ARRAY_CHAR_HPP
|
||||
#define MSGPACK_V1_TYPE_CPP11_ARRAY_CHAR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <std::size_t N>
|
||||
struct convert<std::array<char, N>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::array<char, N>& v) const {
|
||||
switch (o.type) {
|
||||
case msgpack::type::BIN:
|
||||
if(o.via.bin.size != N) { throw msgpack::type_error(); }
|
||||
std::memcpy(v.data(), o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case msgpack::type::STR:
|
||||
if(o.via.str.size != N) { throw msgpack::type_error(); }
|
||||
std::memcpy(v.data(), o.via.str.ptr, N);
|
||||
break;
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct pack<std::array<char, N>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::array<char, N>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_bin(size);
|
||||
o.pack_bin_body(v.data(), size);
|
||||
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object<std::array<char, N>> {
|
||||
void operator()(msgpack::object& o, const std::array<char, N>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
o.via.bin.ptr = v.data();
|
||||
o.via.bin.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object_with_zone<std::array<char, N>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::array<char, N>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.bin.ptr = ptr;
|
||||
o.via.bin.size = size;
|
||||
std::memcpy(ptr, v.data(), size);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_TYPE_CPP11_ARRAY_CHAR_HPP
|
90
include/msgpack/v1/adaptor/cpp11/array_unsigned_char.hpp
Normal file
90
include/msgpack/v1/adaptor/cpp11/array_unsigned_char.hpp
Normal file
@ -0,0 +1,90 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP11_ARRAY_UNSIGNED_CHAR_HPP
|
||||
#define MSGPACK_V1_TYPE_CPP11_ARRAY_UNSIGNED_CHAR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <std::size_t N>
|
||||
struct convert<std::array<unsigned char, N>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::array<unsigned char, N>& v) const {
|
||||
switch (o.type) {
|
||||
case msgpack::type::BIN:
|
||||
if(o.via.bin.size != N) { throw msgpack::type_error(); }
|
||||
std::memcpy(v.data(), o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case msgpack::type::STR:
|
||||
if(o.via.str.size != N) { throw msgpack::type_error(); }
|
||||
std::memcpy(v.data(), o.via.str.ptr, N);
|
||||
break;
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct pack<std::array<unsigned char, N>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::array<unsigned char, N>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_bin(size);
|
||||
o.pack_bin_body(reinterpret_cast<char const*>(v.data()), size);
|
||||
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object<std::array<unsigned char, N>> {
|
||||
void operator()(msgpack::object& o, const std::array<unsigned char, N>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
o.via.bin.ptr = reinterpret_cast<char const*>(v.data());
|
||||
o.via.bin.size = size;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object_with_zone<std::array<unsigned char, N>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::array<unsigned char, N>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.bin.ptr = ptr;
|
||||
o.via.bin.size = size;
|
||||
std::memcpy(ptr, v.data(), size);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_TYPE_CPP11_ARRAY_UNSIGNED_CHAR_HPP
|
94
include/msgpack/v1/adaptor/cpp11/forward_list.hpp
Normal file
94
include/msgpack/v1/adaptor/cpp11/forward_list.hpp
Normal file
@ -0,0 +1,94 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO-2015 Takatoshi
|
||||
//
|
||||
// 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_CPP11_FORWARD_LIST_HPP
|
||||
#define MSGPACK_V1_TYPE_CPP11_FORWARD_LIST_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <forward_list>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct as<std::forward_list<T, Alloc>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||
std::forward_list<T, Alloc> operator()(msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
std::forward_list<T, Alloc> v;
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pend = o.via.array.ptr;
|
||||
while (p != pend) {
|
||||
--p;
|
||||
v.push_front(p->as<T>());
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct convert<std::forward_list<T, Alloc>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::forward_list<T, Alloc>& v) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
v.resize(o.via.array.size);
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
for (auto &e : v) {
|
||||
p->convert(e);
|
||||
++p;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct pack<std::forward_list<T, Alloc>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::forward_list<T, Alloc>& v) const {
|
||||
uint32_t size = checked_get_container_size(std::distance(v.begin(), v.end()));
|
||||
o.pack_array(size);
|
||||
for(auto const& e : v) o.pack(e);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Alloc>
|
||||
struct object_with_zone<std::forward_list<T, Alloc>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::forward_list<T, Alloc>& v) const {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(std::distance(v.begin(), v.end()));
|
||||
o.via.array.size = size;
|
||||
msgpack::object* p = static_cast<msgpack::object*>(
|
||||
o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
o.via.array.ptr = p;
|
||||
for(auto const& e : v) *p++ = msgpack::object(e, o.zone);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_TYPE_CPP11_FORWARD_LIST_HPP
|
68
include/msgpack/v1/adaptor/cpp11/reference_wrapper.hpp
Normal file
68
include/msgpack/v1/adaptor/cpp11/reference_wrapper.hpp
Normal file
@ -0,0 +1,68 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP11_REFERENCE_WRAPPER_HPP
|
||||
#define MSGPACK_V1_TYPE_CPP11_REFERENCE_WRAPPER_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T>
|
||||
struct convert<std::reference_wrapper<T>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::reference_wrapper<T>& v) const {
|
||||
msgpack::adaptor::convert<T>()(o, v.get());
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pack<std::reference_wrapper<T>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::reference_wrapper<T>& v) const {
|
||||
o.pack(v.get());
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object<std::reference_wrapper<T> > {
|
||||
void operator()(msgpack::object& o, const std::reference_wrapper<T>& v) const {
|
||||
msgpack::adaptor::object<typename std::remove_const<T>::type>()(o, v.get());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object_with_zone<std::reference_wrapper<T>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::reference_wrapper<T>& v) const {
|
||||
msgpack::adaptor::object_with_zone<typename std::remove_const<T>::type>()(o, v.get());
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_TYPE_CPP11_REFERENCE_WRAPPER_HPP
|
82
include/msgpack/v1/adaptor/cpp11/shared_ptr.hpp
Normal file
82
include/msgpack/v1/adaptor/cpp11/shared_ptr.hpp
Normal file
@ -0,0 +1,82 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
//
|
||||
// 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_CPP11_SHARED_PTR_HPP
|
||||
#define MSGPACK_V1_TYPE_CPP11_SHARED_PTR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T>
|
||||
struct as<std::shared_ptr<T>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||
std::shared_ptr<T> operator()(msgpack::object const& o) const {
|
||||
if(o.is_nil()) return nullptr;
|
||||
return std::make_shared<T>(o.as<T>());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct convert<std::shared_ptr<T>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::shared_ptr<T>& v) const {
|
||||
if(o.is_nil()) v.reset();
|
||||
else {
|
||||
v = std::make_shared<T>();
|
||||
msgpack::adaptor::convert<T>()(o, *v);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pack<std::shared_ptr<T>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::shared_ptr<T>& v) const {
|
||||
if (v) o.pack(*v);
|
||||
else o.pack_nil();
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object<std::shared_ptr<T> > {
|
||||
void operator()(msgpack::object& o, const std::shared_ptr<T>& v) const {
|
||||
if (v) msgpack::adaptor::object<T>()(o, *v);
|
||||
else o.type = msgpack::type::NIL;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object_with_zone<std::shared_ptr<T>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::shared_ptr<T>& v) const {
|
||||
if (v) msgpack::adaptor::object_with_zone<T>()(o, *v);
|
||||
else o.type = msgpack::type::NIL;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_TYPE_CPP11_SHARED_PTR_HPP
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user