diff --git a/.travis.yml b/.travis.yml index 64b4f57f..314ca904 100644 --- a/.travis.yml +++ b/.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} diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a9b2414..e1aeec6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}") diff --git a/ci/build_autotools.sh b/ci/build_autotools.sh index 39e5e351..b504ba38 100755 --- a/ci/build_autotools.sh +++ b/ci/build_autotools.sh @@ -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 ] diff --git a/ci/build_cmake.sh b/ci/build_cmake.sh index ea108c88..fecaebd6 100755 --- a/ci/build_cmake.sh +++ b/ci/build_cmake.sh @@ -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 ] diff --git a/erb/cpp03_define_array.hpp.erb b/erb/v1/cpp03_define_array.hpp.erb similarity index 58% rename from erb/cpp03_define_array.hpp.erb rename to erb/v1/cpp03_define_array.hpp.erb index 278413e3..8ecca2fc 100644 --- a/erb/cpp03_define_array.hpp.erb +++ b/erb/v1/cpp03_define_array.hpp.erb @@ -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 \ - 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 \ - 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(static_cast(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 { \ - msgpack::object const& operator()(msgpack::object const& o, enum_name& v) const {\ - int tmp; \ - o >> tmp; \ - v = static_cast(tmp); \ - return o; \ - } \ - }; \ - template<> \ - struct object { \ - void operator()(msgpack::object& o, const enum_name& v) const {\ - o << static_cast(v); \ - } \ - }; \ - template<> \ - struct object_with_zone { \ - void operator()(msgpack::object::with_zone& o, const enum_name& v) const { \ - o << static_cast(v); \ - } \ - }; \ - template<> \ - struct pack { \ - template \ - msgpack::packer& operator()(msgpack::packer& o, const enum_name& v) const { \ - return o << static_cast(v); \ - } \ - }; \ - } \ - /** @cond */ \ - } \ - /** @endcond */ \ - } - namespace msgpack { /// @cond MSGPACK_API_VERSION_NAMESPACE(v1) { /// @endcond namespace type { -/// @cond <% GENERATION_LIMIT = 31 %> -template , typename A<%=i%> = void<%}%>> -struct define_array; -/// @endcond - template <> struct define_array<> { typedef define_array<> value_type; @@ -169,5 +105,4 @@ inline define_array, A<%=j%><%}%>> make_define_array(A0& a0 /// @endcond } // namespace msgpack - -#endif // MSGPACK_CPP03_DEFINE_ARRAY_HPP +#endif // MSGPACK_V1_CPP03_DEFINE_ARRAY_HPP diff --git a/erb/v1/cpp03_define_array_decl.hpp.erb b/erb/v1/cpp03_define_array_decl.hpp.erb new file mode 100644 index 00000000..a2681ed1 --- /dev/null +++ b/erb/v1/cpp03_define_array_decl.hpp.erb @@ -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 A<%=i%> = void<%}%>> +struct define_array; +/// @endcond + +define_array<> make_define_array(); + +/// @cond +<%0.upto(GENERATION_LIMIT) {|i|%> +template , typename A<%=j%><%}%>> +inline define_array, 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 diff --git a/erb/cpp03_define_map.hpp.erb b/erb/v1/cpp03_define_map.hpp.erb similarity index 62% rename from erb/cpp03_define_map.hpp.erb rename to erb/v1/cpp03_define_map.hpp.erb index 8a88388c..b00c028a 100644 --- a/erb/cpp03_define_map.hpp.erb +++ b/erb/v1/cpp03_define_map.hpp.erb @@ -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 - -#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 \ - 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 \ - 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(static_cast(this))) - namespace msgpack { /// @cond MSGPACK_API_VERSION_NAMESPACE(v1) { /// @endcond namespace type { -/// @cond <% GENERATION_LIMIT = 31 %> -template , typename A<%=i%> = void<%}%>> -struct define_map; -/// @endcond - template <> struct define_map<> { template @@ -170,4 +114,4 @@ inline define_map, A<%=j%><%}%>> make_define_map(A0& a0<%1. /// @endcond } // namespace msgpack -#endif // MSGPACK_CPP03_DEFINE_MAP_HPP +#endif // MSGPACK_V1_CPP03_DEFINE_MAP_HPP diff --git a/erb/v1/cpp03_define_map_decl.hpp.erb b/erb/v1/cpp03_define_map_decl.hpp.erb new file mode 100644 index 00000000..f095456e --- /dev/null +++ b/erb/v1/cpp03_define_map_decl.hpp.erb @@ -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 A<%=i%> = void<%}%>> +struct define_map; +/// @endcond + +define_map<> make_define_map(); + +/// @cond +<%0.upto(GENERATION_LIMIT) {|i|%> +template , typename A<%=j%><%}%>> +define_map, 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 diff --git a/erb/cpp03_msgpack_tuple.hpp.erb b/erb/v1/cpp03_msgpack_tuple.hpp.erb similarity index 92% rename from erb/cpp03_msgpack_tuple.hpp.erb rename to erb/v1/cpp03_msgpack_tuple.hpp.erb index 41729f64..fbe716ba 100644 --- a/erb/cpp03_msgpack_tuple.hpp.erb +++ b/erb/v1/cpp03_msgpack_tuple.hpp.erb @@ -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 A<%=i%> = void<%}%>> -struct tuple; -/// @endcond - -template -struct tuple_element; - -template -struct const_tuple_element; - template struct tuple_type { typedef T type; @@ -235,4 +222,4 @@ struct object_with_zone, A<%=j%><%}%>> > { } // namespace msgpack -#endif // MSGPACK_CPP03_MSGPACK_TUPLE_HPP +#endif // MSGPACK_V1_CPP03_MSGPACK_TUPLE_HPP diff --git a/erb/v1/cpp03_msgpack_tuple_decl.hpp.erb b/erb/v1/cpp03_msgpack_tuple_decl.hpp.erb new file mode 100644 index 00000000..ab587472 --- /dev/null +++ b/erb/v1/cpp03_msgpack_tuple_decl.hpp.erb @@ -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 A<%=i%> = void<%}%>> +struct tuple; +/// @endcond + +template +struct tuple_element; + +template +struct const_tuple_element; + +template +struct tuple_type; + +/// @cond +<%0.upto(GENERATION_LIMIT) {|i|%> +template , typename A<%=j%><%}%>> +typename type::tuple_element, A<%=j%><%}%>>, N>::reference get(type::tuple, A<%=j%><%}%>>& t); +template , typename A<%=j%><%}%>> +typename type::const_tuple_element, A<%=j%><%}%>>, N>::const_reference get(type::tuple, A<%=j%><%}%>> const& t); +<%}%> +/// @endcond + +tuple<> make_tuple(); + +/// @cond +<%0.upto(GENERATION_LIMIT) {|i|%> +template , typename A<%=j%><%}%>> +tuple, A<%=j%><%}%>> make_tuple(typename tuple_type::transparent_reference a0<%1.upto(i) {|j|%>, typename tuple_type>::transparent_reference a<%=j%><%}%>); +<%}%> +/// @endcond + +} // namespace type + +/// @cond +} // MSGPACK_API_VERSION_NAMESPACE(v1) +/// @endcond + +} // namespace msgpack + +#endif // MSGPACK_V1_CPP03_MSGPACK_TUPLE_DECL_HPP diff --git a/erb/cpp03_zone.hpp.erb b/erb/v1/cpp03_zone.hpp.erb similarity index 94% rename from erb/cpp03_zone.hpp.erb rename to erb/v1/cpp03_zone.hpp.erb index e62eabb3..88fe00d8 100644 --- a/erb/cpp03_zone.hpp.erb +++ b/erb/v1/cpp03_zone.hpp.erb @@ -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 -#include -#include - -#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 diff --git a/erb/v1/cpp03_zone_decl.hpp.erb b/erb/v1/cpp03_zone_decl.hpp.erb new file mode 100644 index 00000000..ce969366 --- /dev/null +++ b/erb/v1/cpp03_zone_decl.hpp.erb @@ -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 +#include +#include + +#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 diff --git a/include/msgpack/adaptor/adaptor_base.hpp b/include/msgpack/adaptor/adaptor_base.hpp index 1be4798e..88257ed5 100644 --- a/include/msgpack/adaptor/adaptor_base.hpp +++ b/include/msgpack/adaptor/adaptor_base.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 -class packer; - -namespace adaptor { - -// Adaptor functors - -template -struct convert { - msgpack::object const& operator()(msgpack::object const& o, T& v) const; -}; - -template -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, T const& v) const; -}; - -template -struct object { - void operator()(msgpack::object& o, T const& v) const; -}; - -template -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, T const& v) const; -}; - -} // namespace adaptor - -// operators - -template -inline -msgpack::object const& operator>> (msgpack::object const& o, T& v) { - return adaptor::convert()(o, v); -} - -template -inline -msgpack::packer& operator<< (msgpack::packer& o, T const& v) { - return adaptor::pack()(o, v); -} - -template -inline -void operator<< (msgpack::object& o, T const& v) { - adaptor::object()(o, v); -} - -template -inline -void operator<< (msgpack::object::with_zone& o, T const& v) { - adaptor::object_with_zone()(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 diff --git a/include/msgpack/adaptor/adaptor_base_decl.hpp b/include/msgpack/adaptor/adaptor_base_decl.hpp new file mode 100644 index 00000000..b1526ca5 --- /dev/null +++ b/include/msgpack/adaptor/adaptor_base_decl.hpp @@ -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 diff --git a/include/msgpack/adaptor/array_ref.hpp b/include/msgpack/adaptor/array_ref.hpp index da1c42ac..2a3f61fb 100644 --- a/include/msgpack/adaptor/array_ref.hpp +++ b/include/msgpack/adaptor/array_ref.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 -#include +#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 -struct array_ref { - array_ref() : data(nullptr) {} - array_ref(T& t) : data(&t) {} - - T* data; - - template - bool operator==(array_ref const& t) const { - return *data == *t.data; - } - template - bool operator!=(array_ref const& t) const { - return !(*data == *t.data); - } - template - bool operator< (array_ref const& t) const - { - return *data < *t.data; - } - template - bool operator> (array_ref const& t) const - { - return *t.data < *data; - } - template - bool operator<= (array_ref const& t) const - { - return !(*t.data < *data); - } - template - bool operator>= (array_ref const& t) const - { - return !(*data < *t.data); - } -}; - -template -inline array_ref make_array_ref(T const& t) { - return array_ref(t); -} - -template -inline array_ref make_array_ref(T& t) { - return array_ref(t); -} - - -} // namespace type - -namespace adaptor { - -template -struct convert > { - msgpack::object const& operator()(msgpack::object const& o, msgpack::type::array_ref& 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 -struct convert > > { - msgpack::object const& operator()(msgpack::object const& o, msgpack::type::array_ref >& 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::iterator it = v.data->begin(); - do { - p->convert(*it); - ++p; - ++it; - } while(p < pend); - } - return o; - } -}; - -template -struct pack > { - template - msgpack::packer& operator()(msgpack::packer& o, const msgpack::type::array_ref& 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 -struct object_with_zone > { - void operator()(msgpack::object::with_zone& o, const msgpack::type::array_ref& 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(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 diff --git a/include/msgpack/adaptor/array_ref_decl.hpp b/include/msgpack/adaptor/array_ref_decl.hpp new file mode 100644 index 00000000..2cb1ace7 --- /dev/null +++ b/include/msgpack/adaptor/array_ref_decl.hpp @@ -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 diff --git a/include/msgpack/adaptor/bool.hpp b/include/msgpack/adaptor/bool.hpp index 34f5fd31..f904fb98 100644 --- a/include/msgpack/adaptor/bool.hpp +++ b/include/msgpack/adaptor/bool.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 { - 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 { - template - msgpack::packer& operator()(msgpack::packer& o, const bool& v) const { - if(v) { o.pack_true(); } - else { o.pack_false(); } - return o; - } -}; - -template <> -struct object { - void operator()(msgpack::object& o, bool v) const { - o.type = msgpack::type::BOOLEAN; - o.via.boolean = v; - } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, bool v) const { - static_cast(o) << v; - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace msgpack +#include "msgpack/v1/adaptor/bool.hpp" #endif // MSGPACK_TYPE_BOOL_HPP diff --git a/include/msgpack/adaptor/boost/fusion.hpp b/include/msgpack/adaptor/boost/fusion.hpp index bd20b9a6..c6191f13 100644 --- a/include/msgpack/adaptor/boost/fusion.hpp +++ b/include/msgpack/adaptor/boost/fusion.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 -#include -#include -#include -#include -#include - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -#if !defined (MSGPACK_USE_CPP03) - -template -struct as< - T, - typename msgpack::enable_if< - boost::fusion::traits::is_sequence::value && - boost::mpl::fold< - T, - boost::mpl::bool_, - boost::mpl::if_ < - boost::mpl::and_< - boost::mpl::_1, - msgpack::has_as - >, - boost::mpl::bool_, - boost::mpl::bool_ - > - >::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::value)) { - throw msgpack::type_error(); - } - using tuple_t = decltype(to_tuple(std::declval(), gen_seq::value>())); - return to_t( - o.as(), - msgpack::gen_seq::value>()); - } - template - static std::tuple< - typename std::remove_reference< - typename boost::fusion::result_of::at_c::type - >::type...> - to_tuple(U const& u, seq) { - return std::make_tuple(boost::fusion::at_c(u)...); - } - template - static T to_t(U const& u, seq) { - return T(std::get(u)...); - } -}; - -#endif // !defined (MSGPACK_USE_CPP03) - -template -struct convert::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 - void operator()(U& v) const { - msgpack::adaptor::convert()(obj_.via.array.ptr[index_++], v); - } - private: - msgpack::object const& obj_; - uint32_t& index_; - }; -}; - -template -struct pack::value>::type > { - template - msgpack::packer& operator()(msgpack::packer& 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(o)); - return o; - } -private: - template - struct pack_imp { - pack_imp(msgpack::packer& stream):stream_(stream) {} - template - void operator()(U const& v) const { - stream_.pack(v); - } - private: - msgpack::packer& stream_; - }; -}; - -template -struct object_with_zone::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(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 - 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 diff --git a/include/msgpack/adaptor/boost/msgpack_variant.hpp b/include/msgpack/adaptor/boost/msgpack_variant.hpp index 07d1218a..b20f1ac9 100644 --- a/include/msgpack/adaptor/boost/msgpack_variant.hpp +++ b/include/msgpack/adaptor/boost/msgpack_variant.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 -#include - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace type { - - -template -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, // BIN - msgpack::type::raw_ref, // BIN - ext, // EXT - ext_ref, // EXT - boost::recursive_wrapper > >, // ARRAY - boost::recursive_wrapper, basic_variant > >, // MAP - boost::recursive_wrapper, basic_variant > >// MAP - >, - private boost::totally_ordered > { - 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, // BIN - msgpack::type::raw_ref, // BIN - ext, // EXT - ext_ref, // EXT - boost::recursive_wrapper > >, // ARRAY - boost::recursive_wrapper, basic_variant > >, // MAP - boost::recursive_wrapper, basic_variant > >// MAP - > base; - basic_variant() {} - template - 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(this); - } - bool is_bool() const { - return boost::get(this); - } - bool is_int64_t() const { - return boost::get(this); - } - bool is_uint64_t() const { - return boost::get(this); - } - bool is_double() const { - return boost::get(this); - } - bool is_string() const { - return boost::get(this); - } -#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 - bool is_boost_string_ref() const { - return boost::get(this); - } -#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 - bool is_vector_char() const { - return boost::get >(this); - } - bool is_vector_char() { - return boost::get >(this); - } - bool is_raw_ref() const { - return boost::get(this); - } - bool is_ext() const { - return boost::get(this); - } - bool is_ext_ref() const { - return boost::get(this); - } - bool is_vector() const { - return boost::get > >(this); - } - bool is_map() const { - return boost::get, basic_variant > >(this); - } - bool is_multimap() const { - return boost::get, basic_variant > >(this); - } - - bool as_bool() const { - return boost::get(*this); - } - int64_t as_int64_t() const { - return boost::get(*this); - } - int64_t& as_int64_t() { - return boost::get(*this); - } - uint64_t as_uint64_t() const { - return boost::get(*this); - } - uint64_t& as_uint64_t() { - return boost::get(*this); - } - double as_double() const { - return boost::get(*this); - } - double& as_double() { - return boost::get(*this); - } - std::string const& as_string() const { - return boost::get(*this); - } - std::string& as_string() { - return boost::get(*this); - } -#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 - boost::string_ref const& as_boost_string_ref() const { - return boost::get(*this); - } - boost::string_ref& as_boost_string_ref() { - return boost::get(*this); - } -#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 - std::vector const& as_vector_char() const { - return boost::get >(*this); - } - std::vector& as_vector_char() { - return boost::get >(*this); - } - raw_ref const& as_raw_ref() const { - return boost::get(*this); - } - ext const& as_ext() const { - return boost::get(*this); - } - ext& as_ext() { - return boost::get(*this); - } - ext_ref const& as_ext_ref() const { - return boost::get(*this); - } - std::vector > const& as_vector() const { - return boost::get > >(*this); - } - std::vector >& as_vector() { - return boost::get > >(*this); - } - std::map, basic_variant > const& as_map() const { - return boost::get, basic_variant > >(*this); - } - std::map, basic_variant >& as_map() { - return boost::get, basic_variant > >(*this); - } - std::multimap, basic_variant > const& as_multimap() const { - return boost::get, basic_variant > >(*this); - } - std::multimap, basic_variant >& as_multimap() { - return boost::get, basic_variant > >(*this); - } -private: - template - void int_init(T v) { - if (v < 0) { - static_cast(*this) = int64_t(v); - } - else { - static_cast(*this) = uint64_t(v); - } - } -}; - -template -inline bool operator<(basic_variant const& lhs, basic_variant const& rhs) { - return - static_cast::base const&>(lhs) < - static_cast::base const&>(rhs); -} - -template -inline bool operator==(basic_variant const& lhs, basic_variant const& rhs) { - return - static_cast::base const&>(lhs) == - static_cast::base const&>(rhs); -} - -typedef basic_variant, 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 -struct as > { - msgpack::type::basic_variant operator()(msgpack::object const& o) const { - switch(o.type) { - case type::NIL: - return o.as(); - case type::BOOLEAN: - return o.as(); - case type::POSITIVE_INTEGER: - return o.as(); - case type::NEGATIVE_INTEGER: - return o.as(); - case type::FLOAT: - return o.as(); - case type::STR: - return o.as(); - case type::BIN: - return o.as(); - case type::EXT: - return o.as(); - case type::ARRAY: - return o.as > >(); - case type::MAP: - return o.as, msgpack::type::basic_variant > >(); - default: - break; - } - return msgpack::type::basic_variant(); - } -}; - -#endif // !defined (MSGPACK_USE_CPP03) - - -template -struct convert > { - msgpack::object const& operator()( - msgpack::object const& o, - msgpack::type::basic_variant& v) const { - switch(o.type) { - case type::NIL: - v = o.as(); - break; - case type::BOOLEAN: - v = o.as(); - break; - case type::POSITIVE_INTEGER: - v = o.as(); - break; - case type::NEGATIVE_INTEGER: - v = o.as(); - break; - case type::FLOAT: - v = o.as(); - break; - case type::STR: - v = o.as(); - break; - case type::BIN: - v = o.as(); - break; - case type::EXT: - v = o.as(); - break; - case type::ARRAY: - v = o.as > >(); - break; - case type::MAP: - v = o.as, msgpack::type::basic_variant > >(); - break; - default: - break; - } - return o; - } -}; - -namespace detail { - -template -struct pack_imp : boost::static_visitor { - template - void operator()(T const& value) const { - pack()(o_, value); - } - pack_imp(packer& o):o_(o) {} - packer& o_; -}; - -} // namespace detail - -template -struct pack > { - template - msgpack::packer& operator()(msgpack::packer& o, const msgpack::type::basic_variant& v) const { - boost::apply_visitor(detail::pack_imp(o), v); - return o; - } -}; - -namespace detail { - -struct object_imp : boost::static_visitor { - void operator()(msgpack::type::nil_t const& v) const { - object()(o_, v); - } - void operator()(bool const& v) const { - object()(o_, v); - } - void operator()(uint64_t const& v) const { - object()(o_, v); - } - void operator()(int64_t const& v) const { - object()(o_, v); - } - void operator()(double const& v) const { - object()(o_, v); - } - template - void operator()(T const&) const { - throw msgpack::type_error(); - } - object_imp(msgpack::object& o):o_(o) {} - msgpack::object& o_; -}; - -} // namespace detail - -template -struct object > { - void operator()(msgpack::object& o, const msgpack::type::basic_variant& v) const { - boost::apply_visitor(detail::object_imp(o), v); - } -}; - -namespace detail { - -struct object_with_zone_imp : boost::static_visitor { - template - void operator()(T const& v) const { - object_with_zone()(o_, v); - } - object_with_zone_imp(msgpack::object::with_zone& o):o_(o) {} - msgpack::object::with_zone& o_; -}; - -} // namespace detail - -template -struct object_with_zone > { - void operator()(msgpack::object::with_zone& o, const msgpack::type::basic_variant& 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 diff --git a/include/msgpack/adaptor/boost/msgpack_variant_decl.hpp b/include/msgpack/adaptor/boost/msgpack_variant_decl.hpp new file mode 100644 index 00000000..64bf98f1 --- /dev/null +++ b/include/msgpack/adaptor/boost/msgpack_variant_decl.hpp @@ -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 diff --git a/include/msgpack/adaptor/boost/optional.hpp b/include/msgpack/adaptor/boost/optional.hpp index 36bfc46f..e4b53ceb 100644 --- a/include/msgpack/adaptor/boost/optional.hpp +++ b/include/msgpack/adaptor/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,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 - -#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 -struct as, typename std::enable_if::value>::type> { - boost::optional operator()(msgpack::object const& o) const { - if(o.is_nil()) return boost::none; - return o.as(); - } -}; - -#endif // !defined (MSGPACK_USE_CPP03) - -template -struct convert > { - msgpack::object const& operator()(msgpack::object const& o, boost::optional& v) const { - if(o.is_nil()) v = boost::none; - else { - T t; - msgpack::adaptor::convert()(o, t); - v = t; - } - return o; - } -}; - -template -struct pack > { - template - msgpack::packer& operator()(msgpack::packer& o, const boost::optional& v) const { - if (v) o.pack(*v); - else o.pack_nil(); - return o; - } -}; - -template -struct object > { - void operator()(msgpack::object& o, const boost::optional& v) const { - if (v) msgpack::adaptor::object()(o, *v); - else o.type = msgpack::type::NIL; - } -}; - -template -struct object_with_zone > { - void operator()(msgpack::object::with_zone& o, const boost::optional& v) const { - if (v) msgpack::adaptor::object_with_zone()(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 diff --git a/include/msgpack/adaptor/boost/string_ref.hpp b/include/msgpack/adaptor/boost/string_ref.hpp index 1ccad4a4..43bf70f4 100644 --- a/include/msgpack/adaptor/boost/string_ref.hpp +++ b/include/msgpack/adaptor/boost/string_ref.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 -#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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template <> -struct convert { - 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 { - template - msgpack::packer& operator()(msgpack::packer& 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 { - 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 { - void operator()(msgpack::object::with_zone& o, const boost::string_ref& v) const { - static_cast(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 diff --git a/include/msgpack/adaptor/char_ptr.hpp b/include/msgpack/adaptor/char_ptr.hpp index 9b3490d2..71cce6cc 100644 --- a/include/msgpack/adaptor/char_ptr.hpp +++ b/include/msgpack/adaptor/char_ptr.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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& 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 { - 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(o.zone.allocate_align(size)); - o.via.str.ptr = ptr; - o.via.str.size = size; - std::memcpy(ptr, v, size); - } -}; - -template <> -struct object { - 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 { - template - packer& operator()(packer& o, char* v) const { - return o << static_cast(v); - } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, char* v) const { - o << static_cast(v); - } -}; - -template <> -struct object { - void operator()(msgpack::object& o, char* v) const { - o << static_cast(v); - } -}; - -template -struct pack { - template - msgpack::packer& operator()(msgpack::packer& 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 { - 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(o.zone.allocate_align(size)); - o.via.str.ptr = ptr; - o.via.str.size = size; - std::memcpy(ptr, v, size); - } -}; - -template -struct object { - 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 { - template - msgpack::packer& operator()(msgpack::packer& 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 { - 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(o.zone.allocate_align(size)); - o.via.str.ptr = ptr; - o.via.str.size = size; - std::memcpy(ptr, v, size); - } -}; - -template -struct object { - 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 diff --git a/include/msgpack/adaptor/check_container_size.hpp b/include/msgpack/adaptor/check_container_size.hpp index cdc5d24f..a464419f 100644 --- a/include/msgpack/adaptor/check_container_size.hpp +++ b/include/msgpack/adaptor/check_container_size.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 +#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 -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 -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 -inline uint32_t checked_get_container_size(T size) { - detail::check_container_size(size); - return static_cast(size); -} - - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace msgpack +#include "msgpack/v1/adaptor/check_container_size.hpp" #endif // MSGPACK_CHECK_CONTAINER_SIZE_HPP diff --git a/include/msgpack/adaptor/check_container_size_decl.hpp b/include/msgpack/adaptor/check_container_size_decl.hpp new file mode 100644 index 00000000..73518226 --- /dev/null +++ b/include/msgpack/adaptor/check_container_size_decl.hpp @@ -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 diff --git a/include/msgpack/adaptor/cpp11/array.hpp b/include/msgpack/adaptor/cpp11/array.hpp index 2c3028b3..fdc49022 100644 --- a/include/msgpack/adaptor/cpp11/array.hpp +++ b/include/msgpack/adaptor/cpp11/array.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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -namespace detail { - -namespace array { - -template -inline std::array concat( - std::array&& a1, - std::array&& a2, - msgpack::seq, - msgpack::seq) { - return {{ std::move(a1[I1])..., std::move(a2[I2])... }}; -} - -template -inline std::array concat(std::array&& a1, std::array&& a2) { - return concat(std::move(a1), std::move(a2), msgpack::gen_seq(), msgpack::gen_seq()); -} - -template -struct as_impl { - static std::array as(msgpack::object const& o) { - msgpack::object* p = o.via.array.ptr + N - 1; - return concat(as_impl::as(o), std::array{{p->as()}}); - } -}; - -template -struct as_impl { - static std::array as(msgpack::object const& o) { - msgpack::object* p = o.via.array.ptr; - return std::array{{p->as()}}; - } -}; - -template -struct as_impl { - static std::array as(msgpack::object const&) { - return std::array(); - } -}; - -} // namespace array - -} // namespace detail - -template -struct as, typename std::enable_if::value>::type> { - std::array 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::as(o); - } -}; - -template -struct convert> { - msgpack::object const& operator()(msgpack::object const& o, std::array& 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 -struct pack> { - template - msgpack::packer& operator()(msgpack::packer& o, const std::array& 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 -struct object_with_zone> { - void operator()(msgpack::object::with_zone& o, const std::array& 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(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 diff --git a/include/msgpack/adaptor/cpp11/array_char.hpp b/include/msgpack/adaptor/cpp11/array_char.hpp index 1e337937..8a9bc6df 100644 --- a/include/msgpack/adaptor/cpp11/array_char.hpp +++ b/include/msgpack/adaptor/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_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 +#include "msgpack/v1/adaptor/cpp11/array_char.hpp" -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct convert> { - msgpack::object const& operator()(msgpack::object const& o, std::array& 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 -struct pack> { - template - msgpack::packer& operator()(msgpack::packer& o, const std::array& 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 -struct object> { - void operator()(msgpack::object& o, const std::array& 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 -struct object_with_zone> { - void operator()(msgpack::object::with_zone& o, const std::array& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = msgpack::type::BIN; - char* ptr = static_cast(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 diff --git a/include/msgpack/adaptor/cpp11/array_unsigned_char.hpp b/include/msgpack/adaptor/cpp11/array_unsigned_char.hpp index 3fdceeb8..0860a88a 100644 --- a/include/msgpack/adaptor/cpp11/array_unsigned_char.hpp +++ b/include/msgpack/adaptor/cpp11/array_unsigned_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 +#include "msgpack/v1/adaptor/cpp11/array_unsigned_char.hpp" -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct convert> { - msgpack::object const& operator()(msgpack::object const& o, std::array& 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 -struct pack> { - template - msgpack::packer& operator()(msgpack::packer& o, const std::array& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.pack_bin(size); - o.pack_bin_body(reinterpret_cast(v.data()), size); - - return o; - } -}; - -template -struct object> { - void operator()(msgpack::object& o, const std::array& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = msgpack::type::BIN; - o.via.bin.ptr = reinterpret_cast(v.data()); - o.via.bin.size = size; - } -}; - -template -struct object_with_zone> { - void operator()(msgpack::object::with_zone& o, const std::array& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = msgpack::type::BIN; - char* ptr = static_cast(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 diff --git a/include/msgpack/adaptor/cpp11/forward_list.hpp b/include/msgpack/adaptor/cpp11/forward_list.hpp index 4924be32..27ac9c0d 100644 --- a/include/msgpack/adaptor/cpp11/forward_list.hpp +++ b/include/msgpack/adaptor/cpp11/forward_list.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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template - struct as, typename std::enable_if::value>::type> { - std::forward_list operator()(msgpack::object const& o) const { - if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } - std::forward_list 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()); - } - return v; - } -}; - -template -struct convert> { - msgpack::object const& operator()(msgpack::object const& o, std::forward_list& 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 -struct pack> { - template - msgpack::packer& operator()(msgpack::packer& o, const std::forward_list& 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 -struct object_with_zone> { - void operator()(msgpack::object::with_zone& o, const std::forward_list& 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( - 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 diff --git a/include/msgpack/adaptor/cpp11/reference_wrapper.hpp b/include/msgpack/adaptor/cpp11/reference_wrapper.hpp index fae122a6..6b09429c 100644 --- a/include/msgpack/adaptor/cpp11/reference_wrapper.hpp +++ b/include/msgpack/adaptor/cpp11/reference_wrapper.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 -#include - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct convert> { - msgpack::object const& operator()(msgpack::object const& o, std::reference_wrapper& v) const { - msgpack::adaptor::convert()(o, v.get()); - return o; - } -}; - -template -struct pack> { - template - msgpack::packer& operator()(msgpack::packer& o, const std::reference_wrapper& v) const { - o.pack(v.get()); - return o; - } -}; - -template -struct object > { - void operator()(msgpack::object& o, const std::reference_wrapper& v) const { - msgpack::adaptor::object::type>()(o, v.get()); - } -}; - -template -struct object_with_zone> { - void operator()(msgpack::object::with_zone& o, const std::reference_wrapper& v) const { - msgpack::adaptor::object_with_zone::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 diff --git a/include/msgpack/adaptor/cpp11/shared_ptr.hpp b/include/msgpack/adaptor/cpp11/shared_ptr.hpp index c449974d..2199a499 100644 --- a/include/msgpack/adaptor/cpp11/shared_ptr.hpp +++ b/include/msgpack/adaptor/cpp11/shared_ptr.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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct as, typename std::enable_if::value>::type> { - std::shared_ptr operator()(msgpack::object const& o) const { - if(o.is_nil()) return nullptr; - return std::make_shared(o.as()); - } -}; - -template -struct convert> { - msgpack::object const& operator()(msgpack::object const& o, std::shared_ptr& v) const { - if(o.is_nil()) v.reset(); - else { - v = std::make_shared(); - msgpack::adaptor::convert()(o, *v); - } - return o; - } -}; - -template -struct pack> { - template - msgpack::packer& operator()(msgpack::packer& o, const std::shared_ptr& v) const { - if (v) o.pack(*v); - else o.pack_nil(); - return o; - } -}; - -template -struct object > { - void operator()(msgpack::object& o, const std::shared_ptr& v) const { - if (v) msgpack::adaptor::object()(o, *v); - else o.type = msgpack::type::NIL; - } -}; - -template -struct object_with_zone> { - void operator()(msgpack::object::with_zone& o, const std::shared_ptr& v) const { - if (v) msgpack::adaptor::object_with_zone()(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 diff --git a/include/msgpack/adaptor/cpp11/tuple.hpp b/include/msgpack/adaptor/cpp11/tuple.hpp index 42a3f811..b833c2a2 100644 --- a/include/msgpack/adaptor/cpp11/tuple.hpp +++ b/include/msgpack/adaptor/cpp11/tuple.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 +#include "msgpack/v1/adaptor/cpp11/tuple.hpp" -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -// --- Pack from tuple to packer stream --- -template -struct StdTuplePacker { - static void pack( - msgpack::packer& o, - const Tuple& v) { - StdTuplePacker::pack(o, v); - o.pack(std::get(v)); - } -}; - -template -struct StdTuplePacker { - static void pack ( - msgpack::packer&, - const Tuple&) { - } -}; - -namespace adaptor { - -template -struct pack> { - template - msgpack::packer& operator()( - msgpack::packer& o, - const std::tuple& v) const { - uint32_t size = checked_get_container_size(sizeof...(Args)); - o.pack_array(size); - StdTuplePacker::pack(o, v); - return o; - } -}; - -} // namespace adaptor - -// --- Convert from tuple to object --- - -template -struct StdTupleAs; - -template -struct StdTupleAsImpl { - static std::tuple as(msgpack::object const& o) { - return std::tuple_cat( - std::make_tuple(o.via.array.ptr[o.via.array.size - sizeof...(Args) - 1].as()), - StdTupleAs::as(o)); - } -}; - -template -struct StdTupleAs { - static std::tuple as(msgpack::object const& o) { - return StdTupleAsImpl::as(o); - } -}; - -template <> -struct StdTupleAs<> { - static std::tuple<> as (msgpack::object const&) { - return std::tuple<>(); - } -}; - -template -struct StdTupleConverter { - static void convert( - msgpack::object const& o, - Tuple& v) { - StdTupleConverter::convert(o, v); - o.via.array.ptr[N-1].convert(v))>::type>(std::get(v)); - } -}; - -template -struct StdTupleConverter { - static void convert ( - msgpack::object const&, - Tuple&) { - } -}; - -namespace adaptor { - -template -struct as, typename std::enable_if::value>::type> { - std::tuple 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::as(o); - } -}; - -template -struct convert> { - msgpack::object const& operator()( - msgpack::object const& o, - std::tuple& v) const { - if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } - if(o.via.array.size < sizeof...(Args)) { throw msgpack::type_error(); } - StdTupleConverter::convert(o, v); - return o; - } -}; - -} // namespace adaptor - -// --- Convert from tuple to object with zone --- -template -struct StdTupleToObjectWithZone { - static void convert( - msgpack::object::with_zone& o, - const Tuple& v) { - StdTupleToObjectWithZone::convert(o, v); - o.via.array.ptr[N-1] = msgpack::object(std::get(v), o.zone); - } -}; - -template -struct StdTupleToObjectWithZone { - static void convert ( - msgpack::object::with_zone&, - const Tuple&) { - } -}; - -namespace adaptor { - -template -struct object_with_zone> { - void operator()( - msgpack::object::with_zone& o, - std::tuple const& v) const { - uint32_t size = checked_get_container_size(sizeof...(Args)); - o.type = msgpack::type::ARRAY; - o.via.array.ptr = static_cast(o.zone.allocate_align(sizeof(msgpack::object)*size)); - o.via.array.size = size; - StdTupleToObjectWithZone::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 diff --git a/include/msgpack/adaptor/cpp11/unique_ptr.hpp b/include/msgpack/adaptor/cpp11/unique_ptr.hpp index af25e662..ef100128 100644 --- a/include/msgpack/adaptor/cpp11/unique_ptr.hpp +++ b/include/msgpack/adaptor/cpp11/unique_ptr.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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct as, typename std::enable_if::value>::type> { - std::unique_ptr operator()(msgpack::object const& o) const { - if(o.is_nil()) return nullptr; - return std::unique_ptr(new T(o.as())); - } -}; - -template -struct convert> { - msgpack::object const& operator()(msgpack::object const& o, std::unique_ptr& v) const { - if(o.is_nil()) v.reset(); - else { - v.reset(new T); - msgpack::adaptor::convert()(o, *v); - } - return o; - } -}; - -template -struct pack> { - template - msgpack::packer& operator()(msgpack::packer& o, const std::unique_ptr& v) const { - if (v) o.pack(*v); - else o.pack_nil(); - return o; - } -}; - -template -struct object > { - void operator()(msgpack::object& o, const std::unique_ptr& v) const { - if (v) msgpack::adaptor::object()(o, *v); - else o.type = msgpack::type::NIL; - } -}; - -template -struct object_with_zone> { - void operator()(msgpack::object::with_zone& o, const std::unique_ptr& v) const { - if (v) msgpack::adaptor::object_with_zone()(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 diff --git a/include/msgpack/adaptor/cpp11/unordered_map.hpp b/include/msgpack/adaptor/cpp11/unordered_map.hpp index 8eb97497..dadbf2e2 100644 --- a/include/msgpack/adaptor/cpp11/unordered_map.hpp +++ b/include/msgpack/adaptor/cpp11/unordered_map.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 +#include "msgpack/v1/adaptor/cpp11/unordered_map.hpp" -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct as< - std::unordered_map, - typename std::enable_if::value && msgpack::has_as::value>::type> { - std::unordered_map 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 v; - for (; p != pend; ++p) { - v.emplace(p->key.as(), p->val.as()); - } - return v; - } -}; - -template -struct convert> { - msgpack::object const& operator()(msgpack::object const& o, std::unordered_map& 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 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 -struct pack> { - template - msgpack::packer& operator()(msgpack::packer& o, const std::unordered_map& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.pack_map(size); - for(typename std::unordered_map::const_iterator it(v.begin()), it_end(v.end()); - it != it_end; ++it) { - o.pack(it->first); - o.pack(it->second); - } - return o; - } -}; - -template -struct object_with_zone> { - void operator()(msgpack::object::with_zone& o, const std::unordered_map& 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(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::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 -struct as< - std::unordered_multimap, - typename std::enable_if::value && msgpack::has_as::value>::type> { - std::unordered_multimap 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 v; - for (; p != pend; ++p) { - v.emplace(p->key.as(), p->val.as()); - } - return v; - } -}; - -template -struct convert> { - msgpack::object const& operator()(msgpack::object const& o, std::unordered_multimap& 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 tmp; - for(; p != pend; ++p) { - std::pair value; - p->key.convert(value.first); - p->val.convert(value.second); - tmp.insert(std::move(value)); - } - v = std::move(tmp); - return o; - } -}; - -template -struct pack> { - template - msgpack::packer& operator()(msgpack::packer& o, const std::unordered_multimap& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.pack_map(size); - for(typename std::unordered_multimap::const_iterator it(v.begin()), it_end(v.end()); - it != it_end; ++it) { - o.pack(it->first); - o.pack(it->second); - } - return o; - } -}; - -template -struct object_with_zone> { - void operator()(msgpack::object::with_zone& o, const std::unordered_multimap& 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(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::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 diff --git a/include/msgpack/adaptor/cpp11/unordered_set.hpp b/include/msgpack/adaptor/cpp11/unordered_set.hpp index dd70c7e9..f2e58621 100644 --- a/include/msgpack/adaptor/cpp11/unordered_set.hpp +++ b/include/msgpack/adaptor/cpp11/unordered_set.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 +#include "msgpack/v1/adaptor/cpp11/unordered_set.hpp" -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct as, typename std::enable_if::value>::type> { - std::unordered_set 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 v; - while (p > pbegin) { - --p; - v.insert(p->as()); - } - return v; - } -}; - -template -struct convert> { - msgpack::object const& operator()(msgpack::object const& o, std::unordered_set& 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 tmp; - while(p > pbegin) { - --p; - tmp.insert(p->as()); - } - v = std::move(tmp); - return o; - } -}; - -template -struct pack> { - template - msgpack::packer& operator()(msgpack::packer& o, const std::unordered_set& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.pack_array(size); - for(typename std::unordered_set::const_iterator it(v.begin()), it_end(v.end()); - it != it_end; ++it) { - o.pack(*it); - } - return o; - } -}; - -template -struct object_with_zone> { - void operator()(msgpack::object::with_zone& o, const std::unordered_set& 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(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::const_iterator it(v.begin()); - do { - *p = msgpack::object(*it, o.zone); - ++p; - ++it; - } while(p < pend); - } - } -}; - - -template -struct as, typename std::enable_if::value>::type> { - std::unordered_multiset 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 v; - while (p > pbegin) { - --p; - v.insert(p->as()); - } - return v; - } -}; - -template -struct convert> { - msgpack::object const& operator()(msgpack::object const& o, std::unordered_multiset& 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 tmp; - while(p > pbegin) { - --p; - tmp.insert(p->as()); - } - v = std::move(tmp); - return o; - } -}; - -template -struct pack> { - template - msgpack::packer& operator()(msgpack::packer& o, const std::unordered_multiset& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.pack_array(size); - for(typename std::unordered_multiset::const_iterator it(v.begin()), it_end(v.end()); - it != it_end; ++it) { - o.pack(*it); - } - return o; - } -}; - -template -struct object_with_zone> { - void operator()(msgpack::object::with_zone& o, const std::unordered_multiset& 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(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::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 diff --git a/include/msgpack/adaptor/define.hpp b/include/msgpack/adaptor/define.hpp index e156994d..15991008 100644 --- a/include/msgpack/adaptor/define.hpp +++ b/include/msgpack/adaptor/define.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 diff --git a/include/msgpack/adaptor/define_decl.hpp b/include/msgpack/adaptor/define_decl.hpp new file mode 100644 index 00000000..2760b653 --- /dev/null +++ b/include/msgpack/adaptor/define_decl.hpp @@ -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 + +#include "msgpack/versioning.hpp" + +// for MSGPACK_ADD_ENUM +#include "msgpack/adaptor/int.hpp" + +#define MSGPACK_DEFINE_ARRAY(...) \ + template \ + 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 \ + 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(static_cast(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 \ + 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 \ + 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(static_cast(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 { \ + msgpack::object const& operator()(msgpack::object const& o, enum_name& v) const { \ + msgpack::underlying_type::type tmp; \ + msgpack::operator>>(o, tmp); \ + v = static_cast(tmp); \ + return o; \ + } \ + }; \ + template<> \ + struct object { \ + void operator()(msgpack::object& o, const enum_name& v) const { \ + msgpack::underlying_type::type tmp = static_cast::type>(v); \ + msgpack::operator<<(o, tmp); \ + } \ + }; \ + template<> \ + struct object_with_zone { \ + void operator()(msgpack::object::with_zone& o, const enum_name& v) const { \ + msgpack::underlying_type::type tmp = static_cast::type>(v); \ + msgpack::operator<<(o, tmp); \ + } \ + }; \ + template <> \ + struct pack { \ + template \ + msgpack::packer& operator()(msgpack::packer& o, const enum_name& v) const { \ + return msgpack::operator<<(o, static_cast::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 diff --git a/include/msgpack/adaptor/deque.hpp b/include/msgpack/adaptor/deque.hpp index 3944f668..dfb61b6b 100644 --- a/include/msgpack/adaptor/deque.hpp +++ b/include/msgpack/adaptor/deque.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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -#if !defined(MSGPACK_USE_CPP03) - -template -struct as, typename std::enable_if::value>::type> { - std::deque operator()(const msgpack::object& o) const { - if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } - std::deque 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()); - ++p; - } while (p < pend); - } - return v; - } -}; - -#endif // !defined(MSGPACK_USE_CPP03) - -template -struct convert > { - msgpack::object const& operator()(msgpack::object const& o, std::deque& 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::iterator it = v.begin(); - for(; p < pend; ++p, ++it) { - p->convert(*it); - } - return o; - } -}; - -template -struct pack > { - template - msgpack::packer& operator()(msgpack::packer& o, const std::deque& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.pack_array(size); - for(typename std::deque::const_iterator it(v.begin()), it_end(v.end()); - it != it_end; ++it) { - o.pack(*it); - } - return o; - } -}; - -template -struct object_with_zone > { - void operator()(msgpack::object::with_zone& o, const std::deque& 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(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::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 diff --git a/include/msgpack/adaptor/ext.hpp b/include/msgpack/adaptor/ext.hpp index 7ffad38f..37658dc9 100644 --- a/include/msgpack/adaptor/ext.hpp +++ b/include/msgpack/adaptor/ext.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 -#include -#include +#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(s); - m_data.reserve(static_cast(s) + 1); - m_data.push_back(static_cast(t)); - m_data.insert(m_data.end(), p, p + s); - } - ext(int8_t t, uint32_t s) { - detail::check_container_size_for_ext(s); - m_data.resize(static_cast(s) + 1); - m_data[0] = static_cast(t); - } - ext(ext_ref const&); - int8_t type() const { - return static_cast(m_data[0]); - } - const char* data() const { - return &m_data[1]; - } - char* data() { - return &m_data[1]; - } - uint32_t size() const { - return static_cast(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 m_data; - friend class ext_ref; -}; - -} // namespace type - -namespace adaptor { - -template <> -struct convert { - 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 { - template - msgpack::packer& operator()(msgpack::packer& 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 { - 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(o.zone.allocate_align(size + 1)); - o.via.ext.ptr = ptr; - o.via.ext.size = size; - ptr[0] = static_cast(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(static_cast(&m_size))), m_size(0) {} - ext_ref(const char* p, uint32_t s) : - m_ptr(s == 0 ? static_cast(static_cast(&m_size)) : p), - m_size(s == 0 ? 0 : s - 1) { - detail::check_container_size_for_ext(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(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; -}; - -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::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 { - template - msgpack::packer& operator()(msgpack::packer& 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 { - 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 { - void operator()(msgpack::object::with_zone& o, const msgpack::type::ext_ref& v) const { - static_cast(o) << v; - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace msgpack - -#endif // MSGPACK_TYPE_EXT_HPP +#endif // MSGPACK_TYPE_EXT_HPP diff --git a/include/msgpack/adaptor/ext_decl.hpp b/include/msgpack/adaptor/ext_decl.hpp new file mode 100644 index 00000000..29bfd617 --- /dev/null +++ b/include/msgpack/adaptor/ext_decl.hpp @@ -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 diff --git a/include/msgpack/adaptor/fixint.hpp b/include/msgpack/adaptor/fixint.hpp index 62f4742e..1c49116e 100644 --- a/include/msgpack/adaptor/fixint.hpp +++ b/include/msgpack/adaptor/fixint.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 -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 fix_uint8; -typedef fix_int fix_uint16; -typedef fix_int fix_uint32; -typedef fix_int fix_uint64; - -typedef fix_int fix_int8; -typedef fix_int fix_int16; -typedef fix_int fix_int32; -typedef fix_int fix_int64; - - -} // namespace type - -namespace adaptor { - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, type::fix_int8& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, type::fix_int16& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, type::fix_int32& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, type::fix_int64& v) const - { v = type::detail::convert_integer(o); return o; } -}; - - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, type::fix_uint8& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, type::fix_uint16& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, type::fix_uint32& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, type::fix_uint64& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, const type::fix_int8& v) const - { o.pack_fix_int8(v); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, const type::fix_int16& v) const - { o.pack_fix_int16(v); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, const type::fix_int32& v) const - { o.pack_fix_int32(v); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, const type::fix_int64& v) const - { o.pack_fix_int64(v); return o; } -}; - - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, const type::fix_uint8& v) const - { o.pack_fix_uint8(v); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, const type::fix_uint16& v) const - { o.pack_fix_uint16(v); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, const type::fix_uint32& v) const - { o.pack_fix_uint32(v); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, const type::fix_uint64& v) const - { o.pack_fix_uint64(v); return o; } -}; - -template <> -struct object { - 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 { - 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 { - 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 { - 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 { - void operator()(msgpack::object& o, type::fix_uint8 v) const - { o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); } -}; - -template <> -struct object { - void operator()(msgpack::object& o, type::fix_uint16 v) const - { o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); } -}; - -template <> -struct object { - void operator()(msgpack::object& o, type::fix_uint32 v) const - { o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); } -}; - -template <> -struct object { - 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 { - void operator()(msgpack::object::with_zone& o, type::fix_int8 v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, type::fix_int16 v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, type::fix_int32 v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, type::fix_int64 v) const - { static_cast(o) << v; } -}; - - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, type::fix_uint8 v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, type::fix_uint16 v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, type::fix_uint32 v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, type::fix_uint64 v) const - { static_cast(o) << v; } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace msgpack - -#endif /* msgpack/type/fixint.hpp */ +#endif // MSGPACK_TYPE_FIXINT_HPP diff --git a/include/msgpack/adaptor/fixint_decl.hpp b/include/msgpack/adaptor/fixint_decl.hpp new file mode 100644 index 00000000..999fdd61 --- /dev/null +++ b/include/msgpack/adaptor/fixint_decl.hpp @@ -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 diff --git a/include/msgpack/adaptor/float.hpp b/include/msgpack/adaptor/float.hpp index 219e3aa7..5683c96d 100644 --- a/include/msgpack/adaptor/float.hpp +++ b/include/msgpack/adaptor/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,114 +10,6 @@ #ifndef MSGPACK_TYPE_FLOAT_HPP #define MSGPACK_TYPE_FLOAT_HPP -#include "msgpack/versioning.hpp" -#include "msgpack/object_fwd.hpp" -#include - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -// FIXME check overflow, underflow - -namespace adaptor { - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, float& v) const { - if(o.type == msgpack::type::FLOAT) { - v = static_cast(o.via.f64); - } - else if (o.type == msgpack::type::POSITIVE_INTEGER) { - v = static_cast(o.via.u64); - } - else if (o.type == msgpack::type::NEGATIVE_INTEGER) { - v = static_cast(o.via.i64); - } - else { - throw msgpack::type_error(); - } - return o; - } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, const float& v) const { - o.pack_float(v); - return o; - } -}; - - -template <> -struct convert { - 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(o.via.u64); - } - else if (o.type == msgpack::type::NEGATIVE_INTEGER) { - v = static_cast(o.via.i64); - } - else { - throw msgpack::type_error(); - } - return o; - } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, const double& v) const { - o.pack_double(v); - return o; - } -}; - - -template <> -struct object { - void operator()(msgpack::object& o, float v) const { - o.type = msgpack::type::FLOAT; - o.via.f64 = static_cast(v); - } -}; - -template <> -struct object { - void operator()(msgpack::object& o, double v) const { - o.type = msgpack::type::FLOAT; - o.via.f64 = v; - } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, float v) const { - static_cast(o) << v; - } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, double v) const { - static_cast(o) << v; - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace msgpack +#include "msgpack/v1/adaptor/float.hpp" #endif // MSGPACK_TYPE_FLOAT_HPP diff --git a/include/msgpack/adaptor/int.hpp b/include/msgpack/adaptor/int.hpp index 32f73ec3..e2213e7e 100644 --- a/include/msgpack/adaptor/int.hpp +++ b/include/msgpack/adaptor/int.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 +#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 - struct convert_integer_sign; - - template - struct convert_integer_sign { - static T convert(msgpack::object const& o) { - if(o.type == msgpack::type::POSITIVE_INTEGER) { - if(o.via.u64 > static_cast(std::numeric_limits::max())) - { throw msgpack::type_error(); } - return static_cast(o.via.u64); - } else if(o.type == msgpack::type::NEGATIVE_INTEGER) { - if(o.via.i64 < static_cast(std::numeric_limits::min())) - { throw msgpack::type_error(); } - return static_cast(o.via.i64); - } - throw msgpack::type_error(); - } - }; - - template - struct convert_integer_sign { - static T convert(msgpack::object const& o) { - if(o.type == msgpack::type::POSITIVE_INTEGER) { - if(o.via.u64 > static_cast(std::numeric_limits::max())) - { throw msgpack::type_error(); } - return static_cast(o.via.u64); - } - throw msgpack::type_error(); - } - }; - - template - struct is_signed { - static const bool value = std::numeric_limits::is_signed; - }; - - template - static inline T convert_integer(msgpack::object const& o) - { - return detail::convert_integer_sign::value>::convert(o); - } - - template - struct object_char_sign; - - template <> - struct object_char_sign { - template - static typename msgpack::enable_if::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 { - 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::value>::make(o, v); - } - -} // namespace detail -} // namespace type - -namespace adaptor { - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, char& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, signed char& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, signed short& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, signed int& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, signed long& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, signed long long& v) const - { v = type::detail::convert_integer(o); return o; } -}; - - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, unsigned char& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, unsigned short& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, unsigned int& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, unsigned long& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - msgpack::object const& operator()(msgpack::object const& o, unsigned long long& v) const - { v = type::detail::convert_integer(o); return o; } -}; - - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, char v) const - { o.pack_char(v); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, signed char v) const - { o.pack_signed_char(v); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, signed short v) const - { o.pack_short(v); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, signed int v) const - { o.pack_int(v); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, signed long v) const - { o.pack_long(v); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, signed long long v) const - { o.pack_long_long(v); return o; } -}; - - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, unsigned char v) const - { o.pack_unsigned_char(v); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, unsigned short v) const - { o.pack_unsigned_short(v); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, unsigned int v) const - { o.pack_unsigned_int(v); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, unsigned long v) const - { o.pack_unsigned_long(v); return o; } -}; - -template <> -struct pack { - template - msgpack::packer& operator()(msgpack::packer& o, unsigned long long v) const - { o.pack_unsigned_long_long(v); return o; } -}; - - -template <> -struct object { - void operator()(msgpack::object& o, char v) const - { type::detail::object_char(o, v); } -}; - -template <> -struct object { - 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 { - 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 { - 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 { - 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 { - 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 { - void operator()(msgpack::object& o, unsigned char v) const - { o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; } -}; - -template <> -struct object { - void operator()(msgpack::object& o, unsigned short v) const - { o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; } -}; - -template <> -struct object { - void operator()(msgpack::object& o, unsigned int v) const - { o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; } -}; - -template <> -struct object { - void operator()(msgpack::object& o, unsigned long v) const - { o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; } -}; - -template <> -struct object { - 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 { - void operator()(msgpack::object::with_zone& o, char v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, signed char v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, signed short v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, signed int v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, signed long v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, const signed long long& v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, unsigned char v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, unsigned short v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, unsigned int v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, unsigned long v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, const unsigned long long& v) const - { static_cast(o) << v; } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace msgpack - -#endif /* msgpack/type/int.hpp */ +#endif // MSGPACK_TYPE_INT_HPP diff --git a/include/msgpack/adaptor/int_decl.hpp b/include/msgpack/adaptor/int_decl.hpp new file mode 100644 index 00000000..cb5e3498 --- /dev/null +++ b/include/msgpack/adaptor/int_decl.hpp @@ -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 diff --git a/include/msgpack/adaptor/list.hpp b/include/msgpack/adaptor/list.hpp index 412396ea..8761da3a 100644 --- a/include/msgpack/adaptor/list.hpp +++ b/include/msgpack/adaptor/list.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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -#if !defined(MSGPACK_USE_CPP03) - -template -struct as, typename std::enable_if::value>::type> { - std::list operator()(msgpack::object const& o) const { - if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } - std::list 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()); - } - return v; - } -}; - -#endif // !defined(MSGPACK_USE_CPP03) - -template -struct convert > { - msgpack::object const& operator()(msgpack::object const& o, std::list& 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::iterator it = v.begin(); - for (; p < pend; ++p, ++it) { - p->convert(*it); - } - return o; - } -}; - -template -struct pack > { - template - msgpack::packer& operator()(msgpack::packer& o, const std::list& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.pack_array(size); - for (typename std::list::const_iterator it(v.begin()), it_end(v.end()); - it != it_end; ++it) { - o.pack(*it); - } - return o; - } -}; - -template -struct object_with_zone > { - void operator()(msgpack::object::with_zone& o, const std::list& 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(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::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 diff --git a/include/msgpack/adaptor/map.hpp b/include/msgpack/adaptor/map.hpp index b0f39fa1..7f0e22e2 100644 --- a/include/msgpack/adaptor/map.hpp +++ b/include/msgpack/adaptor/map.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 -#include -#include +#include "msgpack/v1/adaptor/map.hpp" -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace type { - -template , typename Alloc = std::allocator > > -class assoc_vector : public std::vector< std::pair, Alloc > { -#if !defined(MSGPACK_USE_CPP03) - using std::vector, Alloc>::vector; -#endif // !defined(MSGPACK_USE_CPP03) -}; - -namespace detail { - template - struct pair_first_less { - bool operator() (const std::pair& x, const std::pair& y) const - { return Compare()(x.first, y.first); } - }; -} - -} //namespace type - -namespace adaptor { - -#if !defined(MSGPACK_USE_CPP03) - -template -struct as< - type::assoc_vector, - typename std::enable_if::value && msgpack::has_as::value>::type> { - type::assoc_vector operator()(msgpack::object const& o) const { - if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); } - type::assoc_vector 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(), p->val.as()); - } - std::sort(v.begin(), v.end(), type::detail::pair_first_less()); - return v; - } -}; - -#endif // !defined(MSGPACK_USE_CPP03) - -template -struct convert > { - msgpack::object const& operator()(msgpack::object const& o, type::assoc_vector& 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* 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()); - return o; - } -}; - -template -struct pack > { - template - msgpack::packer& operator()(msgpack::packer& o, const type::assoc_vector& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.pack_map(size); - for (typename type::assoc_vector::const_iterator it(v.begin()), it_end(v.end()); - it != it_end; ++it) { - o.pack(it->first); - o.pack(it->second); - } - return o; - } -}; - -template -struct object_with_zone > { - void operator()(msgpack::object::with_zone& o, const type::assoc_vector& 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(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::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 -struct as< - std::map, - typename std::enable_if::value && msgpack::has_as::value>::type> { - std::map 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 v; - for (; p != pend; ++p) { - v.emplace(p->key.as(), p->val.as()); - } - return v; - } -}; - -#endif // !defined(MSGPACK_USE_CPP03) - -template -struct convert > { - msgpack::object const& operator()(msgpack::object const& o, std::map& 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 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 -struct pack > { - template - msgpack::packer& operator()(msgpack::packer& o, const std::map& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.pack_map(size); - for (typename std::map::const_iterator it(v.begin()), it_end(v.end()); - it != it_end; ++it) { - o.pack(it->first); - o.pack(it->second); - } - return o; - } -}; - -template -struct object_with_zone > { - void operator()(msgpack::object::with_zone& o, const std::map& 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(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::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 -struct as< - std::multimap, - typename std::enable_if::value && msgpack::has_as::value>::type> { - std::multimap 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 v; - for (; p != pend; ++p) { - v.emplace(p->key.as(), p->val.as()); - } - return v; - } -}; - -#endif // !defined(MSGPACK_USE_CPP03) - -template -struct convert > { - msgpack::object const& operator()(msgpack::object const& o, std::multimap& 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 tmp; - for (; p != pend; ++p) { - std::pair 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 -struct pack > { - template - msgpack::packer& operator()(msgpack::packer& o, const std::multimap& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.pack_map(size); - for (typename std::multimap::const_iterator it(v.begin()), it_end(v.end()); - it != it_end; ++it) { - o.pack(it->first); - o.pack(it->second); - } - return o; - } -}; - -template -struct object_with_zone > { - void operator()(msgpack::object::with_zone& o, const std::multimap& 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(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::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 diff --git a/include/msgpack/adaptor/map_decl.hpp b/include/msgpack/adaptor/map_decl.hpp new file mode 100644 index 00000000..2ce545f7 --- /dev/null +++ b/include/msgpack/adaptor/map_decl.hpp @@ -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 diff --git a/include/msgpack/adaptor/msgpack_tuple.hpp b/include/msgpack/adaptor/msgpack_tuple.hpp index 3d324b9a..a6392776 100644 --- a/include/msgpack/adaptor/msgpack_tuple.hpp +++ b/include/msgpack/adaptor/msgpack_tuple.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 diff --git a/include/msgpack/adaptor/msgpack_tuple_decl.hpp b/include/msgpack/adaptor/msgpack_tuple_decl.hpp new file mode 100644 index 00000000..2892b14f --- /dev/null +++ b/include/msgpack/adaptor/msgpack_tuple_decl.hpp @@ -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 diff --git a/include/msgpack/adaptor/nil.hpp b/include/msgpack/adaptor/nil.hpp index ebecb414..92f30812 100644 --- a/include/msgpack/adaptor/nil.hpp +++ b/include/msgpack/adaptor/nil.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 { - 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 { - template - msgpack::packer& operator()(msgpack::packer& o, const type::nil_t&) const { - o.pack_nil(); - return o; - } -}; - -template <> -struct object { - void operator()(msgpack::object& o, type::nil_t) const { - o.type = msgpack::type::NIL; - } -}; - -template <> -struct object_with_zone { - void operator()(msgpack::object::with_zone& o, type::nil_t v) const { - static_cast(o) << v; - } -}; - -} // namespace adaptor - -template <> -inline void msgpack::object::as() 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 diff --git a/include/msgpack/adaptor/nil_decl.hpp b/include/msgpack/adaptor/nil_decl.hpp new file mode 100644 index 00000000..a5bdf436 --- /dev/null +++ b/include/msgpack/adaptor/nil_decl.hpp @@ -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 diff --git a/include/msgpack/adaptor/pair.hpp b/include/msgpack/adaptor/pair.hpp index 6b6d3426..0956aa9a 100644 --- a/include/msgpack/adaptor/pair.hpp +++ b/include/msgpack/adaptor/pair.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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -#if !defined(MSGPACK_USE_CPP03) - -template -struct as, - typename std::enable_if::value>::type> { - std::pair 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(), o.via.array.ptr[1].as()); - } -}; - -#endif // !defined(MSGPACK_USE_CPP03) - -template -struct convert > { - msgpack::object const& operator()(msgpack::object const& o, std::pair& 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 -struct pack > { - template - msgpack::packer& operator()(msgpack::packer& o, const std::pair& v) const { - o.pack_array(2); - o.pack(v.first); - o.pack(v.second); - return o; - } -}; - -template -struct object_with_zone > { - void operator()(msgpack::object::with_zone& o, const std::pair& v) const { - o.type = msgpack::type::ARRAY; - msgpack::object* p = static_cast(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 diff --git a/include/msgpack/adaptor/raw.hpp b/include/msgpack/adaptor/raw.hpp index 84550aae..f85f882c 100644 --- a/include/msgpack/adaptor/raw.hpp +++ b/include/msgpack/adaptor/raw.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 -#include +#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::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 { - template - msgpack::packer& operator()(msgpack::packer& 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 { - 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 { - void operator()(msgpack::object::with_zone& o, const msgpack::type::raw_ref& v) const { - static_cast(o) << v; - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace msgpack +#include "msgpack/v1/adaptor/raw.hpp" #endif // MSGPACK_TYPE_RAW_HPP diff --git a/include/msgpack/adaptor/raw_decl.hpp b/include/msgpack/adaptor/raw_decl.hpp new file mode 100644 index 00000000..eb3b96b8 --- /dev/null +++ b/include/msgpack/adaptor/raw_decl.hpp @@ -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 diff --git a/include/msgpack/adaptor/set.hpp b/include/msgpack/adaptor/set.hpp index bc3af12a..fbf820ab 100644 --- a/include/msgpack/adaptor/set.hpp +++ b/include/msgpack/adaptor/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,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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -#if !defined(MSGPACK_USE_CPP03) - -template -struct as, typename std::enable_if::value>::type> { - std::set 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 v; - while (p > pbegin) { - --p; - v.insert(p->as()); - } - return v; - } -}; - -#endif // !defined(MSGPACK_USE_CPP03) - -template -struct convert > { - msgpack::object const& operator()(msgpack::object const& o, std::set& 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 tmp; - while (p > pbegin) { - --p; - tmp.insert(p->as()); - } -#if __cplusplus >= 201103L - v = std::move(tmp); -#else - tmp.swap(v); -#endif - return o; - } -}; - -template -struct pack > { - template - msgpack::packer& operator()(msgpack::packer& o, const std::set& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.pack_array(size); - for (typename std::set::const_iterator it(v.begin()), it_end(v.end()); - it != it_end; ++it) { - o.pack(*it); - } - return o; - } -}; - -template -struct object_with_zone > { - void operator()(msgpack::object::with_zone& o, const std::set& 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(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::const_iterator it(v.begin()); - do { - *p = msgpack::object(*it, o.zone); - ++p; - ++it; - } while(p < pend); - } - } -}; - -#if !defined(MSGPACK_USE_CPP03) - -template -struct as, typename std::enable_if::value>::type> { - std::multiset 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 v; - while (p > pbegin) { - --p; - v.insert(p->as()); - } - return v; - } -}; - -#endif // !defined(MSGPACK_USE_CPP03) - -template -struct convert > { - msgpack::object const& operator()(msgpack::object const& o, std::multiset& 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 tmp; - while (p > pbegin) { - --p; - tmp.insert(p->as()); - } -#if __cplusplus >= 201103L - v = std::move(tmp); -#else - tmp.swap(v); -#endif - return o; - } -}; - -template -struct pack > { - template - msgpack::packer& operator()(msgpack::packer& o, const std::multiset& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.pack_array(size); - for (typename std::multiset::const_iterator it(v.begin()), it_end(v.end()); - it != it_end; ++it) { - o.pack(*it); - } - return o; - } -}; - -template -struct object_with_zone > { - void operator()(msgpack::object::with_zone& o, const std::multiset& 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(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::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 diff --git a/include/msgpack/adaptor/string.hpp b/include/msgpack/adaptor/string.hpp index 6e22eced..8e318254 100644 --- a/include/msgpack/adaptor/string.hpp +++ b/include/msgpack/adaptor/string.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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template <> -struct convert { - 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 { - template - msgpack::packer& operator()(msgpack::packer& 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 { - 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 { - 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(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 diff --git a/include/msgpack/adaptor/v4raw.hpp b/include/msgpack/adaptor/v4raw.hpp index fcf06e9c..52c0de37 100644 --- a/include/msgpack/adaptor/v4raw.hpp +++ b/include/msgpack/adaptor/v4raw.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 -#include +#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::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 { - template - msgpack::packer& operator()(msgpack::packer& 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 { - 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 { - void operator()(msgpack::object::with_zone& o, const msgpack::type::v4raw_ref& v) const { - static_cast(o) << v; - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace msgpack +#include "msgpack/v1/adaptor/v4raw.hpp" #endif // MSGPACK_TYPE_V4RAW_HPP diff --git a/include/msgpack/adaptor/v4raw_decl.hpp b/include/msgpack/adaptor/v4raw_decl.hpp new file mode 100644 index 00000000..5e591df0 --- /dev/null +++ b/include/msgpack/adaptor/v4raw_decl.hpp @@ -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 diff --git a/include/msgpack/adaptor/vector.hpp b/include/msgpack/adaptor/vector.hpp index b73dd63b..5eb6caca 100644 --- a/include/msgpack/adaptor/vector.hpp +++ b/include/msgpack/adaptor/vector.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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -#if !defined(MSGPACK_USE_CPP03) - -template -struct as, typename std::enable_if::value>::type> { - std::vector operator()(const msgpack::object& o) const { - if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } - std::vector 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()); - ++p; - } while (p < pend); - } - return v; - } -}; - -#endif // !defined(MSGPACK_USE_CPP03) - -template -struct convert > { - msgpack::object const& operator()(msgpack::object const& o, std::vector& 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::iterator it = v.begin(); - do { - p->convert(*it); - ++p; - ++it; - } while(p < pend); - } - return o; - } -}; - -template -struct pack > { - template - msgpack::packer& operator()(msgpack::packer& o, const std::vector& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.pack_array(size); - for (typename std::vector::const_iterator it(v.begin()), it_end(v.end()); - it != it_end; ++it) { - o.pack(*it); - } - return o; - } -}; - -template -struct object_with_zone > { - void operator()(msgpack::object::with_zone& o, const std::vector& 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(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::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 diff --git a/include/msgpack/adaptor/vector_bool.hpp b/include/msgpack/adaptor/vector_bool.hpp index e321c12a..f259ac9b 100644 --- a/include/msgpack/adaptor/vector_bool.hpp +++ b/include/msgpack/adaptor/vector_bool.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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct convert > { - msgpack::object const& operator()(msgpack::object const& o, std::vector& 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::iterator it = v.begin(), end = v.end(); - it != end; - ++it) { - *it = p->as(); - ++p; - } - } - return o; - } -}; - -template -struct pack > { - template - msgpack::packer& operator()(msgpack::packer& o, const std::vector& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.pack_array(size); - for(typename std::vector::const_iterator it(v.begin()), it_end(v.end()); - it != it_end; ++it) { - o.pack(static_cast(*it)); - } - return o; - } -}; - -template -struct object_with_zone > { - void operator()(msgpack::object::with_zone& o, const std::vector& 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(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::const_iterator it(v.begin()); - do { - *p = msgpack::object(static_cast(*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 diff --git a/include/msgpack/adaptor/vector_char.hpp b/include/msgpack/adaptor/vector_char.hpp index ce1ca23d..d196efa4 100644 --- a/include/msgpack/adaptor/vector_char.hpp +++ b/include/msgpack/adaptor/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_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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct convert > { - msgpack::object const& operator()(msgpack::object const& o, std::vector& 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 -struct pack > { - template - msgpack::packer& operator()(msgpack::packer& o, const std::vector& 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 -struct object > { - void operator()(msgpack::object& o, const std::vector& 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 -struct object_with_zone > { - void operator()(msgpack::object::with_zone& o, const std::vector& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = msgpack::type::BIN; - char* ptr = static_cast(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 diff --git a/include/msgpack/adaptor/vector_unsigned_char.hpp b/include/msgpack/adaptor/vector_unsigned_char.hpp index 822aa095..e71e0d36 100644 --- a/include/msgpack/adaptor/vector_unsigned_char.hpp +++ b/include/msgpack/adaptor/vector_unsigned_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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct convert > { - msgpack::object const& operator()(msgpack::object const& o, std::vector& 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 -struct pack > { - template - msgpack::packer& operator()(msgpack::packer& o, const std::vector& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.pack_bin(size); - o.pack_bin_body(reinterpret_cast(&v.front()), size); - - return o; - } -}; - -template -struct object > { - void operator()(msgpack::object& o, const std::vector& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = msgpack::type::BIN; - o.via.bin.ptr = reinterpret_cast(&v.front()); - o.via.bin.size = size; - } -}; - -template -struct object_with_zone > { - void operator()(msgpack::object::with_zone& o, const std::vector& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = msgpack::type::BIN; - char* ptr = static_cast(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 diff --git a/include/msgpack/cpp_config.hpp b/include/msgpack/cpp_config.hpp index 8d33f8b4..0b36d7ef 100644 --- a/include/msgpack/cpp_config.hpp +++ b/include/msgpack/cpp_config.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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -template -struct unique_ptr : std::auto_ptr { - explicit unique_ptr(T* p = 0) throw() : std::auto_ptr(p) {} - unique_ptr(unique_ptr& a) throw() : std::auto_ptr(a) {} - template - unique_ptr (unique_ptr& a) throw() : std::auto_ptr(a) {} -}; - -template -T& move(T& t) -{ - return t; -} - -template -T const& move(T const& t) -{ - return t; -} - -template -struct enable_if { - typedef T type; -}; - -template -struct enable_if { -}; - -template -struct integral_constant { - static T const value = val; - typedef T value_type; - typedef integral_constant type; -}; - -typedef integral_constant true_type; -typedef integral_constant false_type; - -template -struct is_same : false_type {}; - -template -struct is_same : true_type {}; - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace msgpack - - -#else // MSGPACK_USE_CPP03 - -#include -#include - -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 diff --git a/include/msgpack/cpp_config_decl.hpp b/include/msgpack/cpp_config_decl.hpp new file mode 100644 index 00000000..70179c09 --- /dev/null +++ b/include/msgpack/cpp_config_decl.hpp @@ -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 diff --git a/include/msgpack/fbuffer.hpp b/include/msgpack/fbuffer.hpp index a4b71e88..6d51cd54 100644 --- a/include/msgpack/fbuffer.hpp +++ b/include/msgpack/fbuffer.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 -#include +#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 diff --git a/include/msgpack/fbuffer_decl.hpp b/include/msgpack/fbuffer_decl.hpp new file mode 100644 index 00000000..a630ed08 --- /dev/null +++ b/include/msgpack/fbuffer_decl.hpp @@ -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 diff --git a/include/msgpack/iterator.hpp b/include/msgpack/iterator.hpp index db0da533..a118b592 100644 --- a/include/msgpack/iterator.hpp +++ b/include/msgpack/iterator.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 +#include -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 - 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 diff --git a/include/msgpack/iterator_decl.hpp b/include/msgpack/iterator_decl.hpp new file mode 100644 index 00000000..8835e58e --- /dev/null +++ b/include/msgpack/iterator_decl.hpp @@ -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 +#include + +#endif // MSGPACK_V1_ITERATOR_DECL_HPP diff --git a/include/msgpack/meta.hpp b/include/msgpack/meta.hpp index 2db6a942..7062cc55 100644 --- a/include/msgpack/meta.hpp +++ b/include/msgpack/meta.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 - -namespace msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace detail { -template struct bool_pack; - -template struct all_of_imp - : std::is_same, bool_pack>{}; - -} // namespace detail - -template