diff --git a/.gitignore b/.gitignore index 1b855612..169dfff2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,16 @@ -build -.idea +.DS_Store +build/ +.idea/ +.vscode/ + +doc/site/ +doc/doxygen/ + *.pyc compile_commands.json CMakeLists.txt.user cppcheck* report utils/release -.vscode -doc/site -doc/doxygen doc/all.xml reference.md diff --git a/.travis.yml b/.travis.yml index 0c83802f..2dabe462 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,53 +1,32 @@ -dist: trusty -language: cpp -compiler: - #- clang - - g++ - -branches: - only: - - master - - dev - - osx_support - -env: - global: - - CI_HOME=`pwd` - -addons: - apt: - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-precise-3.7 - - george-edison55-precise-backports - packages: - - gcc-5 - - g++-5 - - cmake - - cmake-data +language: c++ +os: linux +dist: focal +sudo: required + +matrix: + include: + - compiler: gcc + env: RPCLIB_CXX_STANDARD=11 BUILD_TYPE=Release COVERAGE="ON" + - compiler: gcc + env: RPCLIB_CXX_STANDARD=14 BUILD_TYPE=Release COVERAGE="OFF" + - compiler: clang + env: RPCLIB_CXX_STANDARD=11 BUILD_TYPE=Release COVERAGE="OFF" + - compiler: clang + env: RPCLIB_CXX_STANDARD=14 BUILD_TYPE=Release COVERAGE="OFF" + +before_install: + - sudo apt-get update -qq install: - - pip install --user cpp-coveralls - - if [ "$CXX" = "g++" ]; then export CXX="g++-5" CC="gcc-5"; fi + - sudo apt-get install -qq g++ cmake script: - - g++-5 --version - - gcc-5 --version - - cd $CI_HOME - - git submodule init - - git submodule update --init --recursive - - mkdir build14 && cd build14 - - cmake -DRPCLIB_ENABLE_COVERAGE=ON -DRPCLIB_BUILD_TESTS=ON -DRPCLIB_CXX_STANDARD=14 .. - - make -j2 - - cd .. - - mkdir build11 && cd build11 - - cmake -DRPCLIB_ENABLE_COVERAGE=ON -DRPCLIB_BUILD_TESTS=ON -DRPCLIB_CXX_STANDARD=11 .. - - make -j2 - - cd .. + - mkdir build ; cd build + - cmake -DRPCLIB_ENABLE_COVERAGE=$COVERAGE -DRPCLIB_BUILD_TESTS=ON -DRPCLIB_CXX_STANDARD=$RPCLIB_CXX_STANDARD -DCMAKE_INSTALL_PREFIX=../install .. + - cmake --build . --config $BUILD_TYPE + - cmake --build . --target install after_success: - - ./build14/output/bin/rpc_test - - ./build11/output/bin/rpc_test - - coveralls --exclude dependencies --exclude test --exclude include/rpc/msgpack --exclude include/rcp/msgpack.hpp --gcov /usr/bin/gcov-5 - - + - ./tests/rpc_test + - lcov --capture --directory . --output-file coverage.info + - bash <(curl -s https://codecov.io/bash) diff --git a/CHANGELOG.md b/CHANGELOG.md index e79bb251..c9c57a1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,63 @@ # Changelog +### 2.3.0 + +This release fixes various issues. + +*Fixes* + + * Fix compile error on gcc 4.9 + * Fix warnings in clang 7 + * Fix self-assignment + * Fix early destruction of server sessions + * Fix crashes in multithreaded environment (#175) + +*Additions* + + * Support calling `rpc::this_server().stop()` from a server procedure (#187) + * Make rpclib compatible with codebases that do not use exceptions + * Add `server::port()` to query the port used by the server + * Set `reuseaddress` option on the server + + +### 2.2.1 + +This release fixed a crash on Windows. + +*Fixes*: + + * Fixed client crashing when `suppress_exceptions` was on + and the server threw an exception. + +### 2.2.0 + +This release fixed a number of long-standing issues. + +*Fixes*: + + * Fixed macOS build (#142) + * Updated msgpack (#152) + * Fixed a bug where the server could crash if the client timed out (#153) + * Fixed code coverage (moved away from coveralls.io) + +*Additions*: + + * Simplified and modularized CMake script (#94) + * Added `this_session()->id()` which is a unique, per-session id + * Added waffle.io badge + * Added missing client::clear_timeout function + +### 2.1.1 + +This release fixes an embarrassing build breakage. + +Released on 2017-07-15. + +Changes since 2.1.1: + + * Fixes building with coverage using clang + + ### 2.1.0 This is mainly a bugfix release. diff --git a/CMakeLists.txt b/CMakeLists.txt index 950ed44f..721b0931 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,395 +1,264 @@ -cmake_minimum_required(VERSION 3.0.0) -project(rpc) +cmake_minimum_required(VERSION 3.5.1) +project(rpc VERSION 2.3.0) set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") -################################################################################ +include(policies) +include(msvc_support) +include(coverage) +include(check_warning_flag) + # # Options # -################################################################################ - -option(RPCLIB_BUILD_TESTS "Build unit RPCLIB_BUILD_TESTS." OFF) -option(RPCLIB_GENERATE_COMPDB "Generate compilation database. Useful for YCM." OFF) -option(RPCLIB_BUILD_EXAMPLES "Build examples." OFF) -option(RPCLIB_ENABLE_LOGGING "ALlow logging in the library for debug purposes. Also usable in a release build." OFF) -option(RPCLIB_ENABLE_COVERAGE "Generate coverage information" OFF) -option(RPCLIB_FORCE_M64 "Force -m64 in CXXFLAGS" OFF) -option(RPCLIB_FORCE_M32 "Force -m32 in CXXFLAGS" OFF) -option(RPCLIB_MSVC_STATIC_RUNTIME "MSVC only: build with /MT instead of /MD" OFF) - -################################################################################ +option(RPCLIB_BUILD_TESTS + "Build unit RPCLIB_BUILD_TESTS." + OFF) +option(RPCLIB_GENERATE_COMPDB + "Generate compilation database. Useful for YCM." + OFF) +option(RPCLIB_BUILD_EXAMPLES + "Build examples." + OFF) +option(RPCLIB_ENABLE_LOGGING + "ALlow logging in the library for debug purposes." + OFF) +option(RPCLIB_ENABLE_COVERAGE + "Generate coverage information" + OFF) +option(RPCLIB_MSVC_STATIC_RUNTIME + "MSVC only: build with /MT instead of /MD" + OFF) + # # Other configuration values # -################################################################################ +set(RPCLIB_DEFAULT_PORT 8080 + CACHE STRING "Default port used for running tests and examples") +set(RPCLIB_DEFAULT_BUFFER_SIZE "1024 << 10" + CACHE STRING "Default buffer size") +set(RPCLIB_CXX_STANDARD 11 CACHE STRING + "C++ version used to build rpclib (Currently: Only 11 and 14 supported)") -set(RPCLIB_DEFAULT_PORT 8080 CACHE STRING "Default port used for running tests and examples") -set(RPCLIB_DEFAULT_BUFFER_SIZE "1024 << 10" CACHE STRING "Default buffer size") -set(RPCLIB_CXX_STANDARD 11 CACHE STRING "C++ version used to build rpclib (Currently: Only 11 and 14 supported)") +if(RPCLIB_GENERATE_COMPDB) + set(CMAKE_EXPORT_COMPILE_COMMANDS "ON") # for YCM + add_custom_command(PROJECT_NAME ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E + copy ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_BINARY_DIR}/../compile_commands.json) +endif() -if(NOT ${RPCLIB_CXX_STANDARD} EQUAL 14 AND NOT ${RPCLIB_CXX_STANDARD} EQUAL 11) - message(fatal_error "Unsupported C++ standard: ${RPCLIB_CXX_STANDARD}") +if(NOT ${RPCLIB_CXX_STANDARD} EQUAL 14 AND + NOT ${RPCLIB_CXX_STANDARD} EQUAL 11) + message(fatal_error "Unsupported C++ standard: ${RPCLIB_CXX_STANDARD}") endif() -################################################################################ +set(CMAKE_CXX_STANDARD ${RPCLIB_CXX_STANDARD}) + # # Compile & install the library # -################################################################################ - -include(TargetArch) - -set(RPCLIB_VERSION_MAJOR 2) -set(RPCLIB_VERSION_MINOR 1) -set(RPCLIB_VERSION_PATCH 0) - -target_architecture(TARGET_ARCH) - -if(RPCLIB_FORCE_M32) - message(STATUS "Compiling for 32-bit") - set(RPCLIB_ARCH_DEF "RPCLIB_ARCH_X86") - set(RPCLIB_TARGET_ARCH "x86") - set(RPCLIB_DEB_ARCH "i386") -elseif(RPCLIB_FORCE_M64) - message(STATUS "Compiling for 64-bit") - set(RPCLIB_ARCH_DEF "RPCLIB_ARCH_X64") - set(RPCLIB_TARGET_ARCH "x64") - set(RPCLIB_DEB_ARCH "amd64") -elseif (${TARGET_ARCH} STREQUAL "i386") - message(STATUS "Compiling for 32-bit") - set(RPCLIB_ARCH_DEF "RPCLIB_ARCH_X86") - set(RPCLIB_TARGET_ARCH "x86") - set(RPCLIB_DEB_ARCH "i386") -elseif(${TARGET_ARCH} STREQUAL "x86_64") - message(STATUS "Compiling for 64-bit") - set(RPCLIB_ARCH_DEF "RPCLIB_ARCH_X64") - set(RPCLIB_TARGET_ARCH "x64") - set(RPCLIB_DEB_ARCH "amd64") -endif() - if (WIN32) - set(RPCLIB_OS_DEF "RPCLIB_WIN32") + set(RPCLIB_OS_DEF "RPCLIB_WIN32") elseif (LINUX) - set(RPCLIB_OS_DEF "RPCLIB_LINUX") + set(RPCLIB_OS_DEF "RPCLIB_LINUX") elseif (APPLE) - set(RPCLIB_OS_DEF "RPCLIB_MAC") + set(RPCLIB_OS_DEF "RPCLIB_MAC") endif() -# This function sets the rpclib-specific flags that are used for -# development. You do not need this in your project. Instead, -# Findrpclib.cmake supplies a (possibly empty) RPCLIB_EXTRA_FLAGS variable -# that you should append to your build flags. -function(set_rpclib_flags TARGET) - # clang is the compiler used for developing mainly, so - # this is where I set the highest warning level - # but feel free to add similar flags to GCC - if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") - - set(RPCLIB_BUILD_FLAGS - "-Wall -pedantic -Weverything -Wno-c++98-compat\ - -Wno-c++98-compat-pedantic -Wno-padded -Wno-missing-prototypes\ - -Wno-undef -pthread") - if(RPCLIB_CXX_STANDARD EQUAL 14) - set(RPCLIB_BUILD_FLAGS "${RPCLIB_BUILD_FLAGS} -std=c++14") - elseif(RPCLIB_CXX_STANDARD EQUAL 11) - set(RPCLIB_BUILD_FLAGS "${RPCLIB_BUILD_FLAGS} -std=c++11") - endif() - - if(RPCLIB_FORCE_M32) - set(RPCLIB_BUILD_FLAGS "${RPCLIB_BUILD_FLAGS} -m32") - elseif(RPCLIB_FORCE_M64) - set(RPCLIB_BUILD_FLAGS "${RPCLIB_BUILD_FLAGS} -m64") - endif() - - set(RPCLIB_DEP_LIBRARIES "pthread") - - elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") - - set(RPCLIB_BUILD_FLAGS "-Wall -pedantic -pthread") - if(RPCLIB_CXX_STANDARD EQUAL 14) - set(RPCLIB_BUILD_FLAGS "${RPCLIB_BUILD_FLAGS} -std=c++14") - elseif(RPCLIB_CXX_STANDARD EQUAL 11) - set(RPCLIB_BUILD_FLAGS "${RPCLIB_BUILD_FLAGS} -std=c++11") - endif() - - if(RPCLIB_ENABLE_COVERAGE) - set(RPCLIB_BUILD_FLAGS "${RPCLIB_BUILD_FLAGS} -g --coverage -O0") - endif() - - if(RPCLIB_FORCE_M32) - set(RPCLIB_BUILD_FLAGS "${RPCLIB_BUILD_FLAGS} -m32") - elseif(RPCLIB_FORCE_M64) - set(RPCLIB_BUILD_FLAGS "${RPCLIB_BUILD_FLAGS} -m64") - endif() - - set(RPCLIB_DEP_LIBRARIES "pthread") - - elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") - - set(RPCLIB_COMPILE_DEFINITIONS - "${RPCLIB_COMPILE_DEFINITIONS}" - "WIN32_LEAN_AND_MEAN" - "NOMINMAX" - "VC_EXTRALEAN" - "_CRT_SECURE_NO_WARNINGS" - "_CRT_NONSTDC_NO_DEPRECATE" - "_WIN32_WINNT=0x0501" - "_GNU_SOURCE" - "ASIO_HAS_STD_ADDRESSOF" - "ASIO_HAS_STD_ARRAY" - "ASIO_HAS_CSTDINT" - "ASIO_HAS_STD_SHARED_PTR" - "ASIO_HAS_STD_TYPE_TRAITS") - - endif() - - if (RPCLIB_EXTRA_BUILD_FLAGS) - set(RPCLIB_BUILD_FLAGS "${RPCLIB_BUILD_FLAGS} ${RPCLIB_EXTRA_BUILD_FLAGS}") - endif() - - set(RPCLIB_COMPILE_DEFINITIONS - "${RPCLIB_COMPILE_DEFINITIONS}" - "${RPCLIB_ARCH_DEF}" - "${RPCLIB_OS_DEF}" - "ASIO_STANDALONE" - "RPCLIB_ASIO=clmdep_asio" - "RPCLIB_FMT=clmdep_fmt" - "RPCLIB_MSGPACK=clmdep_msgpack" - ) - - if(RPCLIB_ENABLE_LOGGING) - set(RPCLIB_COMPILE_DEFINITIONS - "${RPCLIB_COMPILE_DEFINITIONS};RPCLIB_ENABLE_LOGGING") - endif() - - if(RPCLIB_BUILD_FLAGS) - set_target_properties(${TARGET} - PROPERTIES - COMPILE_FLAGS "${RPCLIB_BUILD_FLAGS}") - endif() - - if(RPCLIB_COMPILE_DEFINITIONS) - set_target_properties(${TARGET} - PROPERTIES - COMPILE_DEFINITIONS "${RPCLIB_COMPILE_DEFINITIONS}") - endif() - - target_link_libraries(${TARGET} ${RPCLIB_DEP_LIBRARIES}) - target_include_directories( - ${TARGET} - PUBLIC include - PRIVATE include/rpc - ) - target_include_directories( - ${TARGET} SYSTEM - PRIVATE dependencies/include - ) - -endfunction() - -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/lib) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/lib) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/bin) +set(RPCLIB_DEPENDENCIES "${CMAKE_CURRENT_LIST_DIR}/dependencies") configure_file( - "${PROJECT_SOURCE_DIR}/include/rpc/version.h.in" - "${PROJECT_SOURCE_DIR}/include/rpc/version.h") + "${PROJECT_SOURCE_DIR}/include/rpc/version.h.in" + "${PROJECT_SOURCE_DIR}/include/rpc/version.h") configure_file( - "${PROJECT_SOURCE_DIR}/include/rpc/config.h.in" - "${PROJECT_SOURCE_DIR}/include/rpc/config.h") + "${PROJECT_SOURCE_DIR}/include/rpc/config.h.in" + "${PROJECT_SOURCE_DIR}/include/rpc/config.h") configure_file( - "${PROJECT_SOURCE_DIR}/doc/pages/versions.md.in" - "${PROJECT_SOURCE_DIR}/doc/pages/versions.md") + "${PROJECT_SOURCE_DIR}/doc/pages/versions.md.in" + "${PROJECT_SOURCE_DIR}/doc/pages/versions.md") file(GLOB_RECURSE RPCLIB_HEADERS - include/rpc/*.h - include/msgpack/*.hpp) + include/rpc/*.h + include/msgpack/*.hpp) file(GLOB_RECURSE DEP_HEADERS - dependencies/include/*.h - dependencies/include/*.hpp) + ${RPCLIB_DEPENDENCIES}/include/*.h + ${RPCLIB_DEP_LIBRARIDEPENDENCIES}/include/*.hpp) -if(RPCLIB_NAME_SUFFIX) - set(OUTPUT_LIBRARY_NAME ${CMAKE_PROJECT_NAME}-${RPCLIB_NAME_SUFFIX}) -else() - set(OUTPUT_LIBRARY_NAME ${CMAKE_PROJECT_NAME}) +set(DEP_SOURCES + ${RPCLIB_DEPENDENCIES}/src/format.cc + ${RPCLIB_DEPENDENCIES}/src/posix.cc) + +add_library(${PROJECT_NAME} + lib/rpc/dispatcher.cc + lib/rpc/server.cc + lib/rpc/client.cc + lib/rpc/this_handler.cc + lib/rpc/this_session.cc + lib/rpc/this_server.cc + lib/rpc/rpc_error.cc + lib/rpc/detail/server_session.cc + lib/rpc/detail/response.cc + lib/rpc/detail/client_error.cc + lib/rpc/nonstd/optional.cc + ${DEP_SOURCES} + ${DEP_HEADERS} + ${RPCLIB_HEADERS}) + +# Perform steps and checks required for MSVC support +rpclib_msvc_support() + +set(RPCLIB_BUILD_FLAGS "") # reset flags + +if(RPCLIB_ENABLE_COVERAGE) + enable_coverage(${PROJECT_NAME}) endif() -set(DEP_SOURCES - dependencies/src/format.cc - dependencies/src/posix.cc) - -add_library(${OUTPUT_LIBRARY_NAME} - lib/rpc/dispatcher.cc - lib/rpc/server.cc - lib/rpc/client.cc - lib/rpc/this_handler.cc - lib/rpc/this_session.cc - lib/rpc/this_server.cc - lib/rpc/rpc_error.cc - lib/rpc/detail/server_session.cc - lib/rpc/detail/response.cc - lib/rpc/detail/client_error.cc - lib/rpc/nonstd/optional.cc - ${DEP_SOURCES} - ${DEP_HEADERS} - ${RPCLIB_HEADERS}) - - -set_rpclib_flags(${OUTPUT_LIBRARY_NAME}) - -target_link_libraries(${OUTPUT_LIBRARY_NAME}) - -# When building via conan, respect the compilation settings. -if ("${CONAN_LINK_RUNTIME}" STREQUAL "/MT") - set(RPCLIB_MSVC_STATIC_RUNTIME ON) +if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + # clang is the compiler used for developing mainly, so + # this is where I set the highest warning level + list(APPEND RPCLIB_BUILD_FLAGS + -Wall -pedantic -Weverything -Wno-c++98-compat + -Wno-c++98-compat-pedantic -Wno-padded -Wno-missing-prototypes + -Wno-undef) + + set(UNUSED_LAMBDA_CAPTURE_WARN_SUPPORTED) + check_warning_flag("unused-lambda-capture" UNUSED_LAMBDA_CAPTURE_WARN_SUPPORTED) + if(${UNUSED_LAMBDA_CAPTURE_WARN_SUPPORTED}) + list(APPEND RPCLIB_BUILD_FLAGS -Wno-unused-lambda-capture) + endif() + + check_warning_flag("zero-as-null-pointer-constant" ZERO_AS_NULL_POINTER_CONSTANT_WARN_SUPPORTED) + set(ZERO_AS_NULL_POINTER_CONSTANT_WARN_SUPPORTED) + if(${ZERO_AS_NULL_POINTER_CONSTANT_WARN_SUPPORTED}) + list(APPEND RPCLIB_BUILD_FLAGS -Wno-zero-as-null-pointer-constant) + endif() endif() -# MSVC static runtime support -# -# While this pollutes global flags (when using add_library), you would not want to -# build with a disparity anyway. (also, CMake still has no support for this, so you -# would end up doing something like this yourself). -if (RPCLIB_MSVC_STATIC_RUNTIME) - # Set compiler options. - set(variables - CMAKE_C_FLAGS_DEBUG - CMAKE_C_FLAGS_MINSIZEREL - CMAKE_C_FLAGS_RELEASE - CMAKE_C_FLAGS_RELWITHDEBINFO - CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_MINSIZEREL - CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_RELWITHDEBINFO - ) - - message(STATUS - "MSVC -> forcing use of statically-linked runtime." - ) - - foreach(variable ${variables}) - if(${variable} MATCHES "/MD") - string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}") - endif() - endforeach() +if (RPCLIB_EXTRA_BUILD_FLAGS) + list(APPEND RPCLIB_BUILD_FLAGS ${RPCLIB_EXTRA_BUILD_FLAGS}) +endif() +target_compile_definitions(${PROJECT_NAME} + PRIVATE + "${RPCLIB_COMPILE_DEFINITIONS}" + "${RPCLIB_ARCH_DEF}" + "ASIO_STANDALONE" + "RPCLIB_ASIO=clmdep_asio" + "RPCLIB_FMT=clmdep_fmt" + PUBLIC + "${RPCLIB_OS_DEF}" + "RPCLIB_MSGPACK=clmdep_msgpack" + ) + +if(RPCLIB_ENABLE_LOGGING) + target_compile_definitions(${PROJECT_NAME} PRIVATE "RPCLIB_ENABLE_LOGGING") endif() -install(TARGETS ${OUTPUT_LIBRARY_NAME} DESTINATION lib) -install(DIRECTORY include/ - DESTINATION include - FILES_MATCHING - PATTERN "*.h" - PATTERN "*.hpp" - PATTERN "*.inl" - PATTERN "*.in" EXCLUDE) -install(FILES ${PROJECT_BINARY_DIR}/version.h DESTINATION include/rpc) +if(RPCLIB_BUILD_FLAGS) + target_compile_options(${PROJECT_NAME} PRIVATE ${RPCLIB_BUILD_FLAGS}) +endif() -if(RPCLIB_GENERATE_COMPDB) - set(CMAKE_EXPORT_COMPILE_COMMANDS "ON") # for YCM - add_custom_command(TARGET ${OUTPUT_LIBRARY_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E - copy ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_BINARY_DIR}/../compile_commands.json) +if(RPCLIB_COMPILE_DEFINITIONS) + set_target_properties(${PROJECT_NAME} + PROPERTIES + COMPILE_DEFINITIONS "${RPCLIB_COMPILE_DEFINITIONS}") +endif() + +target_link_libraries(${PROJECT_NAME} ${RPCLIB_DEP_LIBRARIES}) +if (WIN32) + target_link_libraries(${PROJECT_NAME} wsock32 ws2_32) endif() +target_include_directories( + ${PROJECT_NAME} PUBLIC + $ + $ + ) +target_include_directories( + ${PROJECT_NAME} SYSTEM + PRIVATE ${RPCLIB_DEPENDENCIES}/include + ) + +install(TARGETS ${PROJECT_NAME} DESTINATION lib EXPORT rpclibTargets) +install(DIRECTORY include/ + DESTINATION include + FILES_MATCHING + PATTERN "*.h" + PATTERN "*.hpp" + PATTERN "*.inl" + PATTERN "*.in" EXCLUDE) -################################################################################ # # Unit tests # -################################################################################ - if(RPCLIB_BUILD_TESTS) - set(TEST_PROJECT_NAME ${CMAKE_PROJECT_NAME}_test) - set(TEST_SOURCES - dependencies/src/gmock-gtest-all.cc - tests/testmain.cc - tests/testutils.h - tests/rpc/dispatcher_test.cc - tests/rpc/client_test.cc - tests/rpc/response_test.cc - tests/rpc/server_test.cc - tests/rpc/this_handler_test.cc - tests/rpc/this_session_test.cc - tests/rpc/server_session_test.cc - tests/rpc/this_server_test.cc) - - - add_executable(${TEST_PROJECT_NAME} ${TEST_SOURCES}) - set_rpclib_flags(${TEST_PROJECT_NAME}) - target_include_directories(${TEST_PROJECT_NAME} SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/tests") - target_link_libraries( - ${TEST_PROJECT_NAME} - ${OUTPUT_LIBRARY_NAME} - ${RPCLIB_DEP_LIBRARIES}) - - # Set less strict warning for tests, since google test is not quite - # warning-clean - if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") - get_target_property(ORIGINAL_FLAGS ${TEST_PROJECT_NAME} COMPILE_FLAGS) - set_target_properties(${TEST_PROJECT_NAME} PROPERTIES COMPILE_FLAGS - "${ORIGINAL_FLAGS} -Wno-sign-conversion -Wno-weak-vtables -Wno-unused-member-function \ - -Wno-global-constructors -Wno-used-but-marked-unused -Wno-covered-switch-default \ - -Wno-missing-variable-declarations -Wno-deprecated -Wno-unused-macros -Wno-undef \ - -Wno-exit-time-destructors -Wno-switch-enum -Wno-format-nonliteral -Wno-unused-parameter -Wno-disabled-macro-expansion") - endif() - + add_subdirectory(tests) endif() -################################################################################ # # Example programs # -################################################################################ - if(RPCLIB_BUILD_EXAMPLES) - set(RPCLIB_ROOT_DIR "${PROJECT_SOURCE_DIR}") - set(RPCLIB_PROJECT_NAME "${CMAKE_PROJECT_NAME}") - set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/localbuild") - set(ENV{RPCLIB_DEFAULT_PORT} "${RPCLIB_DEFAULT_PORT}") - #add_subdirectory(examples/server) - #add_subdirectory(examples/client) - add_subdirectory(examples/echo) - add_subdirectory(examples/mandelbrot) - add_subdirectory(examples/calculator) + find_package(Threads) + set(RPCLIB_ROOT_DIR "${PROJECT_SOURCE_DIR}") + set(RPCLIB_PROJECT_NAME "${CMAKE_PROJECT_NAME}") + set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/localbuild") + set(ENV{RPCLIB_DEFAULT_PORT} "${RPCLIB_DEFAULT_PORT}") + add_subdirectory(examples/echo) + add_subdirectory(examples/mandelbrot) + add_subdirectory(examples/calculator) endif() +# +# Cmake Package +# +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/cmake/rpclibConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion + ) + +set(CONFIG_PACKAGE_LOCATION lib/cmake/rpclib) +set(INCLUDE_INSTALL_DIR include/ ) + +configure_package_config_file(cmake/rpclibConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/cmake/rpclibConfig.cmake + INSTALL_DESTINATION ${CONFIG_PACKAGE_LOCATION} + PATH_VARS INCLUDE_INSTALL_DIR + ) + +export(EXPORT rpclibTargets + FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/rpclibTargets.cmake" + NAMESPACE rpclib:: + ) + +install(EXPORT rpclibTargets + FILE rpclibTargets.cmake + NAMESPACE rpclib:: + DESTINATION ${CONFIG_PACKAGE_LOCATION} + ) +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/cmake/rpclibConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/cmake/rpclibConfigVersion.cmake + DESTINATION ${CONFIG_PACKAGE_LOCATION} + ) -################################################################################ # -# CPack +# Pkg-config # -################################################################################ - -include(InstallRequiredSystemLibraries) - -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Modern msgpack-rpc library for C++") -set(CPACK_PACKAGE_DESCRIPTION "rpclib is a modern msgpack-rpc library for C++. It allows connecting applications through a network channel where they can talk to each other using the msgpack-rpc protocol. It provides both a client and server, which can be used independently.") -set(CPACK_PACKAGE_VENDOR "Tamás Szelei") -set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") -set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md") -set(CPACK_PACKAGE_VERSION_MAJOR "${RPCLIB_VERSION_MAJOR}") -set(CPACK_PACKAGE_VERSION_MINOR "${RPCLIB_VERSION_MINOR}") -set(CPACK_PACKAGE_VERSION_PATCH "${RPCLIB_VERSION_PATCH}") -set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/output/pkg") -set(CPACK_PACKAGE_EXECUTABLES "librpc" "rpc") -set(CPACK_PACKAGE_NAME "lib${CMAKE_PROJECT_NAME}_${RPCLIB_DEB_ARCH}") -set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${RPCLIB_DEB_ARCH}) -set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Tamás Szelei") -set(CPACK_DEBIAN_PACKAGE_CONTACT "Tamás Szelei") -if(WIN32) - set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}") +if(NOT MSVC) # Don't install pkg-config files when building with MSVC + # Variables for pkg-config files + set(prefix "${CMAKE_INSTALL_PREFIX}") + set(exec_prefix "") + set(libdir "${CMAKE_INSTALL_PREFIX}/lib") + set(includedir "${CMAKE_INSTALL_PREFIX}/include") + set(rpclib_version ${PROJECT_VERSION}) + get_target_property(rpclib_cflags ${PROJECT_NAME} COMPILE_OPTIONS) + string(REPLACE ";" " " rpclib_cflags "${rpclib_cflags}") # Convert list to string + + configure_file(rpclib.pc.in "${CMAKE_CURRENT_BINARY_DIR}/rpclib.pc" @ONLY) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/rpclib.pc" DESTINATION "${libdir}/pkgconfig") endif() -if(WIN32) - #set(CPACK_PACKAGE_ICON "${CMake_SOURCE_DIR}/Utilities/Release\\\\InstallIcon.bmp") - #set(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\MyExecutable.exe") - set(CPACK_PACKAGE_INSTALL_DIRECTORY "librpc ${RPCLIB_VERSION_MAJOR}.${RPCLIB_VERSION_MINOR}.${RPCLIB_VERSION_PATCH}") - set(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} rpclib") - #set(CPACK_NSIS_HELP_LINK "http:\\\\\\\\www.my-project-home-page.org") - set(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\github.com/sztomi/rpc") - #set(CPACK_NSIS_CONTACT "me@my-personal-home-page.com") - set(CPACK_NSIS_MODIFY_PATH ON) -endif() -include(CPack) diff --git a/README.md b/README.md index 2404a18f..9f008715 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,12 @@ +# rpclib ![MIT](https://img.shields.io/badge/license-MIT-blue.svg) [![Build Status](https://travis-ci.org/rpclib/rpclib.svg?branch=master)](https://travis-ci.org/rpclib/rpclib) [![Build status](https://ci.appveyor.com/api/projects/status/9lft2tlamcox8epq?svg=true)](https://ci.appveyor.com/project/sztomi/callme) [![Coverage Status](https://img.shields.io/codecov/c/github/rpclib/rpclib/dev.svg)](https://img.shields.io/codecov/c/github/rpclib/rpclib/dev.svg) ![Coverity](https://scan.coverity.com/projects/7259/badge.svg?flat=1) [![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg?maxAge=2592000)](https://gitter.im/rpclib/Lobby) -# rpclib ![MIT](https://img.shields.io/badge/license-MIT-blue.svg) [![Build Status](https://travis-ci.org/rpclib/rpclib.svg?branch=master)](https://travis-ci.org/rpclib/rpclib) [![Build status](https://ci.appveyor.com/api/projects/status/9lft2tlamcox8epq?svg=true)](https://ci.appveyor.com/project/sztomi/callme) [![Coverage Status](https://coveralls.io/repos/github/rpclib/rpclib/badge.svg)](https://coveralls.io/github/rpclib/rpclib?branch=dev) ![Coverity](https://scan.coverity.com/projects/7259/badge.svg?flat=1) [![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg?maxAge=2592000)](https://gitter.im/rpclib/Lobby) +## Status + +**[rpclib is looking for maintainers](https://github.com/rpclib/rpclib/issues/273)** + +If you're looking for a similar library with support for JSON-RPC and async operations, check out **[packio](https://github.com/qchateau/packio)**. + +## Overview `rpclib` is a RPC library for C++, providing both a client and server implementation. It is built using modern C++14, and as such, requires a recent compiler. Main highlights: diff --git a/appveyor.yml b/appveyor.yml index 4eee674b..0679387a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,30 +1,20 @@ -version: 1.0.{build} -os: Visual Studio 2015 -clone_folder: C:\projects\rpc -test: off +image: Visual Studio 2019 +configuration: Release branches: only: - master - dev -configuration: - - Release - -environment: - matrix: - - CMAKE_PLATFORM: "Visual Studio 14 2015" - -install: true - -build_script: - - cd c:\projects\rpc +before_build: - git submodule init - git submodule update --init --recursive - md build - cd build - - cmake -DRPCLIB_ENABLE_COVERAGE=ON -DRPCLIB_BUILD_TESTS=ON -G "%CMAKE_PLATFORM%" .. - - set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" - - set MSBuildOptions=/v:m /p:Configuration=%Configuration% /logger:%MSBuildLogger% - - msbuild %MSBuildOptions% rpc.sln - - .\output\bin\Release\rpc_test.exe + - cmake .. -DRPCLIB_BUILD_TESTS=ON + +build: + project: build/rpc.sln + +test_script: + - .\tests\Release\rpc_test.exe diff --git a/cmake/TargetArch.cmake b/cmake/TargetArch.cmake deleted file mode 100644 index 3761e4df..00000000 --- a/cmake/TargetArch.cmake +++ /dev/null @@ -1,134 +0,0 @@ -# Based on the Qt 5 processor detection code, so should be very accurate -# https://qt.gitorious.org/qt/qtbase/blobs/master/src/corelib/global/qprocessordetection.h -# Currently handles arm (v5, v6, v7), x86 (32/64), ia64, and ppc (32/64) - -# Regarding POWER/PowerPC, just as is noted in the Qt source, -# "There are many more known variants/revisions that we do not handle/detect." - -set(archdetect_c_code " -#if defined(__arm__) || defined(__TARGET_ARCH_ARM) - #if defined(__ARM_ARCH_7__) \\ - || defined(__ARM_ARCH_7A__) \\ - || defined(__ARM_ARCH_7R__) \\ - || defined(__ARM_ARCH_7M__) \\ - || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 7) - #error cmake_ARCH armv7 - #elif defined(__ARM_ARCH_6__) \\ - || defined(__ARM_ARCH_6J__) \\ - || defined(__ARM_ARCH_6T2__) \\ - || defined(__ARM_ARCH_6Z__) \\ - || defined(__ARM_ARCH_6K__) \\ - || defined(__ARM_ARCH_6ZK__) \\ - || defined(__ARM_ARCH_6M__) \\ - || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 6) - #error cmake_ARCH armv6 - #elif defined(__ARM_ARCH_5TEJ__) \\ - || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 5) - #error cmake_ARCH armv5 - #else - #error cmake_ARCH arm - #endif -#elif defined(__i386) || defined(__i386__) || defined(_M_IX86) - #error cmake_ARCH i386 -#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) - #error cmake_ARCH x86_64 -#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64) - #error cmake_ARCH ia64 -#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\ - || defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \\ - || defined(_M_MPPC) || defined(_M_PPC) - #if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__) - #error cmake_ARCH ppc64 - #else - #error cmake_ARCH ppc - #endif -#endif - -#error cmake_ARCH unknown -") - -# Set ppc_support to TRUE before including this file or ppc and ppc64 -# will be treated as invalid architectures since they are no longer supported by Apple - -function(target_architecture output_var) - if(APPLE AND CMAKE_OSX_ARCHITECTURES) - # On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set - # First let's normalize the order of the values - - # Note that it's not possible to compile PowerPC applications if you are using - # the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we - # disable it by default - # See this page for more information: - # http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4 - - # Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime. - # On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise. - - foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES}) - if("${osx_arch}" STREQUAL "ppc" AND ppc_support) - set(osx_arch_ppc TRUE) - elseif("${osx_arch}" STREQUAL "i386") - set(osx_arch_i386 TRUE) - elseif("${osx_arch}" STREQUAL "x86_64") - set(osx_arch_x86_64 TRUE) - elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support) - set(osx_arch_ppc64 TRUE) - else() - message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}") - endif() - endforeach() - - # Now add all the architectures in our normalized order - if(osx_arch_ppc) - list(APPEND ARCH ppc) - endif() - - if(osx_arch_i386) - list(APPEND ARCH i386) - endif() - - if(osx_arch_x86_64) - list(APPEND ARCH x86_64) - endif() - - if(osx_arch_ppc64) - list(APPEND ARCH ppc64) - endif() - else() - file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}") - - enable_language(C) - - # Detect the architecture in a rather creative way... - # This compiles a small C program which is a series of ifdefs that selects a - # particular #error preprocessor directive whose message string contains the - # target architecture. The program will always fail to compile (both because - # file is not a valid C program, and obviously because of the presence of the - # #error preprocessor directives... but by exploiting the preprocessor in this - # way, we can detect the correct target architecture even when cross-compiling, - # since the program itself never needs to be run (only the compiler/preprocessor) - try_run( - run_result_unused - compile_result_unused - "${CMAKE_BINARY_DIR}" - "${CMAKE_BINARY_DIR}/arch.c" - COMPILE_OUTPUT_VARIABLE ARCH - CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} - ) - - # Parse the architecture name from the compiler output - string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}") - - # Get rid of the value marker leaving just the architecture name - string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}") - - # If we are compiling with an unknown architecture this variable should - # already be set to "unknown" but in the case that it's empty (i.e. due - # to a typo in the code), then set it to unknown - if (NOT ARCH) - set(ARCH unknown) - endif() - endif() - - set(${output_var} "${ARCH}" PARENT_SCOPE) -endfunction() diff --git a/cmake/check_warning_flag.cmake b/cmake/check_warning_flag.cmake new file mode 100644 index 00000000..c0da8bb9 --- /dev/null +++ b/cmake/check_warning_flag.cmake @@ -0,0 +1,9 @@ +include(CheckCXXSourceCompiles) + +function(check_warning_flag FLAG VAR) + set(SRC "int main() {}") + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS "-Werror -Wno-${FLAG}") + check_cxx_source_compiles(${SRC} ${VAR}) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) +endfunction() \ No newline at end of file diff --git a/cmake/coverage.cmake b/cmake/coverage.cmake new file mode 100644 index 00000000..78f1d140 --- /dev/null +++ b/cmake/coverage.cmake @@ -0,0 +1,16 @@ +function(enable_coverage TARGET) + if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + + if(APPLE) + set(COVERAGE_LIB "") + else() + set(COVERAGE_LIB -lgcov) + endif() + + set_target_properties(${TARGET} + PROPERTIES + COMPILE_FLAGS --coverage + LINK_FLAGS "${COVERAGE_LIB} --coverage" + ) + endif() +endfunction() diff --git a/cmake/msvc_support.cmake b/cmake/msvc_support.cmake new file mode 100644 index 00000000..a063bf8c --- /dev/null +++ b/cmake/msvc_support.cmake @@ -0,0 +1,55 @@ + +function(rpclib_msvc_support) + if(MSVC) + # When building via conan, respect the compilation settings. + if ("${CONAN_LINK_RUNTIME}" STREQUAL "/MT") + set(RPCLIB_MSVC_STATIC_RUNTIME ON) + endif() + + if(RPCLIB_ENABLE_COVERAGE) + message(FATAL_ERROR "Coverage is only supported with non-MS compilers") + endif() + + target_compile_definitions(${PROJECT_NAME} PRIVATE + "WIN32_LEAN_AND_MEAN" + "NOMINMAX" + "VC_EXTRALEAN" + "_CRT_SECURE_NO_WARNINGS" + "_CRT_NONSTDC_NO_DEPRECATE" + "_WIN32_WINNT=0x0501" + "_GNU_SOURCE" + "ASIO_HAS_STD_ADDRESSOF" + "ASIO_HAS_STD_ARRAY" + "ASIO_HAS_CSTDINT" + "ASIO_HAS_STD_SHARED_PTR" + "ASIO_HAS_STD_TYPE_TRAITS") + + # MSVC static runtime support + # + # While this pollutes global flags (when using add_library), you would not want to + # build with a disparity anyway. (also, CMake still has no support for this, so you + # would end up doing something like this yourself). + if (RPCLIB_MSVC_STATIC_RUNTIME) + set(variables + CMAKE_C_FLAGS_DEBUG + CMAKE_C_FLAGS_MINSIZEREL + CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_RELWITHDEBINFO + CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_MINSIZEREL + CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_RELWITHDEBINFO + ) + message(STATUS + "MSVC -> forcing use of statically-linked runtime." + ) + + foreach(variable ${variables}) + if(${variable} MATCHES "/MD") + string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}") + endif() + endforeach() + + endif() + endif() +endfunction() diff --git a/cmake/policies.cmake b/cmake/policies.cmake new file mode 100644 index 00000000..914d69a6 --- /dev/null +++ b/cmake/policies.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0054 NEW) + diff --git a/cmake/rpclibConfig.cmake.in b/cmake/rpclibConfig.cmake.in new file mode 100644 index 00000000..1f7c385f --- /dev/null +++ b/cmake/rpclibConfig.cmake.in @@ -0,0 +1,10 @@ +# Example usage: +# find_package(rpclib REQUIRED) +# add_executable(foo main.cpp) +# target_link_libraries(foo rpclib::rpc) + +@PACKAGE_INIT@ + +set(RPCLIB_VERSION @RPCLIB_VERSION_MAJOR@.@RPCLIB_VERSION_MINOR@.@RPCLIB_VERSION_PATCH@) + +include("${CMAKE_CURRENT_LIST_DIR}/rpclibTargets.cmake") diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..f5ca393c --- /dev/null +++ b/codecov.yml @@ -0,0 +1,7 @@ + +ignore: + - "include/rpc/msgpack" + - "dependencies" + +coverage: + precision: 2 diff --git a/conanfile.txt b/conanfile.txt new file mode 100644 index 00000000..0911f43d --- /dev/null +++ b/conanfile.txt @@ -0,0 +1,5 @@ +[requires] +cmake_installer/1.0@conan/stable + +[generators] +virtualenv diff --git a/dependencies/include/asio/impl/error_code.ipp b/dependencies/include/asio/impl/error_code.ipp index 68674f71..c256bb53 100644 --- a/dependencies/include/asio/impl/error_code.ipp +++ b/dependencies/include/asio/impl/error_code.ipp @@ -97,20 +97,18 @@ public: #if defined(__sun) || defined(__QNX__) || defined(__SYMBIAN32__) using namespace std; return strerror(value); -#elif defined(__MACH__) && defined(__APPLE__) \ - || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) \ - || defined(_AIX) || defined(__hpux) || defined(__osf__) \ - || defined(__ANDROID__) - char buf[256] = ""; - using namespace std; - strerror_r(value, buf, sizeof(buf)); - return buf; #else char buf[256] = ""; - return strerror_r(value, buf, sizeof(buf)); + using namespace std; + return strerror_result(strerror_r(value, buf, sizeof(buf)), buf); #endif #endif // defined(ASIO_WINDOWS) } + +private: + // Helper function to adapt the result from glibc's variant of strerror_r. + static const char* strerror_result(int, const char* s) { return s; } + static const char* strerror_result(const char* s, const char*) { return s; } }; } // namespace detail diff --git a/doc/Doxyfile b/doc/Doxyfile index c51f1ee0..91ac1d1f 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -772,6 +772,7 @@ RECURSIVE = YES # run. EXCLUDE = "../include/rpc/msgpack" +EXCLUDE += "../include/rpc/nonstd" # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded diff --git a/doc/mkdocs.yml b/doc/mkdocs.yml index 9c58a5dc..6353760f 100644 --- a/doc/mkdocs.yml +++ b/doc/mkdocs.yml @@ -1,7 +1,7 @@ docs_dir: pages site_name: rpclib -pages: +nav: - 'Home': 'index.md' - 'Guides': - 'Getting started': 'gettingstarted.md' @@ -23,6 +23,7 @@ markdown_extensions: - toc: permalink: False baselevel: 2 + toc_depth: 5 - admonition - attr_list - codehilite diff --git a/doc/pages/compiling.md b/doc/pages/compiling.md index 624be8a0..acae375e 100644 --- a/doc/pages/compiling.md +++ b/doc/pages/compiling.md @@ -30,6 +30,3 @@ There are some compilation options that affect the build output. These options c |`RPCLIB_BUILD_EXAMPLES` | ON | Builds the collection of example programs that demonstrate the features of `rpclib`. | `RPCLIB_ENABLE_LOGGING` | OFF |Enables the internal logging of `rpclib`. This slightly affects performance. Currently the logging is not very configurable (for example, everything goes to stdout), but there are plans to make it easier to integrate with your application. Use this feature for debugging purposes. |`RPCLIB_ENABLE_COVERAGE` | OFF | This enables passing the code coverage generation flag when building with g++. It is used on Travis to provide coverage monitoring in tandem with Coveralls.io. -|`RPCLIB_FORCE_M64` | OFF | Force -m64 for g++ and clang++. Your build tools must support cross-compilation if this is not your native environment. -|`RPCLIB_FORCE_M32` | OFF | Force -m32 for g++ and clang++. Your build tools must support cross-compilation if this is not your native environment. -|`RPCLIB_EXTRA_BUILD_FLAGS` | "" | Use this to pass extra flags to rpclib for building, such as `-fPIC`. Please note that I don't normally test and build with such flags diff --git a/doc/pages/cookbook.md b/doc/pages/cookbook.md index 75273c1b..df0c7374 100644 --- a/doc/pages/cookbook.md +++ b/doc/pages/cookbook.md @@ -270,6 +270,27 @@ int main() { } ``` +### Storing per-session data + +```cpp +#include +#include "rpc/server.h" +#include "rpc/this_session.h" + +int main() { + rpc::server srv(8080); // listen on TCP port 8080 + std::unordered_map data; + + srv.bind("store_me_maybe", [&](std::string const& value) { + auto id = rpc::this_session().id(); + data[id] = value; + }); + + srv.run(); // blocking call + return 0; +} +``` + ## Client examples ### Creating a client diff --git a/doc/pages/reference.md b/doc/pages/reference.md index 1e4c854b..ae8d0ca7 100644 --- a/doc/pages/reference.md +++ b/doc/pages/reference.md @@ -33,13 +33,14 @@ Use this class to connect to msgpack-rpc servers and call their exposed function | RPCLIB_MSGPACK::object_handle | [call](#classrpc_1_1client_1aedc166b5a80820be198ef134f522b049)(std::string const &func_name, Args... args) | std::future< RPCLIB_MSGPACK::object_handle > | [async_call](#classrpc_1_1client_1a2e3702a314c8c0a00bfac652b82d16cc)(std::string const &func_name, Args... args) | void | [send](#classrpc_1_1client_1a5f5ad1d1d0630178a51ae219cd831b44)(std::string const &func_name, Args... args) -| uint64_t | [get_timeout](#classrpc_1_1client_1a7976c427e3e0a87a15931737df624712)() const -| void | [set_timeout](#classrpc_1_1client_1adc950350ae3c955c38fe18d16a6fd6af)(uint64_t value) +| nonstd::optional< int64_t > | [get_timeout](#classrpc_1_1client_1a2c264af4d7169574452b9f968ffde87d)() const +| void | [set_timeout](#classrpc_1_1client_1af890e3067745861642e2ba1a65bebce6)(int64_t value) +| void | [clear_timeout](#classrpc_1_1client_1a89eeffaf87bf0470a65c9c8ca40562bb)() | connection_state | [get_connection_state](#classrpc_1_1client_1a710037bce0d9b80127a98eb6cd54caf1)() const | void | [wait_all_responses](#classrpc_1_1client_1ac37437bc05b70588c079079b957eb15f)() -

rpc::client::client

+#### rpc::client::client ```cpp rpc::client::client(std::string const &addr, uint16_t port); ``` @@ -55,7 +56,7 @@ Constructs a client. When a client is constructed, it initiates a connection asynchronically. This means that it will not block while the connection is established. However, when the first call is performed, it *might* block if the connection was not already established. -

rpc::client::~client

+#### rpc::client::~client ```cpp rpc::client::~client(); ``` @@ -66,7 +67,7 @@ Destructor. During destruction, the connection to the server is gracefully closed. This means that any outstanding reads and writes are completed first. -

rpc::client::call

+#### rpc::client::call ```cpp RPCLIB_MSGPACK::object_handle rpc::client::call(std::string const &func_name, Args... args); ``` @@ -85,7 +86,7 @@ Calls a function with the given name and arguments (if any). A RPCLIB_MSGPACK::object containing the result of the function (if any). To obtain a typed value, use the msgpack API. -

rpc::client::async_call

+#### rpc::client::async_call ```cpp std::future< RPCLIB_MSGPACK::object_handle > rpc::client::async_call(std::string const &func_name, Args... args); ``` @@ -107,7 +108,7 @@ A call is performed asynchronously in the context of the client, i.e. this is no A std::future, possibly holding a future result (which is a RPCLIB_MSGPACK::object). -

rpc::client::send

+#### rpc::client::send ```cpp void rpc::client::send(std::string const &func_name, Args... args); ``` @@ -128,9 +129,9 @@ Notifications are a special kind of calls. They can be used to notify the server !!! warn This function returns immediately (possibly before the notification is written to the socket). -

rpc::client::get_timeout

+#### rpc::client::get_timeout ```cpp -uint64_t rpc::client::get_timeout() const; +nonstd::optional< int64_t > rpc::client::get_timeout() const; ``` Returns the timeout setting of this client in milliseconds. @@ -141,15 +142,23 @@ The timeout is applied to synchronous calls. If the timeout expires without rece !!! warn The timeout has no effect on async calls. For those, the preferred timeout mechanism remains using std::future. -

rpc::client::set_timeout

+#### rpc::client::set_timeout ```cpp -void rpc::client::set_timeout(uint64_t value); +void rpc::client::set_timeout(int64_t value); ``` Sets the timeout for synchronous calls. For more information, see -

rpc::client::get_connection_state

+#### rpc::client::clear_timeout +```cpp +void rpc::client::clear_timeout(); +``` + +Clears the timeout for synchronous calls. For more information, see + + +#### rpc::client::get_connection_state ```cpp connection_state rpc::client::get_connection_state() const; ``` @@ -157,7 +166,7 @@ connection_state rpc::client::get_connection_state() const; Returns the current connection state. -

rpc::client::wait_all_responses

+#### rpc::client::wait_all_responses ```cpp void rpc::client::wait_all_responses(); ``` @@ -185,7 +194,7 @@ This type allows clients to handle arbitrary error objects as the msgpack-rpc sp | RPCLIB_MSGPACK::object_handle & | [get_error](#classrpc_1_1rpc__error_1a88ab8f211393ae62813042a797c08663)() -

rpc::rpc_error::get_function_name

+#### rpc::rpc_error::get_function_name ```cpp std::string rpc::rpc_error::get_function_name() const; ``` @@ -193,7 +202,7 @@ std::string rpc::rpc_error::get_function_name() const; Returns the name of the function that was called on the server while the error occurred. -

rpc::rpc_error::get_error

+#### rpc::rpc_error::get_error ```cpp RPCLIB_MSGPACK::object_handle & rpc::rpc_error::get_error(); ``` @@ -211,15 +220,17 @@ Returns the error object that the server provided. Implements a msgpack-rpc server. This is the main interfacing point with the library for creating servers. -The server maintains a registry of function bindings that it uses to dispatch calls. It also takes care of managing worker threads and TCP connections. The server does not start listening right after construction in order to allow binding functions before that. Use the `run` or `async_run` functions to start listening on the port. +The server maintains a registry of function bindings that it uses to dispatch calls. It also takes care of managing worker threads and TCP connections. The server does not start listening right after construction in order to allow binding functions before that. Use the `run` or `async_run` functions to start listening on the port. This class is not copyable, but moveable. ### Public functions | | | |---------|-------------| | | [server](#classrpc_1_1server_1ac406b44f73cf2ff17240c0cd926a9c1e)(uint16_t port) +| | [server](#classrpc_1_1server_1a744b961d3b151b3449a4e0da37bd471a)(server &&other) noexcept | | [server](#classrpc_1_1server_1ad71ffce076d752e116cefa3672e5d188)(std::string const &address, uint16_t port) | | [~server](#classrpc_1_1server_1a20b9197e5ef1a22371e6fbdb7f58b330)() +| server | [operator=](#classrpc_1_1server_1ac3cf4848fc3969cd26ba5e3bd2dc411b)(server &&other) | void | [run](#classrpc_1_1server_1a981d7e4a08d04d05cbac6770fab0dff8)() | void | [async_run](#classrpc_1_1server_1a462e032fa21cad78eeacc27da103a2b7)(std::size_t worker_threads=1) | void | [bind](#classrpc_1_1server_1a072135629430df6d5576416806f7b02c)(std::string const &name, F func) @@ -228,7 +239,7 @@ The server maintains a registry of function bindings that it uses to dispatch ca | void | [close_sessions](#classrpc_1_1server_1abf6bebbbeea52451aef2126d29240094)() -

rpc::server::server

+#### rpc::server::server ```cpp rpc::server::server(uint16_t port); ``` @@ -239,7 +250,18 @@ Constructs a server that listens on the localhost on the specified port. `port` The port number to listen on. -

rpc::server::server

+#### rpc::server::server +```cpp + rpc::server::server(server &&other) noexcept; +``` + +Move constructor. This is implemented by calling the move assignment operator. + +##### Parameters +`other` The other instance to move from. + + +#### rpc::server::server ```cpp rpc::server::server(std::string const &address, uint16_t port); ``` @@ -247,10 +269,12 @@ Constructs a server that listens on the localhost on the specified port. Constructs a server that listens on the specified address on the specified port. ##### Parameters +`address` The address to bind to. This only works if oee of your network adapaters control the given address. + `port` The port number to listen on. -

rpc::server::~server

+#### rpc::server::~server ```cpp rpc::server::~server(); ``` @@ -261,7 +285,21 @@ Destructor. When the server is destroyed, all ongoin sessions are closed gracefully. -

rpc::server::run

+#### rpc::server::operator= +```cpp +server rpc::server::operator=(server &&other); +``` + +Move assignment operator. + +##### Parameters +`other` The other instance to move from. + +##### Return value +The result of the assignment. + + +#### rpc::server::run ```cpp void rpc::server::run(); ``` @@ -269,10 +307,10 @@ void rpc::server::run(); Starts the server loop. This is a blocking call. ##### Details -First and foremost, running the event loop causes the server to start listening on the specified port. Also, as connections are established and calls are made by clients, the server executes the calls as part of this call. This means that the handlers are executed on the thread that calls `run`. Reads and writes are initiated by this function +First and foremost, running the event loop causes the server to start listening on the specified port. Also, as connections are established and calls are made by clients, the server executes the calls as part of this call. This means that the handlers are executed on the thread that calls `run`. Reads and writes are initiated by this function internally as well. -

rpc::server::async_run

+#### rpc::server::async_run ```cpp void rpc::server::async_run(std::size_t worker_threads=1); ``` @@ -286,7 +324,7 @@ Starts the server loop on one or more threads. This is a non-blocking call. This function behaves similarly to `run`, except the event loop is optionally started on different threads. Effectively this sets up a worker thread pool for the server. Handlers will be executed on one of the threads. -

rpc::server::bind

+#### rpc::server::bind ```cpp void rpc::server::bind(std::string const &name, F func); ``` @@ -305,7 +343,7 @@ Binds a functor to a name so it becomes callable via RPC. This function template accepts a wide range of callables. The arguments and return types of these callables should be serializable by msgpack. `bind` effectively generates a suitable, light-weight compile-time wrapper for the functor. -

rpc::server::suppress_exceptions

+#### rpc::server::suppress_exceptions ```cpp void rpc::server::suppress_exceptions(bool suppress); ``` @@ -315,7 +353,7 @@ Sets the exception behavior in handlers. By default, handlers throwing will cras !!! warn Setting this flag only affects subsequent connections. -

rpc::server::stop

+#### rpc::server::stop ```cpp void rpc::server::stop(); ``` @@ -325,7 +363,7 @@ Stops the server. !!! warn This should not be called from worker threads. -

rpc::server::close_sessions

+#### rpc::server::close_sessions ```cpp void rpc::server::close_sessions(); ``` @@ -356,7 +394,7 @@ Encapsulates information about the currently executing handler. This is the inte | void | [clear](#classrpc_1_1this__handler__t_1a0a53e27b4d8d5b542790b218029d26f4)() -

rpc::this_handler_t::respond_error

+#### rpc::this_handler_t::respond_error ```cpp void rpc::this_handler_t::respond_error(T &&err_obj); ``` @@ -370,7 +408,7 @@ Sets an arbitrary object to be sent back as an error response to the client. `err_obj` The error object. This can be anything that is possible to encode with messagepack (even custom structures). -

rpc::this_handler_t::respond

+#### rpc::this_handler_t::respond ```cpp void rpc::this_handler_t::respond(T &&resp_obj); ``` @@ -386,7 +424,7 @@ Sets an arbitrary object to be sent back as the response to the call. !!! warn The normal return value of the function (if any) will be ignored if a special response is set. -

rpc::this_handler_t::disable_response

+#### rpc::this_handler_t::disable_response ```cpp void rpc::this_handler_t::disable_response(); ``` @@ -396,7 +434,7 @@ Instructs the server to not send a response to the client (ignoring any errors a !!! warn It is unusual to not send a response to requests, and doing so might cause problems in the client (depending on its implementation). -

rpc::this_handler_t::enable_response

+#### rpc::this_handler_t::enable_response ```cpp void rpc::this_handler_t::enable_response(); ``` @@ -404,7 +442,7 @@ void rpc::this_handler_t::enable_response(); Enables sending a response to the call. Sending the response is by default enabled. Enabling the response multiple times have no effect. -

rpc::this_handler_t::clear

+#### rpc::this_handler_t::clear ```cpp void rpc::this_handler_t::clear(); ``` @@ -432,7 +470,7 @@ Allows controlling the server instance from the currently executing handler. | void | [cancel_stop](#classrpc_1_1this__server__t_1a127035c6f2281a5a1bfadf19f4dfe451)() -

rpc::this_server_t::stop

+#### rpc::this_server_t::stop ```cpp void rpc::this_server_t::stop(); ``` @@ -440,7 +478,7 @@ void rpc::this_server_t::stop(); Gracefully stops the server. -

rpc::this_server_t::cancel_stop

+#### rpc::this_server_t::cancel_stop ```cpp void rpc::this_server_t::cancel_stop(); ``` @@ -465,9 +503,10 @@ Encapsulates information about the server session/connection this handler is run | | | |---------|-------------| | void | [post_exit](#classrpc_1_1this__session__t_1ae0551bc44674bdd43e33a4d4a36781b0)() +| session_id_t | [id](#classrpc_1_1this__session__t_1aada2250ec9dd3d88781ca16eb4352047)() const -

rpc::this_session_t::post_exit

+#### rpc::this_session_t::post_exit ```cpp void rpc::this_session_t::post_exit(); ``` @@ -477,15 +516,25 @@ Gracefully exits the session (i.e. ongoing writes and reads are completed; queue !!! warn Use this function if you need to close the connection from a handler. +#### rpc::this_session_t::id +```cpp +session_id_t rpc::this_session_t::id() const; +``` + +Returns an ID that uniquely identifies a session. + +!!! warn + This is not an ID for the client. If the client disconnects and reconnects, this ID may change. That being said, you can use this ID to store client-specific information *for the duration of the session. + ## rpc::timeout ```cpp -#include "" +#include "rpc/rpc_error.h" ``` ### Description - +This exception is thrown by the client when either the connection or a call takes more time than it is set in set_timeout. @@ -496,12 +545,12 @@ Gracefully exits the session (i.e. ongoing writes and reads are completed; queue | const char * | [what](#classrpc_1_1timeout_1ad782f083798c650188b5927a226c3b04)() const noexcept override -

rpc::timeout::what

+#### rpc::timeout::what ```cpp const char * rpc::timeout::what() const noexcept override; ``` - +Describes the exception. diff --git a/doc/pages/versions.md b/doc/pages/versions.md index 971a2108..b56c57bc 100644 --- a/doc/pages/versions.md +++ b/doc/pages/versions.md @@ -1,4 +1,4 @@ -You are reading the documentation of 2.1.0. +You are reading the documentation of 2.3.0. If, for some reason you need the documentation of older versions, you can download them from this page. * [1.0.0](/archive/rpclib_docs_1.0.0.zip) diff --git a/doc/pages/versions.md.in b/doc/pages/versions.md.in index c8d2adff..7095b418 100644 --- a/doc/pages/versions.md.in +++ b/doc/pages/versions.md.in @@ -1,4 +1,4 @@ -You are reading the documentation of @RPCLIB_VERSION_MAJOR@.@RPCLIB_VERSION_MINOR@.@RPCLIB_VERSION_PATCH@. +You are reading the documentation of @rpc_VERSION_MAJOR@.@rpc_VERSION_MINOR@.@rpc_VERSION_PATCH@. If, for some reason you need the documentation of older versions, you can download them from this page. * [1.0.0](/archive/rpclib_docs_1.0.0.zip) \ No newline at end of file diff --git a/doc/reference.md.mako b/doc/reference.md.mako index 49c62b5f..07c4806d 100644 --- a/doc/reference.md.mako +++ b/doc/reference.md.mako @@ -41,7 +41,7 @@ ${"### Public functions"} % for f in c.functions: -

${c.name}::${f.name}

+${"#### "}${c.name}::${f.name} ```cpp ${opt(f.type)} ${c.name}::${f.name}${f.argsstr}; ``` diff --git a/doc/requirements.txt b/doc/requirements.txt index 2767e397..472c5dd8 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -1,4 +1,22 @@ lxml>=3.6.4 Mako>=1.0.4 -mkdocs +mkdocs>=1.0.0 pygments +xsltproc +docker + + +# Manage Docker as non-root user +https://docs.docker.com/engine/install/linux-postinstall/ + +$ sudo groupadd docker +$ sudo usermod -aG docker $USER + +# log out and in to reevaluate user groups or +$ newgrp docker + +# Verify that you can run docker commands without sudo. +$ docker run hello-world + +# If mkdocs serve is used, this is required as well +mkdocs-material diff --git a/examples/calculator/CMakeLists.txt b/examples/calculator/CMakeLists.txt index 9e08a4ef..b56e391b 100644 --- a/examples/calculator/CMakeLists.txt +++ b/examples/calculator/CMakeLists.txt @@ -2,11 +2,12 @@ cmake_minimum_required(VERSION 3.0.0) project(calculator) find_package(rpclib REQUIRED) +find_package(Threads REQUIRED) include_directories(${RPCLIB_INCLUDE_DIR}) add_executable(calculator_server calculator_server.cc) -target_link_libraries(calculator_server ${RPCLIB_LIBS}) +target_link_libraries(calculator_server ${RPCLIB_LIBS} ${CMAKE_THREAD_LIBS_INIT}) set_target_properties( calculator_server PROPERTIES @@ -15,7 +16,7 @@ set_target_properties( target_compile_definitions(calculator_server PUBLIC ${RPCLIB_COMPILE_DEFINITIONS}) add_executable(calculator_client calculator_client.cc) -target_link_libraries(calculator_client ${RPCLIB_LIBS}) +target_link_libraries(calculator_client ${RPCLIB_LIBS} ${CMAKE_THREAD_LIBS_INIT}) set_target_properties( calculator_client PROPERTIES diff --git a/examples/echo/CMakeLists.txt b/examples/echo/CMakeLists.txt index a84839ef..987c5055 100644 --- a/examples/echo/CMakeLists.txt +++ b/examples/echo/CMakeLists.txt @@ -2,11 +2,12 @@ cmake_minimum_required(VERSION 3.0.0) project(echo) find_package(rpclib REQUIRED) +find_package(Threads REQUIRED) include_directories(${RPCLIB_INCLUDE_DIR}) add_executable(echo_server echo_server.cc) -target_link_libraries(echo_server ${RPCLIB_LIBS}) +target_link_libraries(echo_server ${RPCLIB_LIBS} ${CMAKE_THREAD_LIBS_INIT}) set_target_properties( echo_server PROPERTIES @@ -15,7 +16,7 @@ set_target_properties( target_compile_definitions(echo_server PUBLIC ${RPCLIB_COMPILE_DEFINITIONS}) add_executable(echo_client echo_client.cc) -target_link_libraries(echo_client ${RPCLIB_LIBS}) +target_link_libraries(echo_client ${RPCLIB_LIBS} ${CMAKE_THREAD_LIBS_INIT}) set_target_properties( echo_client PROPERTIES diff --git a/examples/echo/echo_server.cc b/examples/echo/echo_server.cc index 6988bbdc..3c59e155 100644 --- a/examples/echo/echo_server.cc +++ b/examples/echo/echo_server.cc @@ -1,7 +1,9 @@ #include "rpc/server.h" +#include int main() { rpc::server srv(rpc::constants::DEFAULT_PORT); + std::cout << "registered on port " << srv.port() << std::endl; srv.bind("echo", [](std::string const& s) { return s; diff --git a/examples/mandelbrot/mandelbrot.h b/examples/mandelbrot/mandelbrot.h index 0a6f9260..e0f52315 100644 --- a/examples/mandelbrot/mandelbrot.h +++ b/examples/mandelbrot/mandelbrot.h @@ -3,7 +3,7 @@ #ifndef MANDELBROT_H_I0UEF3KR #define MANDELBROT_H_I0UEF3KR -#include "msgpack.hpp" +#include "rpc/msgpack.hpp" #include struct pixel { diff --git a/include/rpc/client.h b/include/rpc/client.h index d2ee42e3..fcd16ebe 100644 --- a/include/rpc/client.h +++ b/include/rpc/client.h @@ -88,7 +88,7 @@ class client { //! //! \param func_name The name of the notification to call. //! \param args The arguments to pass to the function. - //! \tparam Args THe types of the arguments. + //! \tparam Args The types of the arguments. //! //! \note This function returns immediately (possibly before the //! notification is written to the socket). @@ -108,9 +108,13 @@ class client { nonstd::optional get_timeout() const; //! \brief Sets the timeout for synchronous calls. For more information, - //! see client::get_timeout(). + //! see get_timeout(). void set_timeout(int64_t value); + //! \brief Clears the timeout for synchronous calls. For more information, + //! see get_timeout(). + void clear_timeout(); + //! \brief Enum representing the connection states of the client. enum class connection_state { initial, connected, disconnected, reset }; diff --git a/include/rpc/client.inl b/include/rpc/client.inl index 04dc825b..f980f069 100644 --- a/include/rpc/client.inl +++ b/include/rpc/client.inl @@ -47,7 +47,7 @@ client::async_call(std::string const &func_name, Args... args) { //! \param args The arguments to pass to the function. //! \note This function returns when the notification is written to the //! socket. -//! \tparam Args THe types of the arguments. +//! \tparam Args The types of the arguments. template void client::send(std::string const &func_name, Args... args) { RPCLIB_CREATE_LOG_CHANNEL(client) diff --git a/include/rpc/config.h b/include/rpc/config.h index 06890879..f0611e34 100644 --- a/include/rpc/config.h +++ b/include/rpc/config.h @@ -11,6 +11,8 @@ namespace rpc { +using session_id_t = std::intptr_t; + //! \brief Constants used in the library struct constants RPCLIB_FINAL { static RPCLIB_CONSTEXPR std::size_t DEFAULT_BUFFER_SIZE = 1024 << 10; @@ -30,7 +32,7 @@ struct constants RPCLIB_FINAL { #endif /* ifndef RPCLIB_MSGPACK */ #ifndef RPCLIB_CXX_STANDARD -#define RPCLIB_CXX_STANDARD 14 +#define RPCLIB_CXX_STANDARD 11 #endif #endif /* end of include guard: CONFIG_H_L7IVDSPZ */ diff --git a/include/rpc/config.h.in b/include/rpc/config.h.in index f344fede..d0538d01 100644 --- a/include/rpc/config.h.in +++ b/include/rpc/config.h.in @@ -11,6 +11,8 @@ namespace rpc { +using session_id_t = std::intptr_t; + //! \brief Constants used in the library struct constants RPCLIB_FINAL { static RPCLIB_CONSTEXPR std::size_t DEFAULT_BUFFER_SIZE = @RPCLIB_DEFAULT_BUFFER_SIZE@; diff --git a/include/rpc/detail/async_writer.h b/include/rpc/detail/async_writer.h index 9977cdce..508500a7 100644 --- a/include/rpc/detail/async_writer.h +++ b/include/rpc/detail/async_writer.h @@ -23,6 +23,27 @@ class async_writer : public std::enable_shared_from_this { RPCLIB_ASIO::ip::tcp::socket socket) : socket_(std::move(socket)), write_strand_(*io), exit_(false) {} + void close() { + exit_ = true; + + auto self = shared_from_this(); + write_strand_.post([this, self]() { + LOG_INFO("Closing socket"); + std::error_code e; + socket_.shutdown( + RPCLIB_ASIO::ip::tcp::socket::shutdown_both, e); + if (e) { + LOG_WARN("std::system_error during socket shutdown. " + "Code: {}. Message: {}", e.value(), e.message()); + } + socket_.close(); + }); + } + + bool is_closed() const { + return exit_.load(); + } + void do_write() { if (exit_) { return; @@ -46,13 +67,6 @@ class async_writer : public std::enable_shared_from_this { } else { LOG_ERROR("Error while writing to socket: {}", ec); } - - if (exit_) { - LOG_INFO("Closing socket"); - socket_.shutdown( - RPCLIB_ASIO::ip::tcp::socket::shutdown_both); - socket_.close(); - } })); } @@ -65,7 +79,9 @@ class async_writer : public std::enable_shared_from_this { do_write(); } - friend class rpc::client; + RPCLIB_ASIO::ip::tcp::socket& socket() { + return socket_; + } protected: template @@ -73,15 +89,14 @@ class async_writer : public std::enable_shared_from_this { return std::static_pointer_cast(shared_from_this()); } -protected: + RPCLIB_ASIO::strand& write_strand() { + return write_strand_; + } + +private: RPCLIB_ASIO::ip::tcp::socket socket_; RPCLIB_ASIO::strand write_strand_; std::atomic_bool exit_{false}; - bool exited_ = false; - std::mutex m_exit_; - std::condition_variable cv_exit_; - -private: std::deque write_queue_; RPCLIB_CREATE_LOG_CHANNEL(async_writer) }; diff --git a/include/rpc/detail/log.h b/include/rpc/detail/log.h index 0d5e51c6..09db735a 100644 --- a/include/rpc/detail/log.h +++ b/include/rpc/detail/log.h @@ -83,11 +83,19 @@ class logger { std::stringstream ss; timespec now_t = {}; clock_gettime(CLOCK_REALTIME, &now_t); +#if __GNUC__ >= 5 ss << std::put_time( std::localtime(reinterpret_cast(&now_t.tv_sec)), "%F %T") - << RPCLIB_FMT::format( +#else + char mltime[128]; + strftime(mltime, sizeof(mltime), "%c %Z", + std::localtime(reinterpret_cast(&now_t.tv_sec))); + ss << mltime +#endif + << RPCLIB_FMT::format( ".{:03}", round(static_cast(now_t.tv_nsec) / 1.0e6)); + return ss.str(); } #endif diff --git a/include/rpc/dispatcher.h b/include/rpc/dispatcher.h index 8044d4cb..18dca30f 100644 --- a/include/rpc/dispatcher.h +++ b/include/rpc/dispatcher.h @@ -60,6 +60,19 @@ class dispatcher { detail::tags::nonvoid_result const &, detail::tags::nonzero_arg const &); + //! \brief Unbind a functor with a given name from callable functors. + void unbind(std::string const &name) { + funcs_.erase(name); + } + + //! \brief returns a list of all names which functors are binded to + std::vector names() const { + std::vector names; + for(auto it = funcs_.begin(); it != funcs_.end(); ++it) + names.push_back(it->first); + return names; + } + //! @} //! \brief Processes a message that contains a call according to diff --git a/include/rpc/dispatcher.inl b/include/rpc/dispatcher.inl index 1380bc59..0d5e413c 100644 --- a/include/rpc/dispatcher.inl +++ b/include/rpc/dispatcher.inl @@ -34,7 +34,7 @@ void dispatcher::bind(std::string const &name, F func, constexpr int args_count = std::tuple_size::value; enforce_arg_count(name, args_count, args.via.array.size); args_type args_real; - args.convert(&args_real); + args.convert(args_real); detail::call(func, args_real); return rpc::detail::make_unique(); })); @@ -69,7 +69,7 @@ void dispatcher::bind(std::string const &name, F func, constexpr int args_count = std::tuple_size::value; enforce_arg_count(name, args_count, args.via.array.size); args_type args_real; - args.convert(&args_real); + args.convert(args_real); auto z = rpc::detail::make_unique(); auto result = RPCLIB_MSGPACK::object(detail::call(func, args_real), *z); return rpc::detail::make_unique(result, std::move(z)); diff --git a/include/rpc/msgpack.hpp b/include/rpc/msgpack.hpp index fbb58ca7..a99073b5 100644 --- a/include/rpc/msgpack.hpp +++ b/include/rpc/msgpack.hpp @@ -29,3 +29,4 @@ #include "rpc/msgpack/vrefbuffer.hpp" #include "rpc/msgpack/version.hpp" #include "rpc/msgpack/type.hpp" + diff --git a/include/rpc/msgpack/adaptor/adaptor_base.hpp b/include/rpc/msgpack/adaptor/adaptor_base.hpp index 70f19b0c..0f221f2f 100644 --- a/include/rpc/msgpack/adaptor/adaptor_base.hpp +++ b/include/rpc/msgpack/adaptor/adaptor_base.hpp @@ -1,92 +1,18 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2015 KONDO Takatoshi +// Copyright (C) 2015-2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_HPP #define MSGPACK_ADAPTOR_BASE_HPP -#include "rpc/msgpack/object_fwd.hpp" - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -template -class packer; - -namespace adaptor { - -// Adaptor functors - -template -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, T& v) const; -}; - -template -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, T const& v) const; -}; - -template -struct object { - void operator()(clmdep_msgpack::object& o, T const& v) const; -}; - -template -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, T const& v) const; -}; - -} // namespace adaptor - -// operators - -template -inline -clmdep_msgpack::object const& operator>> (clmdep_msgpack::object const& o, T& v) { - return adaptor::convert()(o, v); -} - -template -inline -clmdep_msgpack::packer& operator<< (clmdep_msgpack::packer& o, T const& v) { - return adaptor::pack()(o, v); -} - -template -inline -void operator<< (clmdep_msgpack::object& o, T const& v) { - adaptor::object()(o, v); -} - -template -inline -void operator<< (clmdep_msgpack::object::with_zone& o, T const& v) { - adaptor::object_with_zone()(o, v); -} - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace clmdep_msgpack +#include "rpc/msgpack/adaptor/adaptor_base_decl.hpp" +#include "rpc/msgpack/v1/adaptor/adaptor_base.hpp" +#include "rpc/msgpack/v2/adaptor/adaptor_base.hpp" #endif // MSGPACK_ADAPTOR_BASE_HPP diff --git a/include/rpc/msgpack/adaptor/adaptor_base_decl.hpp b/include/rpc/msgpack/adaptor/adaptor_base_decl.hpp new file mode 100644 index 00000000..2915933d --- /dev/null +++ b/include/rpc/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 "rpc/msgpack/v1/adaptor/adaptor_base_decl.hpp" +#include "rpc/msgpack/v2/adaptor/adaptor_base_decl.hpp" + +#endif // MSGPACK_ADAPTOR_BASE_DECL_HPP diff --git a/include/rpc/msgpack/adaptor/array_ref.hpp b/include/rpc/msgpack/adaptor/array_ref.hpp index 393fc906..ddf8dfa9 100644 --- a/include/rpc/msgpack/adaptor/array_ref.hpp +++ b/include/rpc/msgpack/adaptor/array_ref.hpp @@ -1,182 +1,17 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2009 FURUHASHI Sadayuki +// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_HPP #define MSGPACK_TYPE_ARRAY_REF_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" -#include -#include - -namespace clmdep_msgpack { - -/// @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 > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, clmdep_msgpack::type::array_ref& v) const { - if (!v.data) { throw clmdep_msgpack::type_error(); } - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - if (v.data->size() < o.via.bin.size) { throw clmdep_msgpack::type_error(); } - if (o.via.array.size > 0) { - clmdep_msgpack::object* p = o.via.array.ptr; - clmdep_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 > > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, clmdep_msgpack::type::array_ref >& v) const { - if (!v.data) { throw clmdep_msgpack::type_error(); } - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - v.data->resize(o.via.bin.size); - if (o.via.array.size > 0) { - clmdep_msgpack::object* p = o.via.array.ptr; - clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const clmdep_msgpack::type::array_ref& v) const { - if (!v.data) { throw clmdep_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()(clmdep_msgpack::object::with_zone& o, const clmdep_msgpack::type::array_ref& v) const { - if (!v.data) { throw clmdep_msgpack::type_error(); } - o.type = clmdep_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()); - clmdep_msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size)); - clmdep_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 = clmdep_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 +#include "rpc/msgpack/adaptor/array_ref_decl.hpp" -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/array_ref.hpp" -#endif // MSGPACK_TYPE_ARRAY_REF_HPP +#endif // MSGPACK_TYPE_ARRAY_REFL_HPP diff --git a/include/rpc/msgpack/adaptor/array_ref_decl.hpp b/include/rpc/msgpack/adaptor/array_ref_decl.hpp new file mode 100644 index 00000000..550e24e7 --- /dev/null +++ b/include/rpc/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 "rpc/msgpack/v1/adaptor/array_ref_decl.hpp" +#include "rpc/msgpack/v2/adaptor/array_ref_decl.hpp" + +#endif // MSGPACK_TYPE_ARRAY_REF_DECL_HPP diff --git a/include/rpc/msgpack/adaptor/bool.hpp b/include/rpc/msgpack/adaptor/bool.hpp index f5867ca3..02b4c3f2 100644 --- a/include/rpc/msgpack/adaptor/bool.hpp +++ b/include/rpc/msgpack/adaptor/bool.hpp @@ -1,74 +1,15 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2009 FURUHASHI Sadayuki +// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_BOOL_HPP #define MSGPACK_TYPE_BOOL_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, bool& v) const { - if(o.type != clmdep_msgpack::type::BOOLEAN) { throw clmdep_msgpack::type_error(); } - v = o.via.boolean; - return o; - } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const bool& v) const { - if(v) { o.pack_true(); } - else { o.pack_false(); } - return o; - } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, bool v) const { - o.type = clmdep_msgpack::type::BOOLEAN; - o.via.boolean = v; - } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, bool v) const { - static_cast(o) << v; - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/bool.hpp" #endif // MSGPACK_TYPE_BOOL_HPP diff --git a/include/rpc/msgpack/adaptor/boost/fusion.hpp b/include/rpc/msgpack/adaptor/boost/fusion.hpp index 98085f2b..d44f517d 100644 --- a/include/rpc/msgpack/adaptor/boost/fusion.hpp +++ b/include/rpc/msgpack/adaptor/boost/fusion.hpp @@ -3,166 +3,13 @@ // // Copyright (C) 2015 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_FUSION_HPP #define MSGPACK_TYPE_BOOST_FUSION_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" -#include "rpc/msgpack/meta.hpp" - -#if !defined (MSGPACK_USE_CPP03) -#include "rpc/msgpack/adaptor/cpp11/tuple.hpp" -#endif // #if !defined (MSGPACK_USE_CPP03) - -#include -#include -#include -#include -#include -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -#if !defined (MSGPACK_USE_CPP03) - -template -struct as< - T, - typename clmdep_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, - clmdep_msgpack::has_as - >, - boost::mpl::bool_, - boost::mpl::bool_ - > - >::type::value - >::type -> { - T operator()(clmdep_msgpack::object const& o) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - if (o.via.array.size != checked_get_container_size(boost::mpl::size::value)) { - throw clmdep_msgpack::type_error(); - } - using tuple_t = decltype(to_tuple(std::declval(), gen_seq::value>())); - return to_t( - o.as(), - clmdep_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 > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, T& v) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - if (o.via.array.size != checked_get_container_size(boost::fusion::size(v))) { - throw clmdep_msgpack::type_error(); - } - uint32_t index = 0; - boost::fusion::for_each(v, convert_imp(o, index)); - return o; - } -private: - struct convert_imp { - convert_imp(clmdep_msgpack::object const& obj, uint32_t& index):obj_(obj), index_(index) {} - template - void operator()(U& v) const { - clmdep_msgpack::adaptor::convert()(obj_.via.array.ptr[index_++], v); - } - private: - clmdep_msgpack::object const& obj_; - uint32_t& index_; - }; -}; - -template -struct pack::value>::type > { - template - clmdep_msgpack::packer& operator()(clmdep_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(clmdep_msgpack::packer& stream):stream_(stream) {} - template - void operator()(U const& v) const { - stream_.pack(v); - } - private: - clmdep_msgpack::packer& stream_; - }; -}; - -template -struct object_with_zone::value>::type > { - void operator()(clmdep_msgpack::object::with_zone& o, const T& v) const { - uint32_t size = checked_get_container_size(boost::fusion::size(v)); - o.type = clmdep_msgpack::type::ARRAY; - o.via.array.ptr = static_cast(o.zone.allocate_align(sizeof(clmdep_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(clmdep_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_++] = clmdep_msgpack::object(v, obj_.zone); - } - clmdep_msgpack::object::with_zone const& obj_; - uint32_t& count_; - }; -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/boost/fusion.hpp" #endif // MSGPACK_TYPE_BOOST_FUSION_HPP diff --git a/include/rpc/msgpack/adaptor/boost/msgpack_variant.hpp b/include/rpc/msgpack/adaptor/boost/msgpack_variant.hpp index 7dbd2bec..128c3c0f 100644 --- a/include/rpc/msgpack/adaptor/boost/msgpack_variant.hpp +++ b/include/rpc/msgpack/adaptor/boost/msgpack_variant.hpp @@ -1,438 +1,18 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2015 KONDO Takatoshi +// Copyright (C) 2015-2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_HPP #define MSGPACK_TYPE_BOOST_MSGPACK_VARIANT_HPP -#if defined(MSGPACK_USE_BOOST) - -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" -#include "rpc/msgpack/adaptor/boost/string_ref.hpp" - -#include "rpc/msgpack/adaptor/nil.hpp" -#include "rpc/msgpack/adaptor/bool.hpp" -#include "rpc/msgpack/adaptor/int.hpp" -#include "rpc/msgpack/adaptor/float.hpp" -#include "rpc/msgpack/adaptor/string.hpp" -#include "rpc/msgpack/adaptor/vector_char.hpp" -#include "rpc/msgpack/adaptor/raw.hpp" -#include "rpc/msgpack/adaptor/ext.hpp" -#include "rpc/msgpack/adaptor/vector.hpp" -#include "rpc/msgpack/adaptor/map.hpp" - -#include -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace type { - - -template -struct basic_variant : - boost::variant< - nil, // 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 - clmdep_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, // 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 - clmdep_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 > { - clmdep_msgpack::type::basic_variant operator()(clmdep_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, clmdep_msgpack::type::basic_variant > >(); - default: - break; - } - return clmdep_msgpack::type::basic_variant(); - } -}; - -#endif // !defined (MSGPACK_USE_CPP03) - - -template -struct convert > { - clmdep_msgpack::object const& operator()( - clmdep_msgpack::object const& o, - clmdep_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, clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const clmdep_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()(clmdep_msgpack::type::nil 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 clmdep_msgpack::type_error(); - } - object_imp(clmdep_msgpack::object& o):o_(o) {} - clmdep_msgpack::object& o_; -}; - -} // namespace detail - -template -struct object > { - void operator()(clmdep_msgpack::object& o, const clmdep_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(clmdep_msgpack::object::with_zone& o):o_(o) {} - clmdep_msgpack::object::with_zone& o_; -}; - -} // namespace detail - -template -struct object_with_zone > { - void operator()(clmdep_msgpack::object::with_zone& o, const clmdep_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 +#include "rpc/msgpack/adaptor/boost/msgpack_variant_decl.hpp" -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/boost/msgpack_variant.hpp" +//#include "rpc/msgpack/v2/adaptor/boost/msgpack_variant.hpp" -#endif // MSGPACK_USE_BOOST #endif // MSGPACK_TYPE_BOOST_MSGPACK_VARIANT_HPP diff --git a/include/rpc/msgpack/adaptor/boost/msgpack_variant_decl.hpp b/include/rpc/msgpack/adaptor/boost/msgpack_variant_decl.hpp new file mode 100644 index 00000000..258967b3 --- /dev/null +++ b/include/rpc/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 "rpc/msgpack/v1/adaptor/boost/msgpack_variant_decl.hpp" +#include "rpc/msgpack/v2/adaptor/boost/msgpack_variant_decl.hpp" + +#endif // MSGPACK_TYPE_BOOST_MSGPACK_VARIANT_DECL_HPP diff --git a/include/rpc/msgpack/adaptor/boost/optional.hpp b/include/rpc/msgpack/adaptor/boost/optional.hpp index 74f7908e..26d0a8b7 100644 --- a/include/rpc/msgpack/adaptor/boost/optional.hpp +++ b/include/rpc/msgpack/adaptor/boost/optional.hpp @@ -1,104 +1,15 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2015 KONDO Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_OPTIONAL_HPP #define MSGPACK_TYPE_BOOST_OPTIONAL_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -// To supress 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 clmdep_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()(clmdep_msgpack::object const& o) const { - if(o.is_nil()) return boost::none; - return o.as(); - } -}; - -#endif // !defined (MSGPACK_USE_CPP03) - -template -struct convert > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, boost::optional& v) const { - if(o.is_nil()) v = boost::none; - else { - T t; - clmdep_msgpack::adaptor::convert()(o, t); - v = t; - } - return o; - } -}; - -template -struct pack > { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const boost::optional& v) const { - if (v) o.pack(*v); - else o.pack_nil(); - return o; - } -}; - -template -struct object > { - void operator()(clmdep_msgpack::object& o, const boost::optional& v) const { - if (v) clmdep_msgpack::adaptor::object()(o, *v); - else o.type = clmdep_msgpack::type::NIL; - } -}; - -template -struct object_with_zone > { - void operator()(clmdep_msgpack::object::with_zone& o, const boost::optional& v) const { - if (v) clmdep_msgpack::adaptor::object_with_zone()(o, *v); - else o.type = clmdep_msgpack::type::NIL; - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/boost/optional.hpp" #endif // MSGPACK_TYPE_BOOST_OPTIONAL_HPP diff --git a/include/rpc/msgpack/adaptor/boost/string_ref.hpp b/include/rpc/msgpack/adaptor/boost/string_ref.hpp index 6dea3da5..d487b061 100644 --- a/include/rpc/msgpack/adaptor/boost/string_ref.hpp +++ b/include/rpc/msgpack/adaptor/boost/string_ref.hpp @@ -1,95 +1,15 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2015 KONDO Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_STRING_REF_HPP #define MSGPACK_TYPE_BOOST_STRING_REF_HPP -#include -#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 - -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, boost::string_ref& v) const { - switch (o.type) { - case clmdep_msgpack::type::BIN: - v = boost::string_ref(o.via.bin.ptr, o.via.bin.size); - break; - case clmdep_msgpack::type::STR: - v = boost::string_ref(o.via.str.ptr, o.via.str.size); - break; - default: - throw clmdep_msgpack::type_error(); - break; - } - return o; - } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object& o, const boost::string_ref& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = clmdep_msgpack::type::STR; - o.via.str.ptr = v.data(); - o.via.str.size = size; - } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_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 clmdep_msgpack - -#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 +#include "rpc/msgpack/v1/adaptor/boost/string_ref.hpp" #endif // MSGPACK_TYPE_BOOST_STRING_REF_HPP diff --git a/include/rpc/msgpack/adaptor/boost/string_view.hpp b/include/rpc/msgpack/adaptor/boost/string_view.hpp new file mode 100644 index 00000000..fde49a5b --- /dev/null +++ b/include/rpc/msgpack/adaptor/boost/string_view.hpp @@ -0,0 +1,15 @@ +// +// MessagePack for C++ static resolution routine +// +// Copyright (C) 2017 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_STRING_VIEW_HPP +#define MSGPACK_TYPE_BOOST_STRING_VIEW_HPP + +#include "rpc/msgpack/v1/adaptor/boost/string_view.hpp" + +#endif // MSGPACK_TYPE_BOOST_STRING_VIEW_HPP diff --git a/include/rpc/msgpack/adaptor/carray.hpp b/include/rpc/msgpack/adaptor/carray.hpp new file mode 100644 index 00000000..08e0f1eb --- /dev/null +++ b/include/rpc/msgpack/adaptor/carray.hpp @@ -0,0 +1,15 @@ +// +// 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_CARRAY_HPP +#define MSGPACK_TYPE_CARRAY_HPP + +#include "rpc/msgpack/v1/adaptor/carray.hpp" + +#endif // MSGPACK_TYPE_CARRAY_HPP diff --git a/include/rpc/msgpack/adaptor/char_ptr.hpp b/include/rpc/msgpack/adaptor/char_ptr.hpp index 0743524a..406e3246 100644 --- a/include/rpc/msgpack/adaptor/char_ptr.hpp +++ b/include/rpc/msgpack/adaptor/char_ptr.hpp @@ -1,165 +1,15 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2014-2015 KONDO Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_CHAR_PTR_HPP #define MSGPACK_TYPE_CHAR_PTR_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/object_fwd.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const char* v) const { - uint32_t size = checked_get_container_size(std::strlen(v)); - o.type = clmdep_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()(clmdep_msgpack::object& o, const char* v) const { - uint32_t size = checked_get_container_size(std::strlen(v)); - o.type = clmdep_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()(clmdep_msgpack::object::with_zone& o, char* v) const { - o << static_cast(v); - } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, char* v) const { - o << static_cast(v); - } -}; - -template -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const char* v) const { - uint32_t size = checked_get_container_size(std::strlen(v)); - o.type = clmdep_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()(clmdep_msgpack::object& o, const char* v) const { - uint32_t size = checked_get_container_size(std::strlen(v)); - o.type = clmdep_msgpack::type::STR; - o.via.str.ptr = v; - o.via.str.size = size; - } -}; - -template -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const char* v) const { - uint32_t size = checked_get_container_size(std::strlen(v)); - o.type = clmdep_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()(clmdep_msgpack::object& o, const char* v) const { - uint32_t size = checked_get_container_size(std::strlen(v)); - o.type = clmdep_msgpack::type::STR; - o.via.str.ptr = v; - o.via.str.size = size; - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/char_ptr.hpp" #endif // MSGPACK_TYPE_CHAR_PTR_HPP diff --git a/include/rpc/msgpack/adaptor/check_container_size.hpp b/include/rpc/msgpack/adaptor/check_container_size.hpp index a5b4531b..f65c5d5d 100644 --- a/include/rpc/msgpack/adaptor/check_container_size.hpp +++ b/include/rpc/msgpack/adaptor/check_container_size.hpp @@ -1,75 +1,17 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2015 KONDO Takatoshi +// Copyright (C) 2015-2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_HPP #define MSGPACK_CHECK_CONTAINER_SIZE_HPP -#include "rpc/msgpack/versioning.hpp" -#include - -namespace clmdep_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 +#include "rpc/msgpack/adaptor/check_container_size_decl.hpp" -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/check_container_size.hpp" #endif // MSGPACK_CHECK_CONTAINER_SIZE_HPP diff --git a/include/rpc/msgpack/adaptor/check_container_size_decl.hpp b/include/rpc/msgpack/adaptor/check_container_size_decl.hpp new file mode 100644 index 00000000..ee698567 --- /dev/null +++ b/include/rpc/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 "rpc/msgpack/v1/adaptor/check_container_size_decl.hpp" +#include "rpc/msgpack/v2/adaptor/check_container_size_decl.hpp" + +#endif // MSGPACK_CHECK_CONTAINER_SIZE_DECL_HPP diff --git a/include/rpc/msgpack/adaptor/cpp11/array.hpp b/include/rpc/msgpack/adaptor/cpp11/array.hpp index 0a234a1b..f7d2b038 100644 --- a/include/rpc/msgpack/adaptor/cpp11/array.hpp +++ b/include/rpc/msgpack/adaptor/cpp11/array.hpp @@ -1,146 +1,16 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2014-2015 KONDO Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// 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) // -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#ifndef MSGPACK_CPP11_ARRAY_HPP -#define MSGPACK_CPP11_ARRAY_HPP - -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" -#include "rpc/msgpack/meta.hpp" - -#include - -namespace clmdep_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, - clmdep_msgpack::seq, - clmdep_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), clmdep_msgpack::gen_seq(), clmdep_msgpack::gen_seq()); -} - -template -struct as_impl { - static std::array as(clmdep_msgpack::object const& o) { - clmdep_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(clmdep_msgpack::object const& o) { - clmdep_msgpack::object* p = o.via.array.ptr; - return std::array{{p->as()}}; - } -}; - -template -struct as_impl { - static std::array as(clmdep_msgpack::object const&) { - return std::array(); - } -}; - -} // namespace array - -} // namespace detail - -template -struct as, typename std::enable_if::value>::type> { - std::array operator()(clmdep_msgpack::object const& o) const { - if(o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - if(o.via.array.size != N) { throw clmdep_msgpack::type_error(); } - return detail::array::as_impl::as(o); - } -}; - -template -struct convert> { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::array& v) const { - if(o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - if(o.via.array.size != N) { throw clmdep_msgpack::type_error(); } - if(o.via.array.size > 0) { - clmdep_msgpack::object* p = o.via.array.ptr; - clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const std::array& v) const { - o.type = clmdep_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()); - clmdep_msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size)); - o.via.array.size = size; - o.via.array.ptr = p; - for (auto const& e : v) *p++ = clmdep_msgpack::object(e, o.zone); - } - } -}; - -} // namespace adaptor -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond +#ifndef MSGPACK_TYPE_CPP11_ARRAY_HPP +#define MSGPACK_TYPE_CPP11_ARRAY_HPP -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/cpp11/array.hpp" -#endif // MSGPACK_CPP11_ARRAY_HPP +#endif // MSGPACK_TYPE_CPP11_ARRAY_HPP diff --git a/include/rpc/msgpack/adaptor/cpp11/array_char.hpp b/include/rpc/msgpack/adaptor/cpp11/array_char.hpp index e2a5dcf4..922b65f6 100644 --- a/include/rpc/msgpack/adaptor/cpp11/array_char.hpp +++ b/include/rpc/msgpack/adaptor/cpp11/array_char.hpp @@ -1,97 +1,16 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2014-2015 KONDO Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// 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) // -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#ifndef MSGPACK_TYPE_ARRAY_CHAR_HPP -#define MSGPACK_TYPE_ARRAY_CHAR_HPP - -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct convert> { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::array& v) const { - switch (o.type) { - case clmdep_msgpack::type::BIN: - if(o.via.bin.size != N) { throw clmdep_msgpack::type_error(); } - std::memcpy(v.data(), o.via.bin.ptr, o.via.bin.size); - break; - case clmdep_msgpack::type::STR: - if(o.via.str.size != N) { throw clmdep_msgpack::type_error(); } - std::memcpy(v.data(), o.via.str.ptr, N); - break; - default: - throw clmdep_msgpack::type_error(); - break; - } - return o; - } -}; - -template -struct pack> { - template - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object& o, const std::array& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = clmdep_msgpack::type::BIN; - o.via.bin.ptr = v.data(); - o.via.bin.size = size; - } -}; - -template -struct object_with_zone> { - void operator()(clmdep_msgpack::object::with_zone& o, const std::array& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = clmdep_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 +#ifndef MSGPACK_TYPE_CPP11_ARRAY_CHAR_HPP +#define MSGPACK_TYPE_CPP11_ARRAY_CHAR_HPP -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/cpp11/array_char.hpp" -#endif // MSGPACK_TYPE_ARRAY_CHAR_HPP +#endif // MSGPACK_TYPE_CPP11_ARRAY_CHAR_HPP diff --git a/include/rpc/msgpack/adaptor/cpp11/array_unsigned_char.hpp b/include/rpc/msgpack/adaptor/cpp11/array_unsigned_char.hpp index 35b1df63..c31841d4 100644 --- a/include/rpc/msgpack/adaptor/cpp11/array_unsigned_char.hpp +++ b/include/rpc/msgpack/adaptor/cpp11/array_unsigned_char.hpp @@ -1,97 +1,16 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2014-2015 KONDO Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// 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) // -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#ifndef MSGPACK_TYPE_ARRAY_UNSIGNED_CHAR_HPP -#define MSGPACK_TYPE_ARRAY_UNSIGNED_CHAR_HPP - -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct convert> { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::array& v) const { - switch (o.type) { - case clmdep_msgpack::type::BIN: - if(o.via.bin.size != N) { throw clmdep_msgpack::type_error(); } - std::memcpy(v.data(), o.via.bin.ptr, o.via.bin.size); - break; - case clmdep_msgpack::type::STR: - if(o.via.str.size != N) { throw clmdep_msgpack::type_error(); } - std::memcpy(v.data(), o.via.str.ptr, N); - break; - default: - throw clmdep_msgpack::type_error(); - break; - } - return o; - } -}; - -template -struct pack> { - template - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object& o, const std::array& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = clmdep_msgpack::type::BIN; - o.via.bin.ptr = reinterpret_cast(v.data()); - o.via.bin.size = size; - } -}; - -template -struct object_with_zone> { - void operator()(clmdep_msgpack::object::with_zone& o, const std::array& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = clmdep_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 +#ifndef MSGPACK_TYPE_CPP11_ARRAY_UNSIGNED_CHAR_HPP +#define MSGPACK_TYPE_CPP11_ARRAY_UNSIGNED_CHAR_HPP -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/cpp11/array_unsigned_char.hpp" -#endif // MSGPACK_TYPE_ARRAY_UNSIGNED_CHAR_HPP +#endif // MSGPACK_TYPE_CPP11_ARRAY_UNSIGNED_CHAR_HPP diff --git a/include/rpc/msgpack/adaptor/cpp11/forward_list.hpp b/include/rpc/msgpack/adaptor/cpp11/forward_list.hpp index b1200760..44329ce1 100644 --- a/include/rpc/msgpack/adaptor/cpp11/forward_list.hpp +++ b/include/rpc/msgpack/adaptor/cpp11/forward_list.hpp @@ -1,102 +1,16 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2014 KONDO-2015 Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// 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) // -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#ifndef MSGPACK_CPP11_FORWARD_LIST_HPP -#define MSGPACK_CPP11_FORWARD_LIST_HPP - -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template - struct as, typename std::enable_if::value>::type> { - std::forward_list operator()(clmdep_msgpack::object const& o) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - std::forward_list v; - clmdep_msgpack::object* p = o.via.array.ptr + o.via.array.size; - clmdep_msgpack::object* const pend = o.via.array.ptr; - while (p != pend) { - --p; - v.push_front(p->as()); - } - return v; - } -}; - -template -struct convert> { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::forward_list& v) const { - if(o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - v.resize(o.via.array.size); - clmdep_msgpack::object* p = o.via.array.ptr; - for (auto &e : v) { - p->convert(e); - ++p; - } - return o; - } -}; - -template -struct pack> { - template - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const std::forward_list& v) const { - o.type = clmdep_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; - clmdep_msgpack::object* p = static_cast( - o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size)); - o.via.array.ptr = p; - for(auto const& e : v) *p++ = clmdep_msgpack::object(e, o.zone); - } - } -}; - -} // namespace adaptor -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond +#ifndef MSGPACK_TYPE_CPP11_FORWARD_LIST_HPP +#define MSGPACK_TYPE_CPP11_FORWARD_LIST_HPP -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/cpp11/forward_list.hpp" -#endif // MSGPACK_CPP11_FORWARD_LIST_HPP +#endif // MSGPACK_TYPE_CPP11_FORWARD_LIST_HPP diff --git a/include/rpc/msgpack/adaptor/cpp11/reference_wrapper.hpp b/include/rpc/msgpack/adaptor/cpp11/reference_wrapper.hpp new file mode 100644 index 00000000..3c15d3e2 --- /dev/null +++ b/include/rpc/msgpack/adaptor/cpp11/reference_wrapper.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_CPP11_REFERENCE_WRAPPER_HPP +#define MSGPACK_TYPE_CPP11_REFERENCE_WRAPPER_HPP + +#include "rpc/msgpack/v1/adaptor/cpp11/reference_wrapper.hpp" + +#endif // MSGPACK_TYPE_CPP11_REFERENCE_WRAPPER_HPP diff --git a/include/rpc/msgpack/adaptor/cpp11/shared_ptr.hpp b/include/rpc/msgpack/adaptor/cpp11/shared_ptr.hpp index 9054c781..0dff7995 100644 --- a/include/rpc/msgpack/adaptor/cpp11/shared_ptr.hpp +++ b/include/rpc/msgpack/adaptor/cpp11/shared_ptr.hpp @@ -1,90 +1,16 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2015 KONDO Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// 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) // -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#ifndef MSGPACK_CPP11_SHARED_PTR_HPP -#define MSGPACK_CPP11_SHARED_PTR_HPP - -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct as, typename std::enable_if::value>::type> { - std::shared_ptr operator()(clmdep_msgpack::object const& o) const { - if(o.is_nil()) return nullptr; - return std::make_shared(o.as()); - } -}; - -template -struct convert> { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::shared_ptr& v) const { - if(o.is_nil()) v.reset(); - else { - v = std::make_shared(); - clmdep_msgpack::adaptor::convert()(o, *v); - } - return o; - } -}; - -template -struct pack> { - template - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object& o, const std::shared_ptr& v) const { - if (v) clmdep_msgpack::adaptor::object()(o, *v); - else o.type = clmdep_msgpack::type::NIL; - } -}; - -template -struct object_with_zone> { - void operator()(clmdep_msgpack::object::with_zone& o, const std::shared_ptr& v) const { - if (v) clmdep_msgpack::adaptor::object_with_zone()(o, *v); - else o.type = clmdep_msgpack::type::NIL; - } -}; - -} // namespace adaptor -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond +#ifndef MSGPACK_TYPE_CPP11_SHARED_PTR_HPP +#define MSGPACK_TYPE_CPP11_SHARED_PTR_HPP -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/cpp11/shared_ptr.hpp" -#endif // MSGPACK_CPP11_SHARED_PTR_HPP +#endif // MSGPACK_TYPE_CPP11_SHARED_PTR_HPP diff --git a/include/rpc/msgpack/adaptor/cpp11/tuple.hpp b/include/rpc/msgpack/adaptor/cpp11/tuple.hpp index 35be7b12..242a027f 100644 --- a/include/rpc/msgpack/adaptor/cpp11/tuple.hpp +++ b/include/rpc/msgpack/adaptor/cpp11/tuple.hpp @@ -1,184 +1,16 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// 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) // -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#ifndef MSGPACK_CPP11_TUPLE_HPP -#define MSGPACK_CPP11_TUPLE_HPP - -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" -#include "rpc/msgpack/meta.hpp" - -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -// --- Pack from tuple to packer stream --- -template -struct StdTuplePacker { - static void pack( - clmdep_msgpack::packer& o, - const Tuple& v) { - StdTuplePacker::pack(o, v); - o.pack(std::get(v)); - } -}; - -template -struct StdTuplePacker { - static void pack ( - clmdep_msgpack::packer&, - const Tuple&) { - } -}; - -namespace adaptor { - -template -struct pack> { - template - clmdep_msgpack::packer& operator()( - clmdep_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(clmdep_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(clmdep_msgpack::object const& o) { - return StdTupleAsImpl::as(o); - } -}; - -template <> -struct StdTupleAs<> { - static std::tuple<> as (clmdep_msgpack::object const&) { - return std::tuple<>(); - } -}; - -template -struct StdTupleConverter { - static void convert( - clmdep_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 ( - clmdep_msgpack::object const&, - Tuple&) { - } -}; - -namespace adaptor { - -template -struct as, typename std::enable_if::value>::type> { - std::tuple operator()( - clmdep_msgpack::object const& o) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - if (o.via.array.size < sizeof...(Args)) { throw clmdep_msgpack::type_error(); } - return StdTupleAs::as(o); - } -}; - -template -struct convert> { - clmdep_msgpack::object const& operator()( - clmdep_msgpack::object const& o, - std::tuple& v) const { - if(o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - if(o.via.array.size < sizeof...(Args)) { throw clmdep_msgpack::type_error(); } - StdTupleConverter::convert(o, v); - return o; - } -}; - -} // namespace adaptor - -// --- Convert from tuple to object with zone --- -template -struct StdTupleToObjectWithZone { - static void convert( - clmdep_msgpack::object::with_zone& o, - const Tuple& v) { - StdTupleToObjectWithZone::convert(o, v); - o.via.array.ptr[N-1] = clmdep_msgpack::object(std::get(v), o.zone); - } -}; - -template -struct StdTupleToObjectWithZone { - static void convert ( - clmdep_msgpack::object::with_zone&, - const Tuple&) { - } -}; - -namespace adaptor { - -template -struct object_with_zone> { - void operator()( - clmdep_msgpack::object::with_zone& o, - std::tuple const& v) const { - uint32_t size = checked_get_container_size(sizeof...(Args)); - o.type = clmdep_msgpack::type::ARRAY; - o.via.array.ptr = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size)); - o.via.array.size = size; - StdTupleToObjectWithZone::convert(o, v); - } -}; - -} // namespace adaptor -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond +#ifndef MSGPACK_TYPE_CPP11_TUPLE_HPP +#define MSGPACK_TYPE_CPP11_TUPLE_HPP -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/cpp11/tuple.hpp" -#endif // MSGPACK_CPP11_TUPLE_HPP +#endif // MSGPACK_TYPE_CPP11_TUPLE_HPP diff --git a/include/rpc/msgpack/adaptor/cpp11/unique_ptr.hpp b/include/rpc/msgpack/adaptor/cpp11/unique_ptr.hpp index 49792b06..874ad176 100644 --- a/include/rpc/msgpack/adaptor/cpp11/unique_ptr.hpp +++ b/include/rpc/msgpack/adaptor/cpp11/unique_ptr.hpp @@ -1,90 +1,16 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2015 KONDO Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// 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) // -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#ifndef MSGPACK_CPP11_UNIQUE_PTR_HPP -#define MSGPACK_CPP11_UNIQUE_PTR_HPP - -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct as, typename std::enable_if::value>::type> { - std::unique_ptr operator()(clmdep_msgpack::object const& o) const { - if(o.is_nil()) return nullptr; - return std::unique_ptr(new T(o.as())); - } -}; - -template -struct convert> { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::unique_ptr& v) const { - if(o.is_nil()) v.reset(); - else { - v.reset(new T); - clmdep_msgpack::adaptor::convert()(o, *v); - } - return o; - } -}; - -template -struct pack> { - template - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object& o, const std::unique_ptr& v) const { - if (v) clmdep_msgpack::adaptor::object()(o, *v); - else o.type = clmdep_msgpack::type::NIL; - } -}; - -template -struct object_with_zone> { - void operator()(clmdep_msgpack::object::with_zone& o, const std::unique_ptr& v) const { - if (v) clmdep_msgpack::adaptor::object_with_zone()(o, *v); - else o.type = clmdep_msgpack::type::NIL; - } -}; - -} // namespace adaptor -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond +#ifndef MSGPACK_TYPE_CPP11_UNIQUE_PTR_HPP +#define MSGPACK_TYPE_CPP11_UNIQUE_PTR_HPP -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/cpp11/unique_ptr.hpp" -#endif // MSGPACK_CPP11_UNIQUE_PTR_HPP +#endif // MSGPACK_TYPE_CPP11_UNIQUE_PTR_HPP diff --git a/include/rpc/msgpack/adaptor/cpp11/unordered_map.hpp b/include/rpc/msgpack/adaptor/cpp11/unordered_map.hpp index 428c987d..93d7db60 100644 --- a/include/rpc/msgpack/adaptor/cpp11/unordered_map.hpp +++ b/include/rpc/msgpack/adaptor/cpp11/unordered_map.hpp @@ -1,190 +1,16 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2014-2015 KONDO Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// 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) // -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#ifndef MSGPACK_TYPE_UNORDERED_MAP_HPP -#define MSGPACK_TYPE_UNORDERED_MAP_HPP - -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct as< - std::unordered_map, - typename std::enable_if::value && clmdep_msgpack::has_as::value>::type> { - std::unordered_map operator()(clmdep_msgpack::object const& o) const { - if (o.type != clmdep_msgpack::type::MAP) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object_kv* p(o.via.map.ptr); - clmdep_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> { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::unordered_map& v) const { - if(o.type != clmdep_msgpack::type::MAP) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object_kv* p(o.via.map.ptr); - clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const std::unordered_map& v) const { - o.type = clmdep_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()); - clmdep_msgpack::object_kv* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object_kv)*size)); - clmdep_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 = clmdep_msgpack::object(it->first, o.zone); - p->val = clmdep_msgpack::object(it->second, o.zone); - ++p; - ++it; - } while(p < pend); - } - } -}; - - -template -struct as< - std::unordered_multimap, - typename std::enable_if::value && clmdep_msgpack::has_as::value>::type> { - std::unordered_multimap operator()(clmdep_msgpack::object const& o) const { - if (o.type != clmdep_msgpack::type::MAP) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object_kv* p(o.via.map.ptr); - clmdep_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> { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::unordered_multimap& v) const { - if(o.type != clmdep_msgpack::type::MAP) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object_kv* p(o.via.map.ptr); - clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const std::unordered_multimap& v) const { - o.type = clmdep_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()); - clmdep_msgpack::object_kv* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object_kv)*size)); - clmdep_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 = clmdep_msgpack::object(it->first, o.zone); - p->val = clmdep_msgpack::object(it->second, o.zone); - ++p; - ++it; - } while(p < pend); - } - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond -} // namespace clmdep_msgpack +#ifndef MSGPACK_TYPE_CPP11_UNORDERED_MAP_HPP +#define MSGPACK_TYPE_CPP11_UNORDERED_MAP_HPP +#include "rpc/msgpack/v1/adaptor/cpp11/unordered_map.hpp" -#endif // MSGPACK_TYPE_UNORDERED_MAP_HPP +#endif // MSGPACK_TYPE_CPP11_UNORDERED_MAP_HPP diff --git a/include/rpc/msgpack/adaptor/cpp11/unordered_set.hpp b/include/rpc/msgpack/adaptor/cpp11/unordered_set.hpp index 2e5eeef1..46b8c131 100644 --- a/include/rpc/msgpack/adaptor/cpp11/unordered_set.hpp +++ b/include/rpc/msgpack/adaptor/cpp11/unordered_set.hpp @@ -1,180 +1,16 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2014-2015 KONDO Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// 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) // -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#ifndef MSGPACK_TYPE_UNORDERED_SET_HPP -#define MSGPACK_TYPE_UNORDERED_SET_HPP - -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct as, typename std::enable_if::value>::type> { - std::unordered_set operator()(clmdep_msgpack::object const& o) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object* p = o.via.array.ptr + o.via.array.size; - clmdep_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> { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::unordered_set& v) const { - if(o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object* p = o.via.array.ptr + o.via.array.size; - clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const std::unordered_set& v) const { - o.type = clmdep_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()); - clmdep_msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size)); - clmdep_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 = clmdep_msgpack::object(*it, o.zone); - ++p; - ++it; - } while(p < pend); - } - } -}; - - -template -struct as, typename std::enable_if::value>::type> { - std::unordered_multiset operator()(clmdep_msgpack::object const& o) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object* p = o.via.array.ptr + o.via.array.size; - clmdep_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> { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::unordered_multiset& v) const { - if(o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object* p = o.via.array.ptr + o.via.array.size; - clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const std::unordered_multiset& v) const { - o.type = clmdep_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()); - clmdep_msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size)); - clmdep_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 = clmdep_msgpack::object(*it, o.zone); - ++p; - ++it; - } while(p < pend); - } - } -}; - -} // namespace adaptor -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond +#ifndef MSGPACK_TYPE_CPP11_UNORDERED_SET_HPP +#define MSGPACK_TYPE_CPP11_UNORDERED_SET_HPP -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/cpp11/unordered_set.hpp" -#endif // MSGPACK_TYPE_UNORDERED_SET_HPP +#endif // MSGPACK_TYPE_CPP11_UNORDERED_SET_HPP diff --git a/include/rpc/msgpack/adaptor/cpp17/optional.hpp b/include/rpc/msgpack/adaptor/cpp17/optional.hpp new file mode 100644 index 00000000..8e7a2566 --- /dev/null +++ b/include/rpc/msgpack/adaptor/cpp17/optional.hpp @@ -0,0 +1,16 @@ +// +// MessagePack for C++ static resolution routine +// +// Copyright (C) 2017 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_CPP17_OPTIONAL_HPP +#define MSGPACK_TYPE_CPP17_OPTIONAL_HPP + +#include "rpc/msgpack/v1/adaptor/cpp17/optional.hpp" + +#endif // MSGPACK_TYPE_CPP17_OPTIONAL_HPP diff --git a/include/rpc/msgpack/adaptor/cpp17/string_view.hpp b/include/rpc/msgpack/adaptor/cpp17/string_view.hpp new file mode 100644 index 00000000..bdc48fed --- /dev/null +++ b/include/rpc/msgpack/adaptor/cpp17/string_view.hpp @@ -0,0 +1,16 @@ +// +// MessagePack for C++ static resolution routine +// +// Copyright (C) 2017 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_CPP17_STRING_VIEW_HPP +#define MSGPACK_TYPE_CPP17_STRING_VIEW_HPP + +#include "rpc/msgpack/v1/adaptor/cpp17/string_view.hpp" + +#endif // MSGPACK_TYPE_CPP17_STRING_VIEW_HPP diff --git a/include/rpc/msgpack/adaptor/define.hpp b/include/rpc/msgpack/adaptor/define.hpp index dce5f53c..46d7caf0 100644 --- a/include/rpc/msgpack/adaptor/define.hpp +++ b/include/rpc/msgpack/adaptor/define.hpp @@ -1,39 +1,17 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi +// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_HPP #define MSGPACK_DEFINE_HPP -#include "rpc/msgpack/cpp_config.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 +#include "rpc/msgpack/adaptor/define_decl.hpp" -#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 "rpc/msgpack/v1/adaptor/define.hpp" #endif // MSGPACK_DEFINE_HPP diff --git a/include/rpc/msgpack/adaptor/define_decl.hpp b/include/rpc/msgpack/adaptor/define_decl.hpp new file mode 100644 index 00000000..7b80cef7 --- /dev/null +++ b/include/rpc/msgpack/adaptor/define_decl.hpp @@ -0,0 +1,143 @@ +// +// 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 "rpc/msgpack/versioning.hpp" + +// for MSGPACK_ADD_ENUM +#include "rpc/msgpack/adaptor/int.hpp" + +#define MSGPACK_DEFINE_ARRAY(...) \ + template \ + void msgpack_pack(Packer& pk) const \ + { \ + clmdep_msgpack::type::make_define_array(__VA_ARGS__).msgpack_pack(pk); \ + } \ + void msgpack_unpack(clmdep_msgpack::object const& o) \ + { \ + clmdep_msgpack::type::make_define_array(__VA_ARGS__).msgpack_unpack(o); \ + }\ + template \ + void msgpack_object(MSGPACK_OBJECT* o, clmdep_msgpack::zone& z) const \ + { \ + clmdep_msgpack::type::make_define_array(__VA_ARGS__).msgpack_object(o, z); \ + } + +#define MSGPACK_BASE_ARRAY(base) (*const_cast(static_cast(this))) +#define MSGPACK_NVP(name, value) (name) (value) + +#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 \ + { \ + clmdep_msgpack::type::make_define_map \ + MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \ + .msgpack_pack(pk); \ + } \ + void msgpack_unpack(clmdep_msgpack::object const& o) \ + { \ + clmdep_msgpack::type::make_define_map \ + MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \ + .msgpack_unpack(o); \ + }\ + template \ + void msgpack_object(MSGPACK_OBJECT* o, clmdep_msgpack::zone& z) const \ + { \ + clmdep_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 clmdep_msgpack { \ + /** @cond */ \ + MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) { \ + /** @endcond */ \ + namespace adaptor { \ + template<> \ + struct convert { \ + clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, enum_name& v) const { \ + clmdep_msgpack::underlying_type::type tmp; \ + clmdep_msgpack::operator>>(o, tmp); \ + v = static_cast(tmp); \ + return o; \ + } \ + }; \ + template<> \ + struct object { \ + void operator()(clmdep_msgpack::object& o, const enum_name& v) const { \ + clmdep_msgpack::underlying_type::type tmp = static_cast::type>(v); \ + clmdep_msgpack::operator<<(o, tmp); \ + } \ + }; \ + template<> \ + struct object_with_zone { \ + void operator()(clmdep_msgpack::object::with_zone& o, const enum_name& v) const { \ + clmdep_msgpack::underlying_type::type tmp = static_cast::type>(v); \ + clmdep_msgpack::operator<<(o, tmp); \ + } \ + }; \ + template <> \ + struct pack { \ + template \ + clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const enum_name& v) const { \ + return clmdep_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 "rpc/msgpack/v1/adaptor/define_decl.hpp" +#include "rpc/msgpack/v2/adaptor/define_decl.hpp" + +#endif // MSGPACK_DEFINE_DECL_HPP diff --git a/include/rpc/msgpack/adaptor/deque.hpp b/include/rpc/msgpack/adaptor/deque.hpp index e2e5b853..6d4e640c 100644 --- a/include/rpc/msgpack/adaptor/deque.hpp +++ b/include/rpc/msgpack/adaptor/deque.hpp @@ -1,116 +1,15 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2015 FURUHASHI Sadayuki +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_DEQUE_HPP #define MSGPACK_TYPE_DEQUE_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_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 clmdep_msgpack::object& o) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - std::deque v; - if (o.via.array.size > 0) { - clmdep_msgpack::object* p = o.via.array.ptr; - clmdep_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 > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::deque& v) const { - if(o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - v.resize(o.via.array.size); - clmdep_msgpack::object* p = o.via.array.ptr; - clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const std::deque& v) const { - o.type = clmdep_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()); - clmdep_msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size)); - clmdep_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 = clmdep_msgpack::object(*it, o.zone); - ++p; - ++it; - } while(p < pend); - } - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/deque.hpp" -#endif /* msgpack/type/deque.hpp */ +#endif // MSGPACK_TYPE_DEQUE_HPP diff --git a/include/rpc/msgpack/adaptor/ext.hpp b/include/rpc/msgpack/adaptor/ext.hpp index 1f1a6040..74dd8e5b 100644 --- a/include/rpc/msgpack/adaptor/ext.hpp +++ b/include/rpc/msgpack/adaptor/ext.hpp @@ -3,243 +3,15 @@ // // Copyright (C) 2015 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_HPP #define MSGPACK_TYPE_EXT_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include -#include -#include - -namespace clmdep_msgpack { - -/// @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 { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, clmdep_msgpack::type::ext& v) const { - if(o.type != clmdep_msgpack::type::EXT) { - throw clmdep_msgpack::type_error(); - } - v = clmdep_msgpack::type::ext(o.via.ext.type(), o.via.ext.data(), o.via.ext.size); - return o; - } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const clmdep_msgpack::type::ext& v) const { - // size limit has aleady 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()(clmdep_msgpack::object::with_zone& o, const clmdep_msgpack::type::ext& v) const { - // size limit has aleady been checked at ext's constructor - uint32_t size = v.size(); - o.type = clmdep_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 shoudn'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 aleady 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 clmdep_msgpack::adaptor::object; -}; - -inline ext::ext(ext_ref const& x) { - // size limit has aleady 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 { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, clmdep_msgpack::type::ext_ref& v) const { - if(o.type != clmdep_msgpack::type::EXT) { throw clmdep_msgpack::type_error(); } - v = clmdep_msgpack::type::ext_ref(o.via.ext.ptr, o.via.ext.size + 1); - return o; - } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const clmdep_msgpack::type::ext_ref& v) const { - // size limit has aleady 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()(clmdep_msgpack::object& o, const clmdep_msgpack::type::ext_ref& v) const { - // size limit has aleady been checked at ext_ref's constructor - uint32_t size = v.size(); - o.type = clmdep_msgpack::type::EXT; - o.via.ext.ptr = v.m_ptr; - o.via.ext.size = size; - } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, const clmdep_msgpack::type::ext_ref& v) const { - static_cast(o) << v; - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond +#include "rpc/msgpack/adaptor/ext_decl.hpp" -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/ext.hpp" -#endif // MSGPACK_TYPE_EXT_HPP +#endif // MSGPACK_TYPE_EXT_HPP diff --git a/include/rpc/msgpack/adaptor/ext_decl.hpp b/include/rpc/msgpack/adaptor/ext_decl.hpp new file mode 100644 index 00000000..a8cf78a9 --- /dev/null +++ b/include/rpc/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 "rpc/msgpack/v1/adaptor/ext_decl.hpp" +#include "rpc/msgpack/v2/adaptor/ext_decl.hpp" + +#endif // MSGPACK_TYPE_EXT_DECL_HPP diff --git a/include/rpc/msgpack/adaptor/fixint.hpp b/include/rpc/msgpack/adaptor/fixint.hpp index b5f5b095..ef395e69 100644 --- a/include/rpc/msgpack/adaptor/fixint.hpp +++ b/include/rpc/msgpack/adaptor/fixint.hpp @@ -1,306 +1,17 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2020 FURUHASHI Sadayuki +// Copyright (C) 2016 FURUHASHI Sadayuki and KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_HPP #define MSGPACK_TYPE_FIXINT_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/int.hpp" - -namespace clmdep_msgpack { - -/// @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 { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, type::fix_int8& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, type::fix_int16& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, type::fix_int32& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, type::fix_int64& v) const - { v = type::detail::convert_integer(o); return o; } -}; - - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, type::fix_uint8& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, type::fix_uint16& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, type::fix_uint32& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, type::fix_uint64& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const type::fix_int8& v) const - { o.pack_fix_int8(v); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const type::fix_int16& v) const - { o.pack_fix_int16(v); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const type::fix_int32& v) const - { o.pack_fix_int32(v); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const type::fix_int64& v) const - { o.pack_fix_int64(v); return o; } -}; - - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const type::fix_uint8& v) const - { o.pack_fix_uint8(v); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const type::fix_uint16& v) const - { o.pack_fix_uint16(v); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const type::fix_uint32& v) const - { o.pack_fix_uint32(v); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const type::fix_uint64& v) const - { o.pack_fix_uint64(v); return o; } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, type::fix_int8 v) const { - if (v.get() < 0) { - o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; - o.via.i64 = v.get(); - } - else { - o.type = clmdep_msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v.get(); - } - } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, type::fix_int16 v) const { - if(v.get() < 0) { - o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; - o.via.i64 = v.get(); - } - else { - o.type = clmdep_msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v.get(); - } - } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, type::fix_int32 v) const { - if (v.get() < 0) { - o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; - o.via.i64 = v.get(); - } - else { - o.type = clmdep_msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v.get(); - } - } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, type::fix_int64 v) const { - if (v.get() < 0) { - o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; - o.via.i64 = v.get(); - } - else { - o.type = clmdep_msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v.get(); - } - } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, type::fix_uint8 v) const - { o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, type::fix_uint16 v) const - { o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, type::fix_uint32 v) const - { o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, type::fix_uint64 v) const - { o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, type::fix_int8 v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, type::fix_int16 v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, type::fix_int32 v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, type::fix_int64 v) const - { static_cast(o) << v; } -}; - - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, type::fix_uint8 v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, type::fix_uint16 v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, type::fix_uint32 v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, type::fix_uint64 v) const - { static_cast(o) << v; } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond +#include "rpc/msgpack/adaptor/fixint_decl.hpp" -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/fixint.hpp" -#endif /* msgpack/type/fixint.hpp */ +#endif // MSGPACK_TYPE_FIXINT_HPP diff --git a/include/rpc/msgpack/adaptor/fixint_decl.hpp b/include/rpc/msgpack/adaptor/fixint_decl.hpp new file mode 100644 index 00000000..05776d27 --- /dev/null +++ b/include/rpc/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 "rpc/msgpack/v1/adaptor/fixint_decl.hpp" +#include "rpc/msgpack/v2/adaptor/fixint_decl.hpp" + +#endif // MSGPACK_TYPE_FIXINT_DECL_HPP diff --git a/include/rpc/msgpack/adaptor/float.hpp b/include/rpc/msgpack/adaptor/float.hpp index 8967b64d..e1ed4d90 100644 --- a/include/rpc/msgpack/adaptor/float.hpp +++ b/include/rpc/msgpack/adaptor/float.hpp @@ -1,131 +1,15 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2009 FURUHASHI Sadayuki +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_FLOAT_HPP #define MSGPACK_TYPE_FLOAT_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/object_fwd.hpp" -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -// FIXME check overflow, underflow - -namespace adaptor { - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, float& v) const { - if(o.type == clmdep_msgpack::type::FLOAT) { - v = static_cast(o.via.f64); - } - else if (o.type == clmdep_msgpack::type::POSITIVE_INTEGER) { - v = static_cast(o.via.u64); - } - else if (o.type == clmdep_msgpack::type::NEGATIVE_INTEGER) { - v = static_cast(o.via.i64); - } - else { - throw clmdep_msgpack::type_error(); - } - return o; - } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const float& v) const { - o.pack_float(v); - return o; - } -}; - - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, double& v) const { - if(o.type == clmdep_msgpack::type::FLOAT) { - v = o.via.f64; - } - else if (o.type == clmdep_msgpack::type::POSITIVE_INTEGER) { - v = static_cast(o.via.u64); - } - else if (o.type == clmdep_msgpack::type::NEGATIVE_INTEGER) { - v = static_cast(o.via.i64); - } - else { - throw clmdep_msgpack::type_error(); - } - return o; - } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const double& v) const { - o.pack_double(v); - return o; - } -}; - - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, float v) const { - o.type = clmdep_msgpack::type::FLOAT; - o.via.f64 = static_cast(v); - } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, double v) const { - o.type = clmdep_msgpack::type::FLOAT; - o.via.f64 = v; - } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, float v) const { - static_cast(o) << v; - } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, double v) const { - static_cast(o) << v; - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/float.hpp" #endif // MSGPACK_TYPE_FLOAT_HPP diff --git a/include/rpc/msgpack/adaptor/int.hpp b/include/rpc/msgpack/adaptor/int.hpp index 68856b23..021be266 100644 --- a/include/rpc/msgpack/adaptor/int.hpp +++ b/include/rpc/msgpack/adaptor/int.hpp @@ -1,436 +1,17 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2009 FURUHASHI Sadayuki +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_HPP #define MSGPACK_TYPE_INT_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1){ -/// @endcond - -namespace type { -namespace detail { - template - struct convert_integer_sign; - - template - struct convert_integer_sign { - static inline T convert(clmdep_msgpack::object const& o) { - if(o.type == clmdep_msgpack::type::POSITIVE_INTEGER) { - if(o.via.u64 > static_cast(std::numeric_limits::max())) - { throw clmdep_msgpack::type_error(); } - return static_cast(o.via.u64); - } else if(o.type == clmdep_msgpack::type::NEGATIVE_INTEGER) { - if(o.via.i64 < static_cast(std::numeric_limits::min())) - { throw clmdep_msgpack::type_error(); } - return static_cast(o.via.i64); - } - throw clmdep_msgpack::type_error(); - } - }; - - template - struct convert_integer_sign { - static inline T convert(clmdep_msgpack::object const& o) { - if(o.type == clmdep_msgpack::type::POSITIVE_INTEGER) { - if(o.via.u64 > static_cast(std::numeric_limits::max())) - { throw clmdep_msgpack::type_error(); } - return static_cast(o.via.u64); - } - throw clmdep_msgpack::type_error(); - } - }; - - template - struct is_signed { - static const bool value = std::numeric_limits::is_signed; - }; - - template - static inline T convert_integer(clmdep_msgpack::object const& o) - { - return detail::convert_integer_sign::value>::convert(o); - } - - template - struct object_char_sign; - - template <> - struct object_char_sign { - static inline void make(clmdep_msgpack::object& o, char v) { - if (v < 0) { - o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; - o.via.i64 = v; - } - else { - o.type = clmdep_msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v; - } - } - }; - - template <> - struct object_char_sign { - static inline void make(clmdep_msgpack::object& o, char v) { - o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; - } - }; - - static inline void object_char(clmdep_msgpack::object& o, char v) { - return object_char_sign::value>::make(o, v); - } - -} // namespace detail -} // namespace type - -namespace adaptor { - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, char& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, signed char& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, signed short& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, signed int& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, signed long& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, signed long long& v) const - { v = type::detail::convert_integer(o); return o; } -}; - - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, unsigned char& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, unsigned short& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, unsigned int& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, unsigned long& v) const - { v = type::detail::convert_integer(o); return o; } -}; - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, unsigned long long& v) const - { v = type::detail::convert_integer(o); return o; } -}; - - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, char v) const - { o.pack_char(v); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, signed char v) const - { o.pack_signed_char(v); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, signed short v) const - { o.pack_short(v); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, signed int v) const - { o.pack_int(v); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, signed long v) const - { o.pack_long(v); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, signed long long v) const - { o.pack_long_long(v); return o; } -}; - - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, unsigned char v) const - { o.pack_unsigned_char(v); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, unsigned short v) const - { o.pack_unsigned_short(v); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, unsigned int v) const - { o.pack_unsigned_int(v); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, unsigned long v) const - { o.pack_unsigned_long(v); return o; } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, unsigned long long v) const - { o.pack_unsigned_long_long(v); return o; } -}; - - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, char v) const - { type::detail::object_char(o, v); } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, signed char v) const { - if (v < 0) { - o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; - o.via.i64 = v; - } - else { - o.type = clmdep_msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v; - } - } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, signed short v) const { - if (v < 0) { - o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; - o.via.i64 = v; - } - else { - o.type = clmdep_msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v; - } - } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, signed int v) const { - if (v < 0) { - o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; - o.via.i64 = v; - } - else { - o.type = clmdep_msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v; - } - } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, signed long v) const { - if (v < 0) { - o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; - o.via.i64 = v; - } - else { - o.type = clmdep_msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v; - } - } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, signed long long v) const { - if (v < 0) { - o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; - o.via.i64 = v; - } - else{ - o.type = clmdep_msgpack::type::POSITIVE_INTEGER; - o.via.u64 = v; - } - } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, unsigned char v) const - { o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, unsigned short v) const - { o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, unsigned int v) const - { o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, unsigned long v) const - { o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, unsigned long long v) const - { o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; } -}; - - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, char v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, signed char v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, signed short v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, signed int v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, signed long v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, const signed long long& v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, unsigned char v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, unsigned short v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, unsigned int v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, unsigned long v) const - { static_cast(o) << v; } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, const unsigned long long& v) const - { static_cast(o) << v; } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond +#include "rpc/msgpack/adaptor/int_decl.hpp" -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/int.hpp" -#endif /* msgpack/type/int.hpp */ +#endif // MSGPACK_TYPE_INT_HPP diff --git a/include/rpc/msgpack/adaptor/int_decl.hpp b/include/rpc/msgpack/adaptor/int_decl.hpp new file mode 100644 index 00000000..c0bfc798 --- /dev/null +++ b/include/rpc/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 "rpc/msgpack/v1/adaptor/int_decl.hpp" +#include "rpc/msgpack/v2/adaptor/int_decl.hpp" + +#endif // MSGPACK_TYPE_INT_DECL_HPP diff --git a/include/rpc/msgpack/adaptor/list.hpp b/include/rpc/msgpack/adaptor/list.hpp index 38666cb9..f3157d50 100644 --- a/include/rpc/msgpack/adaptor/list.hpp +++ b/include/rpc/msgpack/adaptor/list.hpp @@ -1,114 +1,15 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2015 FURUHASHI Sadayuki +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_LIST_HPP #define MSGPACK_TYPE_LIST_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_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()(clmdep_msgpack::object const& o) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - std::list v; - clmdep_msgpack::object* p = o.via.array.ptr; - clmdep_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 > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::list& v) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - v.resize(o.via.array.size); - clmdep_msgpack::object* p = o.via.array.ptr; - clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const std::list& v) const { - o.type = clmdep_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()); - clmdep_msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size)); - clmdep_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 = clmdep_msgpack::object(*it, o.zone); - ++p; - ++it; - } while(p < pend); - } - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/list.hpp" #endif // MSGPACK_TYPE_LIST_HPP diff --git a/include/rpc/msgpack/adaptor/map.hpp b/include/rpc/msgpack/adaptor/map.hpp index 7e94223f..f846db44 100644 --- a/include/rpc/msgpack/adaptor/map.hpp +++ b/include/rpc/msgpack/adaptor/map.hpp @@ -1,314 +1,18 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2015 FURUHASHI Sadayuki +// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_HPP #define MSGPACK_TYPE_MAP_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/object_fwd.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include -#include -#include - -namespace clmdep_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 && clmdep_msgpack::has_as::value>::type> { - type::assoc_vector operator()(clmdep_msgpack::object const& o) const { - if (o.type != clmdep_msgpack::type::MAP) { throw clmdep_msgpack::type_error(); } - type::assoc_vector v; - v.reserve(o.via.map.size); - clmdep_msgpack::object_kv* p = o.via.map.ptr; - clmdep_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 > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, type::assoc_vector& v) const { - if (o.type != clmdep_msgpack::type::MAP) { throw clmdep_msgpack::type_error(); } - v.resize(o.via.map.size); - clmdep_msgpack::object_kv* p = o.via.map.ptr; - clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const type::assoc_vector& v) const { - o.type = clmdep_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()); - clmdep_msgpack::object_kv* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object_kv)*size)); - clmdep_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 = clmdep_msgpack::object(it->first, o.zone); - p->val = clmdep_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 && clmdep_msgpack::has_as::value>::type> { - std::map operator()(clmdep_msgpack::object const& o) const { - if (o.type != clmdep_msgpack::type::MAP) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object_kv* p(o.via.map.ptr); - clmdep_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 > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::map& v) const { - if (o.type != clmdep_msgpack::type::MAP) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object_kv* p(o.via.map.ptr); - clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const std::map& v) const { - o.type = clmdep_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()); - clmdep_msgpack::object_kv* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object_kv)*size)); - clmdep_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 = clmdep_msgpack::object(it->first, o.zone); - p->val = clmdep_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 && clmdep_msgpack::has_as::value>::type> { - std::multimap operator()(clmdep_msgpack::object const& o) const { - if (o.type != clmdep_msgpack::type::MAP) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object_kv* p(o.via.map.ptr); - clmdep_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 > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::multimap& v) const { - if (o.type != clmdep_msgpack::type::MAP) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object_kv* p(o.via.map.ptr); - clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const std::multimap& v) const { - o.type = clmdep_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()); - clmdep_msgpack::object_kv* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object_kv)*size)); - clmdep_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 = clmdep_msgpack::object(it->first, o.zone); - p->val = clmdep_msgpack::object(it->second, o.zone); - ++p; - ++it; - } while(p < pend); - } - } -}; - -} // namespace adaptor +#include "rpc/msgpack/adaptor/map_decl.hpp" -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond +#include "rpc/msgpack/v1/adaptor/map.hpp" -} // namespace clmdep_msgpack #endif // MSGPACK_TYPE_MAP_HPP diff --git a/include/rpc/msgpack/adaptor/map_decl.hpp b/include/rpc/msgpack/adaptor/map_decl.hpp new file mode 100644 index 00000000..42a86987 --- /dev/null +++ b/include/rpc/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 "rpc/msgpack/v1/adaptor/map_decl.hpp" +#include "rpc/msgpack/v2/adaptor/map_decl.hpp" + +#endif // MSGPACK_TYPE_MAP_DECL_HPP diff --git a/include/rpc/msgpack/adaptor/msgpack_tuple.hpp b/include/rpc/msgpack/adaptor/msgpack_tuple.hpp index 6ca153df..2c566c01 100644 --- a/include/rpc/msgpack/adaptor/msgpack_tuple.hpp +++ b/include/rpc/msgpack/adaptor/msgpack_tuple.hpp @@ -3,27 +3,15 @@ // // Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_HPP #define MSGPACK_MSGPACK_TUPLE_HPP -#include "rpc/msgpack/cpp_config.hpp" +#include "rpc/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 "rpc/msgpack/v1/adaptor/msgpack_tuple.hpp" #endif // MSGPACK_MSGPACK_TUPLE_HPP diff --git a/include/rpc/msgpack/adaptor/msgpack_tuple_decl.hpp b/include/rpc/msgpack/adaptor/msgpack_tuple_decl.hpp new file mode 100644 index 00000000..e60b6b7c --- /dev/null +++ b/include/rpc/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 "rpc/msgpack/v1/adaptor/msgpack_tuple_decl.hpp" +#include "rpc/msgpack/v2/adaptor/msgpack_tuple_decl.hpp" + +#endif // MSGPACK_MSGPACK_TUPLE_DECL_HPP diff --git a/include/rpc/msgpack/adaptor/nil.hpp b/include/rpc/msgpack/adaptor/nil.hpp index 4dca2af1..5872b513 100644 --- a/include/rpc/msgpack/adaptor/nil.hpp +++ b/include/rpc/msgpack/adaptor/nil.hpp @@ -1,92 +1,17 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2009 FURUHASHI Sadayuki +// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_HPP #define MSGPACK_TYPE_NIL_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace type { - -struct nil { }; - -inline bool operator<(nil const& lhs, nil const& rhs) { - return &lhs < &rhs; -} - -inline bool operator==(nil const& lhs, nil const& rhs) { - return &lhs == &rhs; -} - -} // namespace type - -namespace adaptor { - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, type::nil&) const { - if(o.type != clmdep_msgpack::type::NIL) { throw clmdep_msgpack::type_error(); } - return o; - } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const type::nil&) const { - o.pack_nil(); - return o; - } -}; - -template <> -struct object { - void operator()(clmdep_msgpack::object& o, type::nil) const { - o.type = clmdep_msgpack::type::NIL; - } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, type::nil v) const { - static_cast(o) << v; - } -}; - -} // namespace adaptror - -template <> -inline void clmdep_msgpack::object::as() const -{ - clmdep_msgpack::type::nil v; - convert(v); -} - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond +#include "rpc/msgpack/adaptor/nil_decl.hpp" -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/nil.hpp" #endif // MSGPACK_TYPE_NIL_HPP diff --git a/include/rpc/msgpack/adaptor/nil_decl.hpp b/include/rpc/msgpack/adaptor/nil_decl.hpp new file mode 100644 index 00000000..d9d8b7a2 --- /dev/null +++ b/include/rpc/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 "rpc/msgpack/v1/adaptor/nil_decl.hpp" +#include "rpc/msgpack/v2/adaptor/nil_decl.hpp" + +#endif // MSGPACK_TYPE_NIL_DECL_HPP diff --git a/include/rpc/msgpack/adaptor/pair.hpp b/include/rpc/msgpack/adaptor/pair.hpp index 2f6f0c18..04a67f2b 100644 --- a/include/rpc/msgpack/adaptor/pair.hpp +++ b/include/rpc/msgpack/adaptor/pair.hpp @@ -1,91 +1,15 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2009 FURUHASHI Sadayuki +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_PAIR_HPP #define MSGPACK_TYPE_PAIR_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/meta.hpp" - -#include - -namespace clmdep_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()(clmdep_msgpack::object const& o) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - if (o.via.array.size != 2) { throw clmdep_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 > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::pair& v) const { - if(o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - if(o.via.array.size != 2) { throw clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const std::pair& v) const { - o.type = clmdep_msgpack::type::ARRAY; - clmdep_msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*2)); - o.via.array.ptr = p; - o.via.array.size = 2; - p[0] = clmdep_msgpack::object(v.first, o.zone); - p[1] = clmdep_msgpack::object(v.second, o.zone); - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/pair.hpp" #endif // MSGPACK_TYPE_PAIR_HPP diff --git a/include/rpc/msgpack/adaptor/raw.hpp b/include/rpc/msgpack/adaptor/raw.hpp index a0134008..85ccd683 100644 --- a/include/rpc/msgpack/adaptor/raw.hpp +++ b/include/rpc/msgpack/adaptor/raw.hpp @@ -1,114 +1,17 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2009 FURUHASHI Sadayuki +// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_HPP #define MSGPACK_TYPE_RAW_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include -#include - -namespace clmdep_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 { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, clmdep_msgpack::type::raw_ref& v) const { - if(o.type != clmdep_msgpack::type::BIN) { throw clmdep_msgpack::type_error(); } - v.ptr = o.via.bin.ptr; - v.size = o.via.bin.size; - return o; - } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const clmdep_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()(clmdep_msgpack::object& o, const clmdep_msgpack::type::raw_ref& v) const { - o.type = clmdep_msgpack::type::BIN; - o.via.bin.ptr = v.ptr; - o.via.bin.size = v.size; - } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, const clmdep_msgpack::type::raw_ref& v) const { - static_cast(o) << v; - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond +#include "rpc/msgpack/adaptor/raw_decl.hpp" -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/raw.hpp" #endif // MSGPACK_TYPE_RAW_HPP diff --git a/include/rpc/msgpack/adaptor/raw_decl.hpp b/include/rpc/msgpack/adaptor/raw_decl.hpp new file mode 100644 index 00000000..88932506 --- /dev/null +++ b/include/rpc/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 "rpc/msgpack/v1/adaptor/raw_decl.hpp" +#include "rpc/msgpack/v2/adaptor/raw_decl.hpp" + +#endif // MSGPACK_TYPE_RAW_DECL_HPP diff --git a/include/rpc/msgpack/adaptor/set.hpp b/include/rpc/msgpack/adaptor/set.hpp index 405a9927..48f267fc 100644 --- a/include/rpc/msgpack/adaptor/set.hpp +++ b/include/rpc/msgpack/adaptor/set.hpp @@ -1,196 +1,15 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2015 FURUHASHI Sadayuki +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_SET_HPP #define MSGPACK_TYPE_SET_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_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()(clmdep_msgpack::object const& o) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object* p = o.via.array.ptr + o.via.array.size; - clmdep_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 > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::set& v) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object* p = o.via.array.ptr + o.via.array.size; - clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const std::set& v) const { - o.type = clmdep_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()); - clmdep_msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size)); - clmdep_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 = clmdep_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()(clmdep_msgpack::object const& o) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object* p = o.via.array.ptr + o.via.array.size; - clmdep_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 > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::multiset& v) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - clmdep_msgpack::object* p = o.via.array.ptr + o.via.array.size; - clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const std::multiset& v) const { - o.type = clmdep_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()); - clmdep_msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size)); - clmdep_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 = clmdep_msgpack::object(*it, o.zone); - ++p; - ++it; - } while(p < pend); - } - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/set.hpp" #endif // MSGPACK_TYPE_SET_HPP diff --git a/include/rpc/msgpack/adaptor/size_equal_only.hpp b/include/rpc/msgpack/adaptor/size_equal_only.hpp new file mode 100644 index 00000000..9daef986 --- /dev/null +++ b/include/rpc/msgpack/adaptor/size_equal_only.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_TYPE_SIZE_EQUAL_ONLY_HPP +#define MSGPACK_TYPE_SIZE_EQUAL_ONLY_HPP + +#include "rpc/msgpack/adaptor/size_equal_only_decl.hpp" + +#include "rpc/msgpack/v1/adaptor/size_equal_only.hpp" + +#endif // MSGPACK_TYPE_SIZE_EQUAL_ONLYL_HPP diff --git a/include/rpc/msgpack/adaptor/size_equal_only_decl.hpp b/include/rpc/msgpack/adaptor/size_equal_only_decl.hpp new file mode 100644 index 00000000..438609c4 --- /dev/null +++ b/include/rpc/msgpack/adaptor/size_equal_only_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_SIZE_EQUAL_ONLY_DECL_HPP +#define MSGPACK_TYPE_SIZE_EQUAL_ONLY_DECL_HPP + +#include "rpc/msgpack/v1/adaptor/size_equal_only_decl.hpp" +#include "rpc/msgpack/v2/adaptor/size_equal_only_decl.hpp" + +#endif // MSGPACK_TYPE_SIZE_EQUAL_ONLY_DECL_HPP diff --git a/include/rpc/msgpack/adaptor/string.hpp b/include/rpc/msgpack/adaptor/string.hpp index c9c5359f..c4908138 100644 --- a/include/rpc/msgpack/adaptor/string.hpp +++ b/include/rpc/msgpack/adaptor/string.hpp @@ -1,94 +1,15 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2015 FURUHASHI Sadayuki +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_STRING_HPP #define MSGPACK_TYPE_STRING_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template <> -struct convert { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::string& v) const { - switch (o.type) { - case clmdep_msgpack::type::BIN: - v.assign(o.via.bin.ptr, o.via.bin.size); - break; - case clmdep_msgpack::type::STR: - v.assign(o.via.str.ptr, o.via.str.size); - break; - default: - throw clmdep_msgpack::type_error(); - break; - } - return o; - } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object& o, const std::string& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = clmdep_msgpack::type::STR; - o.via.str.ptr = v.data(); - o.via.str.size = size; - } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, const std::string& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = clmdep_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 clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/string.hpp" #endif // MSGPACK_TYPE_STRING_HPP diff --git a/include/rpc/msgpack/adaptor/tr1/unordered_map.hpp b/include/rpc/msgpack/adaptor/tr1/unordered_map.hpp index 4fec3ba6..61bdc2f7 100644 --- a/include/rpc/msgpack/adaptor/tr1/unordered_map.hpp +++ b/include/rpc/msgpack/adaptor/tr1/unordered_map.hpp @@ -3,17 +3,9 @@ // // Copyright (C) 2008-2015 FURUHASHI Sadayuki // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_TR1_UNORDERED_MAP_HPP #define MSGPACK_TYPE_TR1_UNORDERED_MAP_HPP @@ -88,11 +80,11 @@ struct object_with_zone void operator()(clmdep_msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_map& v) const { o.type = clmdep_msgpack::type::MAP; if(v.empty()) { - o.via.map.ptr = nullptr; + o.via.map.ptr = MSGPACK_NULLPTR; o.via.map.size = 0; } else { uint32_t size = checked_get_container_size(v.size()); - clmdep_msgpack::object_kv* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object_kv)*size)); + clmdep_msgpack::object_kv* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object_kv)*size, MSGPACK_ZONE_ALIGNOF(clmdep_msgpack::object_kv))); clmdep_msgpack::object_kv* const pend = p + size; o.via.map.ptr = p; o.via.map.size = size; @@ -145,11 +137,11 @@ struct object_with_zone& v) const { o.type = clmdep_msgpack::type::MAP; if(v.empty()) { - o.via.map.ptr = nullptr; + o.via.map.ptr = MSGPACK_NULLPTR; o.via.map.size = 0; } else { uint32_t size = checked_get_container_size(v.size()); - clmdep_msgpack::object_kv* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object_kv)*size)); + clmdep_msgpack::object_kv* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object_kv)*size, MSGPACK_ZONE_ALIGNOF(clmdep_msgpack::object_kv))); clmdep_msgpack::object_kv* const pend = p + size; o.via.map.ptr = p; o.via.map.size = size; diff --git a/include/rpc/msgpack/adaptor/tr1/unordered_set.hpp b/include/rpc/msgpack/adaptor/tr1/unordered_set.hpp index e00b160d..51dfe4bd 100644 --- a/include/rpc/msgpack/adaptor/tr1/unordered_set.hpp +++ b/include/rpc/msgpack/adaptor/tr1/unordered_set.hpp @@ -3,17 +3,9 @@ // // Copyright (C) 2008-2015 FURUHASHI Sadayuki // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_TR1_UNORDERED_SET_HPP #define MSGPACK_TYPE_TR1_UNORDERED_SET_HPP @@ -86,11 +78,11 @@ struct object_with_zone void operator()(clmdep_msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_set& v) const { o.type = clmdep_msgpack::type::ARRAY; if(v.empty()) { - o.via.array.ptr = nullptr; + o.via.array.ptr = MSGPACK_NULLPTR; o.via.array.size = 0; } else { uint32_t size = checked_get_container_size(v.size()); - clmdep_msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size)); + clmdep_msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size, MSGPACK_ZONE_ALIGNOF(clmdep_msgpack::object))); clmdep_msgpack::object* const pend = p + size; o.via.array.ptr = p; o.via.array.size = size; @@ -140,11 +132,11 @@ struct object_with_zone& v) const { o.type = clmdep_msgpack::type::ARRAY; if(v.empty()) { - o.via.array.ptr = nullptr; + o.via.array.ptr = MSGPACK_NULLPTR; o.via.array.size = 0; } else { uint32_t size = checked_get_container_size(v.size()); - clmdep_msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size)); + clmdep_msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size, MSGPACK_ZONE_ALIGNOF(clmdep_msgpack::object))); clmdep_msgpack::object* const pend = p + size; o.via.array.ptr = p; o.via.array.size = size; diff --git a/include/rpc/msgpack/adaptor/v4raw.hpp b/include/rpc/msgpack/adaptor/v4raw.hpp index 8ddf786b..315f02e2 100644 --- a/include/rpc/msgpack/adaptor/v4raw.hpp +++ b/include/rpc/msgpack/adaptor/v4raw.hpp @@ -1,114 +1,17 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi +// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_HPP #define MSGPACK_TYPE_V4RAW_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include -#include - -namespace clmdep_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 { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, clmdep_msgpack::type::v4raw_ref& v) const { - if(o.type != clmdep_msgpack::type::STR) { throw clmdep_msgpack::type_error(); } - v.ptr = o.via.str.ptr; - v.size = o.via.str.size; - return o; - } -}; - -template <> -struct pack { - template - clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, const clmdep_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()(clmdep_msgpack::object& o, const clmdep_msgpack::type::v4raw_ref& v) const { - o.type = clmdep_msgpack::type::STR; - o.via.str.ptr = v.ptr; - o.via.str.size = v.size; - } -}; - -template <> -struct object_with_zone { - void operator()(clmdep_msgpack::object::with_zone& o, const clmdep_msgpack::type::v4raw_ref& v) const { - static_cast(o) << v; - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond +#include "rpc/msgpack/adaptor/v4raw_decl.hpp" -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/v4raw.hpp" #endif // MSGPACK_TYPE_V4RAW_HPP diff --git a/include/rpc/msgpack/adaptor/v4raw_decl.hpp b/include/rpc/msgpack/adaptor/v4raw_decl.hpp new file mode 100644 index 00000000..890620d2 --- /dev/null +++ b/include/rpc/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 "rpc/msgpack/v1/adaptor/v4raw_decl.hpp" +#include "rpc/msgpack/v2/adaptor/v4raw_decl.hpp" + +#endif // MSGPACK_TYPE_V4RAW_DECL_HPP diff --git a/include/rpc/msgpack/adaptor/vector.hpp b/include/rpc/msgpack/adaptor/vector.hpp index d5a2a12e..8e7016d6 100644 --- a/include/rpc/msgpack/adaptor/vector.hpp +++ b/include/rpc/msgpack/adaptor/vector.hpp @@ -1,129 +1,15 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_VECTOR_HPP #define MSGPACK_TYPE_VECTOR_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_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 clmdep_msgpack::object& o) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - std::vector v; - v.reserve(o.via.array.size); - if (o.via.array.size > 0) { - clmdep_msgpack::object* p = o.via.array.ptr; - clmdep_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 > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::vector& v) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - v.resize(o.via.array.size); - if (o.via.array.size > 0) { - clmdep_msgpack::object* p = o.via.array.ptr; - clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const std::vector& v) const { - o.type = clmdep_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()); - clmdep_msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size)); - clmdep_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 = clmdep_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 clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/vector.hpp" #endif // MSGPACK_TYPE_VECTOR_HPP diff --git a/include/rpc/msgpack/adaptor/vector_bool.hpp b/include/rpc/msgpack/adaptor/vector_bool.hpp index bfee60e6..5dadb6b8 100644 --- a/include/rpc/msgpack/adaptor/vector_bool.hpp +++ b/include/rpc/msgpack/adaptor/vector_bool.hpp @@ -1,96 +1,15 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2015 KONDO Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_VECTOR_BOOL_HPP #define MSGPACK_TYPE_VECTOR_BOOL_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/object_fwd.hpp" -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct convert > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::vector& v) const { - if (o.type != clmdep_msgpack::type::ARRAY) { throw clmdep_msgpack::type_error(); } - if (o.via.array.size > 0) { - v.resize(o.via.array.size); - clmdep_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 - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object::with_zone& o, const std::vector& v) const { - o.type = clmdep_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()); - clmdep_msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size)); - clmdep_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 = clmdep_msgpack::object(static_cast(*it), o.zone); - ++p; - ++it; - } while(p < pend); - } - } -}; - -} // namespace adaptor - -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond - -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/vector_bool.hpp" #endif // MSGPACK_TYPE_VECTOR_BOOL_HPP diff --git a/include/rpc/msgpack/adaptor/vector_char.hpp b/include/rpc/msgpack/adaptor/vector_char.hpp index a5416e8d..ba61de3b 100644 --- a/include/rpc/msgpack/adaptor/vector_char.hpp +++ b/include/rpc/msgpack/adaptor/vector_char.hpp @@ -1,97 +1,15 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2014-2015 KONDO Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_VECTOR_CHAR_HPP #define MSGPACK_TYPE_VECTOR_CHAR_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct convert > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::vector& v) const { - switch (o.type) { - case clmdep_msgpack::type::BIN: - v.resize(o.via.bin.size); - std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size); - break; - case clmdep_msgpack::type::STR: - v.resize(o.via.str.size); - std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size); - break; - default: - throw clmdep_msgpack::type_error(); - break; - } - return o; - } -}; - -template -struct pack > { - template - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object& o, const std::vector& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = clmdep_msgpack::type::BIN; - o.via.bin.ptr = &v.front(); - o.via.bin.size = size; - } -}; - -template -struct object_with_zone > { - void operator()(clmdep_msgpack::object::with_zone& o, const std::vector& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = clmdep_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 clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/vector_char.hpp" #endif // MSGPACK_TYPE_VECTOR_CHAR_HPP diff --git a/include/rpc/msgpack/adaptor/vector_unsigned_char.hpp b/include/rpc/msgpack/adaptor/vector_unsigned_char.hpp index 3321d0d6..d953c7af 100644 --- a/include/rpc/msgpack/adaptor/vector_unsigned_char.hpp +++ b/include/rpc/msgpack/adaptor/vector_unsigned_char.hpp @@ -1,97 +1,15 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2014-2015 KONDO Takatoshi +// Copyright (C) 2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_VECTOR_UNSIGNED_CHAR_HPP #define MSGPACK_TYPE_VECTOR_UNSIGNED_CHAR_HPP -#include "rpc/msgpack/versioning.hpp" -#include "rpc/msgpack/adaptor/adaptor_base.hpp" -#include "rpc/msgpack/adaptor/check_container_size.hpp" - -#include - -namespace clmdep_msgpack { - -/// @cond -MSGPACK_API_VERSION_NAMESPACE(v1) { -/// @endcond - -namespace adaptor { - -template -struct convert > { - clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, std::vector& v) const { - switch (o.type) { - case clmdep_msgpack::type::BIN: - v.resize(o.via.bin.size); - std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size); - break; - case clmdep_msgpack::type::STR: - v.resize(o.via.str.size); - std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size); - break; - default: - throw clmdep_msgpack::type_error(); - break; - } - return o; - } -}; - -template -struct pack > { - template - clmdep_msgpack::packer& operator()(clmdep_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()(clmdep_msgpack::object& o, const std::vector& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = clmdep_msgpack::type::BIN; - o.via.bin.ptr = reinterpret_cast(&v.front()); - o.via.bin.size = size; - } -}; - -template -struct object_with_zone > { - void operator()(clmdep_msgpack::object::with_zone& o, const std::vector& v) const { - uint32_t size = checked_get_container_size(v.size()); - o.type = clmdep_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 clmdep_msgpack +#include "rpc/msgpack/v1/adaptor/vector_unsigned_char.hpp" #endif // MSGPACK_TYPE_VECTOR_UNSIGNED_CHAR_HPP diff --git a/include/rpc/msgpack/cpp_config.hpp b/include/rpc/msgpack/cpp_config.hpp index 9836ba47..f399e8c8 100644 --- a/include/rpc/msgpack/cpp_config.hpp +++ b/include/rpc/msgpack/cpp_config.hpp @@ -1,135 +1,17 @@ // // MessagePack for C++ C++03/C++11 Adaptation // -// Copyright (C) 2013 KONDO Takatoshi +// Copyright (C) 2013-2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_HPP #define MSGPACK_CPP_CONFIG_HPP -#include "rpc/msgpack/versioning.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 - - - -#if defined __cplusplus -#if __cplusplus < 201103L - -#if !defined(nullptr) -# if _MSC_VER < 1600 -# define nullptr (0) -# endif -#endif - -#include - -namespace clmdep_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 clmdep_msgpack - - -#else // __cplusplus < 201103L - -#include -#include - -namespace clmdep_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 clmdep_msgpack - - -#endif // __cplusplus < 201103L +#include "rpc/msgpack/cpp_config_decl.hpp" -#endif // __cplusplus +#include "rpc/msgpack/v1/cpp_config.hpp" -#endif /* msgpack/cpp_config.hpp */ +#endif // MSGPACK_CPP_CONFIG_HPP diff --git a/include/rpc/msgpack/cpp_config_decl.hpp b/include/rpc/msgpack/cpp_config_decl.hpp new file mode 100644 index 00000000..44e1e627 --- /dev/null +++ b/include/rpc/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 "rpc/msgpack/v1/cpp_config_decl.hpp" +#include "rpc/msgpack/v2/cpp_config_decl.hpp" + +#endif // MSGPACK_CPP_CONFIG_DECL_HPP diff --git a/include/rpc/msgpack/fbuffer.h b/include/rpc/msgpack/fbuffer.h index d12830e4..d766c839 100644 --- a/include/rpc/msgpack/fbuffer.h +++ b/include/rpc/msgpack/fbuffer.h @@ -3,17 +3,9 @@ * * Copyright (C) 2013 Vladimir Volodko * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * 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_H #define MSGPACK_FBUFFER_H @@ -31,9 +23,9 @@ extern "C" { * @{ */ -static inline int msgpack_fbuffer_write(void* data, const char* buf, unsigned int len) +static inline int msgpack_fbuffer_write(void* data, const char* buf, size_t len) { - return (1 == fwrite(buf, len, 1, (FILE *)data)) ? 0 : -1; + return (len == fwrite(buf, len, 1, (FILE *)data)) ? 0 : -1; } /** @} */ diff --git a/include/rpc/msgpack/fbuffer.hpp b/include/rpc/msgpack/fbuffer.hpp index 460fdfcd..8a887bf2 100644 --- a/include/rpc/msgpack/fbuffer.hpp +++ b/include/rpc/msgpack/fbuffer.hpp @@ -3,66 +3,15 @@ // // Copyright (C) 2013 Vladimir Volodko // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// 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) // -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#ifndef MSGPACK_FBUFFER_HPP__ -#define MSGPACK_FBUFFER_HPP__ - -#include "rpc/msgpack/versioning.hpp" - -#include -#include - -namespace clmdep_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; -}; +#ifndef MSGPACK_FBUFFER_HPP +#define MSGPACK_FBUFFER_HPP -/// @cond -} // MSGPACK_API_VERSION_NAMESPACE(v1) -/// @endcond +#include "rpc/msgpack/fbuffer_decl.hpp" -} // namespace clmdep_msgpack +#include "rpc/msgpack/v1/fbuffer.hpp" -#endif /* msgpack/fbuffer.hpp */ +#endif // MSGPACK_FBUFFER_HPP diff --git a/include/rpc/msgpack/fbuffer_decl.hpp b/include/rpc/msgpack/fbuffer_decl.hpp new file mode 100644 index 00000000..76ae765f --- /dev/null +++ b/include/rpc/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 "rpc/msgpack/v1/fbuffer_decl.hpp" +#include "rpc/msgpack/v2/fbuffer_decl.hpp" + +#endif // MSGPACK_FBUFFER_DECL_HPP diff --git a/include/rpc/msgpack/gcc_atomic.h b/include/rpc/msgpack/gcc_atomic.h index 276acdc9..6b1b1a79 100644 --- a/include/rpc/msgpack/gcc_atomic.h +++ b/include/rpc/msgpack/gcc_atomic.h @@ -1,15 +1,7 @@ /* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * 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_GCC_ATOMIC_H diff --git a/include/rpc/msgpack/gcc_atomic.hpp b/include/rpc/msgpack/gcc_atomic.hpp new file mode 100644 index 00000000..3a71a609 --- /dev/null +++ b/include/rpc/msgpack/gcc_atomic.hpp @@ -0,0 +1,31 @@ +// +// MessagePack for C++ old gcc workaround for atomic operation +// +// Copyright (C) 2008-2013 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_GCC_ATOMIC_HPP +#define MSGPACK_GCC_ATOMIC_HPP + +#if defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41) + +#include "rpc/msgpack/gcc_atomic.h" +#include + +int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr) +{ + return __gnu_cxx::__exchange_and_add(ptr, -1) - 1; +} + +int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr) +{ + return __gnu_cxx::__exchange_and_add(ptr, 1) + 1; +} + +#endif // old gcc workaround + +#endif /* gcc_atomic.hpp */ diff --git a/include/rpc/msgpack/iterator.hpp b/include/rpc/msgpack/iterator.hpp index 2e33eeb3..4f29f0d5 100644 --- a/include/rpc/msgpack/iterator.hpp +++ b/include/rpc/msgpack/iterator.hpp @@ -1,46 +1,18 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2015 MIZUKI Hirata +// Copyright (C) 2015-2016 MIZUKI Hirata // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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_HPP #define MSGPACK_ITERATOR_HPP -#if !defined(MSGPACK_USE_CPP03) - -#include -namespace clmdep_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 -} +#include -#endif // !defined(MSGPACK_USE_CPP03) #endif // MSGPACK_ITERATOR_HPP diff --git a/include/rpc/msgpack/iterator_decl.hpp b/include/rpc/msgpack/iterator_decl.hpp new file mode 100644 index 00000000..a26709df --- /dev/null +++ b/include/rpc/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/rpc/msgpack/meta.hpp b/include/rpc/msgpack/meta.hpp index c6e976d4..68c9eb04 100644 --- a/include/rpc/msgpack/meta.hpp +++ b/include/rpc/msgpack/meta.hpp @@ -1,59 +1,18 @@ // // MessagePack for C++ static resolution routine // -// Copyright (C) 2015 KONDO Takatoshi +// Copyright (C) 2015-2016 KONDO Takatoshi // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) // #ifndef MSGPACK_META_HPP #define MSGPACK_META_HPP -#if !defined(MSGPACK_USE_CPP03) - -#include - -namespace clmdep_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