From bc9380d5e29876ddba62de9f63af1b32bf1fd6ba Mon Sep 17 00:00:00 2001 From: Junhyun Shim Date: Wed, 2 Mar 2022 15:04:30 +0100 Subject: [PATCH 01/84] Change Mako file extensions to cpp --- bindings/c/CMakeLists.txt | 8 ++++---- bindings/c/test/mako/{mako.c => mako.cpp} | 0 bindings/c/test/mako/{mako.h => mako.hpp} | 0 bindings/c/test/mako/{utils.c => utils.cpp} | 0 bindings/c/test/mako/{utils.h => utils.hpp} | 0 5 files changed, 4 insertions(+), 4 deletions(-) rename bindings/c/test/mako/{mako.c => mako.cpp} (100%) rename bindings/c/test/mako/{mako.h => mako.hpp} (100%) rename bindings/c/test/mako/{utils.c => utils.cpp} (100%) rename bindings/c/test/mako/{utils.h => utils.hpp} (100%) diff --git a/bindings/c/CMakeLists.txt b/bindings/c/CMakeLists.txt index 78dce4cdc9..31b65d83d1 100644 --- a/bindings/c/CMakeLists.txt +++ b/bindings/c/CMakeLists.txt @@ -81,10 +81,10 @@ endif() # check later whether this works if(NOT WIN32 AND NOT IS_ARM_MAC) set(MAKO_SRCS - test/mako/mako.c - test/mako/mako.h - test/mako/utils.c - test/mako/utils.h) + test/mako/mako.cpp + test/mako/mako.hpp + test/mako/utils.cpp + test/mako/utils.hpp) add_subdirectory(test/unit/third_party) find_package(Threads REQUIRED) set(UNIT_TEST_SRCS diff --git a/bindings/c/test/mako/mako.c b/bindings/c/test/mako/mako.cpp similarity index 100% rename from bindings/c/test/mako/mako.c rename to bindings/c/test/mako/mako.cpp diff --git a/bindings/c/test/mako/mako.h b/bindings/c/test/mako/mako.hpp similarity index 100% rename from bindings/c/test/mako/mako.h rename to bindings/c/test/mako/mako.hpp diff --git a/bindings/c/test/mako/utils.c b/bindings/c/test/mako/utils.cpp similarity index 100% rename from bindings/c/test/mako/utils.c rename to bindings/c/test/mako/utils.cpp diff --git a/bindings/c/test/mako/utils.h b/bindings/c/test/mako/utils.hpp similarity index 100% rename from bindings/c/test/mako/utils.h rename to bindings/c/test/mako/utils.hpp From b23c51ffccc2a25a12656d0ac3214a0f5d6fb90e Mon Sep 17 00:00:00 2001 From: Junhyun Shim Date: Wed, 2 Mar 2022 15:12:36 +0100 Subject: [PATCH 02/84] C++ wrapper for fdb_c API * Header-only * C objects wrapped in refcounting C++ objects * Accept lambdas as future callback * Type-safe access to Future values * throw/nothrow member functions --- bindings/c/CMakeLists.txt | 6 +- bindings/c/test/fdb.hpp | 552 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 557 insertions(+), 1 deletion(-) create mode 100644 bindings/c/test/fdb.hpp diff --git a/bindings/c/CMakeLists.txt b/bindings/c/CMakeLists.txt index 31b65d83d1..0058fd5354 100644 --- a/bindings/c/CMakeLists.txt +++ b/bindings/c/CMakeLists.txt @@ -99,6 +99,10 @@ if(NOT WIN32 AND NOT IS_ARM_MAC) test/unit/fdb_api.cpp test/unit/fdb_api.hpp) + add_library(fdb_cpp INTERFACE) + target_sources(fdb_cpp INTERFACE test/fdb.hpp) + target_include_directories(fdb_cpp INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/test) + target_link_libraries(fdb_cpp INTERFACE fmt::fmt) if(OPEN_FOR_IDE) add_library(fdb_c_performance_test OBJECT test/performance_test.c test/test.h) add_library(fdb_c_ryw_benchmark OBJECT test/ryw_benchmark.c test/test.h) @@ -143,7 +147,7 @@ if(NOT WIN32 AND NOT IS_ARM_MAC) # do not set RPATH for mako set_property(TARGET mako PROPERTY SKIP_BUILD_RPATH TRUE) - target_link_libraries(mako PRIVATE fdb_c fdbclient) + target_link_libraries(mako PRIVATE fdb_c fdbclient fmt::fmt Threads::Threads fdb_cpp) if(NOT OPEN_FOR_IDE) # Make sure that fdb_c.h is compatible with c90 diff --git a/bindings/c/test/fdb.hpp b/bindings/c/test/fdb.hpp new file mode 100644 index 0000000000..f0538ebcc0 --- /dev/null +++ b/bindings/c/test/fdb.hpp @@ -0,0 +1,552 @@ +#pragma once + +#ifndef FDB_API_VERSION +#define FDB_API_VERSION 710 +#endif + +#include +#include +#include +#include +#include +#include + +// introduce the option enums +#include + +namespace fdb { + +// hide C API to discourage mixing C/C++ API +namespace native { +#include +} + +using ByteString = std::basic_string; +using BytesRef = std::basic_string_view; +using CharsRef = std::string_view; +using KeyRef = BytesRef; +using ValueRef = BytesRef; + +inline uint8_t const* to_byte_ptr(char const* ptr) noexcept { + return reinterpret_cast(ptr); +} + +// get bytestring view from charstring: e.g. std::basic_string{_view} +template