diff --git a/CMakeLists.txt b/CMakeLists.txt index 05ea693817304568a6727e7d802382a721614139..11ccb223031131b585ae4f45d61cc4bb4d60565c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,9 +22,9 @@ cmake_minimum_required(VERSION 3.13) set(libcaosdb_VERSION 0.1.0) set(libcaosdb_COMPATIBLE_SERVER_VERSION_MAJOR 0) -set(libcaosdb_COMPATIBLE_SERVER_VERSION_MINOR 5) +set(libcaosdb_COMPATIBLE_SERVER_VERSION_MINOR 6) set(libcaosdb_COMPATIBLE_SERVER_VERSION_PATCH 0) -set(libcaosdb_COMPATIBLE_SERVER_VERSION_PRE_RELEASE "GRPC${libcaosdb_VERSION}") +set(libcaosdb_COMPATIBLE_SERVER_VERSION_PRE_RELEASE "") project(libcaosdb VERSION ${libcaosdb_VERSION} @@ -162,6 +162,9 @@ if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") $<INSTALL_INTERFACE:include> ) + target_include_directories(caosdb_grpc SYSTEM PUBLIC + ${CONAN_INCLUDE_DIRS} + ) else() add_library(caosdb SHARED ${libcaosdb_INCL} ${libcaosdb_SRC} ${GRPC_GENERATED}) @@ -178,12 +181,24 @@ target_include_directories(caosdb PUBLIC $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include> $<INSTALL_INTERFACE:include> ) +target_include_directories(caosdb SYSTEM PUBLIC + ${CONAN_INCLUDE_DIRS} +) add_library(ccaosdb SHARED src/ccaosdb.cpp) target_link_libraries(ccaosdb - ${LIBCAOSDB} ${CONAN_LIBS} + ${LIBCAOSDB} +) +target_include_directories(ccaosdb PUBLIC + $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include> + $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include> + $<INSTALL_INTERFACE:include> ) +target_include_directories(ccaosdb SYSTEM PUBLIC + ${CONAN_INCLUDE_DIRS} +) + add_executable(ccaosdbcli EXCLUDE_FROM_ALL src/ccaosdbcli.c) target_include_directories(ccaosdbcli SYSTEM PUBLIC @@ -194,9 +209,14 @@ target_include_directories(ccaosdbcli PUBLIC $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include> $<INSTALL_INTERFACE:include> ) +target_include_directories(ccaosdbcli SYSTEM PUBLIC + ${CONAN_INCLUDE_DIRS} +) + target_link_libraries(ccaosdbcli - ccaosdb ${CONAN_LIBS} + ${LIBCAOSDB} + ccaosdb ) add_executable(cxxcaosdbcli EXCLUDE_FROM_ALL src/cxxcaosdbcli.cpp) @@ -208,6 +228,9 @@ target_include_directories(cxxcaosdbcli PUBLIC $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include> $<INSTALL_INTERFACE:include> ) +target_include_directories(cxxcaosdbcli SYSTEM PUBLIC + ${CONAN_INCLUDE_DIRS} +) target_link_libraries(cxxcaosdbcli ${LIBCAOSDB} ${CONAN_LIBS} diff --git a/conanfile.py b/conanfile.py index 78425df0cf78e7b5d78344898b887a75c756429d..6fc869fb02b3e5577a5af06c647df1dcf3048958 100644 --- a/conanfile.py +++ b/conanfile.py @@ -23,7 +23,7 @@ class CaosdbConan(ConanFile): exports = ("*.cmake", "*CMakeLists.txt", "*.in", "*.h", "*.proto", "*.c", "*.cpp", "*.rst", "*.md", - ) + ) exports_sources = "src", "doc", "include", "test", "cmake", "proto" def config_options(self): diff --git a/doc/README_SETUP.md b/doc/README_SETUP.md index 0c81e17bba384dbd3274ee5d357b07adf2d5e64c..ceb857617f4c4a890a15afa65a7a58e7db857e76 100644 --- a/doc/README_SETUP.md +++ b/doc/README_SETUP.md @@ -102,7 +102,7 @@ The client will load the configuration file from the first existing file in the following locations (precedence from highest to lowest): 1. A file specified by the environment variable - `$CAOSDB_CLIENT_CONFIGURATION`. +`$CAOSDB_CLIENT_CONFIGURATION`. 2. `$PWD/caosdb_client.json` 3. `$PWD/caosdb-client.json` 4. `$PWD/.caosdb_client.json` @@ -124,10 +124,10 @@ For the tests there is a slightly different setup required (with option `-D CMAK 2. `conan install .. ` (with gcc, append ` -s "compiler.libcxx=libstdc++11"`, with apple-clang, append ` -s compiler.cppstd=17`) 3. `cmake -B . -D CMAKE_BUILD_TYPE=Debug ..` - * If your clang-format version is too old, formatting, linting etc. can be skipped: - `cmake -B . -D CMAKE_BUILD_TYPE=Debug -D SKIP_LINTING=ON ..` - * Depending on the clang version it might be necessary to also add - `-DCMAKE_CXX_FLAGS="-Wno-unused-parameter"` +* If your clang-format version is too old, formatting, linting etc. can be skipped: + `cmake -B . -D CMAKE_BUILD_TYPE=Debug -D SKIP_LINTING=ON ..` +* Depending on the clang version it might be necessary to also add + `-DCMAKE_CXX_FLAGS="-Wno-unused-parameter"` 5. `cmake --build .` #### Run #### diff --git a/include/caosdb/certificate_provider.h b/include/caosdb/certificate_provider.h index 197ab7277a8110063351718897b65c8db3289768..1fd4a80b630e53b8b704b29f7803837a3cff6ced 100644 --- a/include/caosdb/certificate_provider.h +++ b/include/caosdb/certificate_provider.h @@ -22,10 +22,9 @@ #ifndef CAOSDB_CERTIFICATE_PROVIDER_H #define CAOSDB_CERTIFICATE_PROVIDER_H -#include <boost/filesystem/path.hpp> // for path - +#include <filesystem> // for path namespace caosdb::configuration { -using boost::filesystem::path; +using std::filesystem::path; class CertificateProvider { public: diff --git a/include/caosdb/configuration.h b/include/caosdb/configuration.h index 1c3f0148a6679fd152563bd11859d2cab28a9d1a..b360632cf98b8f00d8f19246b09a30b0a98f1e4e 100644 --- a/include/caosdb/configuration.h +++ b/include/caosdb/configuration.h @@ -41,8 +41,6 @@ #include <string> // for string namespace caosdb::configuration { -using boost::filesystem::exists; -using boost::filesystem::path; using boost::json::array; using boost::json::object; using boost::json::value; @@ -52,6 +50,8 @@ using caosdb::exceptions::ConfigurationError; using caosdb::utility::load_json_file; using google::protobuf::Arena; using grpc::ChannelCredentials; +using std::filesystem::exists; +using std::filesystem::path; const std::string logger_name = "caosdb::configuration"; diff --git a/include/caosdb/connection.h b/include/caosdb/connection.h index c11eaa1d6863f9f256164e0897463ff1afb720ad..238fb1c97331feb26be577ca6f225b1c5b860cea 100644 --- a/include/caosdb/connection.h +++ b/include/caosdb/connection.h @@ -27,21 +27,20 @@ * @date 2021-05-18 * @brief Configuration and setup of the connection. */ -#include "caosdb/authentication.h" // for Authenticator -#include "caosdb/configuration.h" // for ConnectionConfigura... +#include "caosdb/authentication.h" // for Authenticator +#include "caosdb/configuration.h" // for ConnectionConfigura... #include "caosdb/entity/v1/main.grpc.pb.h" // for EntityTransactionSe... #include "caosdb/info.h" // for VersionInfo #include "caosdb/info/v1/main.grpc.pb.h" // for GeneralInfoService:... -#include "caosdb/transaction.h" // for Transaction -#include "caosdb/transaction_status.h" // for TransactionStatus -#include <boost/filesystem/path.hpp> // for path -#include <grpcpp/channel.h> // for Channel -#include <map> // for map -#include <memory> // for shared_ptr, unique_ptr -#include <string> // for string, basic_string +#include "caosdb/transaction.h" // for Transaction +#include "caosdb/transaction_status.h" // for TransactionStatus +#include <filesystem> // for path +#include <grpcpp/channel.h> // for Channel +#include <map> // for map +#include <memory> // for shared_ptr, unique_ptr +#include <string> // for string, basic_string namespace caosdb::connection { -using boost::filesystem::path; using caosdb::authentication::Authenticator; using caosdb::configuration::ConnectionConfiguration; using caosdb::entity::v1::EntityTransactionService; @@ -50,6 +49,7 @@ using caosdb::info::VersionInfo; using caosdb::info::v1::GeneralInfoService; using caosdb::transaction::Transaction; using caosdb::transaction::TransactionStatus; +using std::filesystem::path; /** * @brief A reusable connection to a CaosDBServer. diff --git a/include/caosdb/constants.h.in b/include/caosdb/constants.h.in index bfec36bfbebf91fcd3e9eed38dd9ff305afc7a74..a42c9dfd563df0a340553daf3cbcf3726bf0054e 100644 --- a/include/caosdb/constants.h.in +++ b/include/caosdb/constants.h.in @@ -22,22 +22,25 @@ #ifndef CAOSDB_CONSTANTS_H #define CAOSDB_CONSTANTS_H +#ifndef __GNUC__ +# define __attribute__(x) +#endif #ifdef __cplusplus namespace caosdb { #endif // clang-format off -const int LIBCAOSDB_VERSION_MAJOR = @libcaosdb_VERSION_MAJOR@; -const int LIBCAOSDB_VERSION_MINOR = @libcaosdb_VERSION_MINOR@; -const int LIBCAOSDB_VERSION_PATCH = @libcaosdb_VERSION_PATCH@; -const int COMPATIBLE_SERVER_VERSION_MAJOR = @libcaosdb_COMPATIBLE_SERVER_VERSION_MAJOR@; -const int COMPATIBLE_SERVER_VERSION_MINOR = @libcaosdb_COMPATIBLE_SERVER_VERSION_MINOR@; -const int COMPATIBLE_SERVER_VERSION_PATCH = @libcaosdb_COMPATIBLE_SERVER_VERSION_PATCH@; -const char* COMPATIBLE_SERVER_VERSION_PRE_RELEASE = "@libcaosdb_COMPATIBLE_SERVER_VERSION_PRE_RELEASE@"; +static const int LIBCAOSDB_VERSION_MAJOR = @libcaosdb_VERSION_MAJOR@; +static const int LIBCAOSDB_VERSION_MINOR = @libcaosdb_VERSION_MINOR@; +static const int LIBCAOSDB_VERSION_PATCH = @libcaosdb_VERSION_PATCH@; +static const int COMPATIBLE_SERVER_VERSION_MAJOR = @libcaosdb_COMPATIBLE_SERVER_VERSION_MAJOR@; +static const int COMPATIBLE_SERVER_VERSION_MINOR = @libcaosdb_COMPATIBLE_SERVER_VERSION_MINOR@; +static const int COMPATIBLE_SERVER_VERSION_PATCH = @libcaosdb_COMPATIBLE_SERVER_VERSION_PATCH@; +__attribute__((unused)) static const char* COMPATIBLE_SERVER_VERSION_PRE_RELEASE = "@libcaosdb_COMPATIBLE_SERVER_VERSION_PRE_RELEASE@"; /** * Precedence of configuration files from highest to lowest. */ -const char* LIBCAOSDB_CONFIGURATION_FILES_PRECEDENCE[] = { +__attribute__((unused)) static const char* LIBCAOSDB_CONFIGURATION_FILES_PRECEDENCE[] = { "$CAOSDB_CLIENT_CONFIGURATION", "caosdb_client.json", "caosdb-client.json", diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h index a46c01616a737a6aec114d94fdb76e3c902f62e9..11955fc91330c435bdc348f2bb5c6ed15aef37b0 100644 --- a/include/caosdb/entity.h +++ b/include/caosdb/entity.h @@ -36,14 +36,13 @@ #include "caosdb/protobuf_helper.h" // for get_arena #include "caosdb/status_code.h" // for StatusCode #include "caosdb/value.h" // for Value -#include <boost/filesystem/operations.hpp> // for exists, is_di... -#include <boost/filesystem/path.hpp> // for path #include <boost/log/core/record.hpp> // for record #include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring... #include <boost/log/sources/record_ostream.hpp> // for basic_record_... #include <boost/preprocessor/seq/limits/enum_256.hpp> // for BOOST_PP_SEQ_... #include <boost/preprocessor/seq/limits/size_256.hpp> // for BOOST_PP_SEQ_... #include <cstdint> // for int64_t +#include <filesystem> // for path #include <google/protobuf/arena.h> // for Arena #include <google/protobuf/message.h> // for RepeatedPtrField #include <iosfwd> // for streamsize @@ -56,9 +55,9 @@ #include <vector> // for vector namespace caosdb::entity { -using boost::filesystem::exists; -using boost::filesystem::is_directory; using caosdb::entity::v1::IdResponse; +using std::filesystem::exists; +using std::filesystem::is_directory; using ProtoParent = caosdb::entity::v1::Parent; using ProtoProperty = caosdb::entity::v1::Property; using ProtoEntity = caosdb::entity::v1::Entity; @@ -114,7 +113,7 @@ const std::map<Role, std::string> role_names = {{Role::UNSPECIFIED, "UNSPECIFIED struct FileDescriptor { FileTransmissionId *file_transmission_id; ProtoFileDescriptor *wrapped; - boost::filesystem::path local_path; + std::filesystem::path local_path; }; /** @@ -776,7 +775,7 @@ public: this->value = other.value; this->properties = other.properties; this->parents = other.parents; - this->file_descriptor.local_path = boost::filesystem::path(other.file_descriptor.local_path); + this->file_descriptor.local_path = std::filesystem::path(other.file_descriptor.local_path); this->file_descriptor.file_transmission_id->CopyFrom( *other.file_descriptor.file_transmission_id); this->file_descriptor.wrapped->CopyFrom(*other.file_descriptor.wrapped); @@ -871,11 +870,11 @@ public: inline auto GetFileDescriptor() -> FileDescriptor & { return this->file_descriptor; } - inline auto GetLocalPath() const noexcept -> const boost::filesystem::path & { + inline auto GetLocalPath() const noexcept -> const std::filesystem::path & { return this->file_descriptor.local_path; } - inline auto SetLocalPath(const boost::filesystem::path &local_path) noexcept -> StatusCode { + inline auto SetLocalPath(const std::filesystem::path &local_path) noexcept -> StatusCode { if (GetRole() != Role::FILE) { CAOSDB_LOG_WARN(logger_name) << "Entity::SetLocalPath failed. This is not a file entity."; return StatusCode::NOT_A_FILE_ENTITY; diff --git a/include/caosdb/file_transmission/file_reader.h b/include/caosdb/file_transmission/file_reader.h index 5820c1e9294c76f0f777a6e7cfae9cde7ebf490f..14f8614896de79b15e9bb793a04ac17f40f27fec 100644 --- a/include/caosdb/file_transmission/file_reader.h +++ b/include/caosdb/file_transmission/file_reader.h @@ -49,21 +49,19 @@ #ifndef CAOSDB_FILE_TRANSMISSION_FILE_READER_H #define CAOSDB_FILE_TRANSMISSION_FILE_READER_H -#include <boost/filesystem/fstream.hpp> // for ifstream -#include <boost/filesystem/operations.hpp> // for exists -#include <boost/filesystem/path.hpp> // for path -#include <cstddef> // for size_t -#include <fstream> // for ifstream, size_t -#include <string> // for string +#include <cstddef> // for size_t +#include <filesystem> // for ifstream +#include <fstream> // for ifstream, size_t +#include <string> // for string namespace caosdb::transaction { -using boost::filesystem::exists; -using boost::filesystem::ifstream; -using boost::filesystem::path; +using std::ifstream; +using std::filesystem::exists; +using std::filesystem::path; class FileReader final { public: - FileReader(boost::filesystem::path filename); + FileReader(std::filesystem::path filename); ~FileReader() = default; @@ -81,7 +79,7 @@ private: void openFile(); std::ifstream stream_; - boost::filesystem::path filename_; + std::filesystem::path filename_; unsigned long long size_; }; diff --git a/include/caosdb/file_transmission/file_writer.h b/include/caosdb/file_transmission/file_writer.h index 801d74b9547951d2a3b86ed4b333bfb4b7035aa9..165178b1e3b44f9d3208220d1422af1bb61d0833 100644 --- a/include/caosdb/file_transmission/file_writer.h +++ b/include/caosdb/file_transmission/file_writer.h @@ -49,15 +49,15 @@ #ifndef CAOSDB_FILE_TRANSMISSION_FILE_WRITER_H #define CAOSDB_FILE_TRANSMISSION_FILE_WRITER_H -#include <boost/filesystem/path.hpp> // for path -#include <fstream> // for ofstream -#include <string> // for string +#include <filesystem> // for path +#include <fstream> // for ofstream +#include <string> // for string namespace caosdb::transaction { class FileWriter final { public: - FileWriter(boost::filesystem::path filename); + FileWriter(std::filesystem::path filename); ~FileWriter() = default; @@ -73,7 +73,7 @@ private: void openFile(); std::ofstream stream_; - boost::filesystem::path filename_; + std::filesystem::path filename_; }; } // namespace caosdb::transaction diff --git a/include/caosdb/protobuf_helper.h b/include/caosdb/protobuf_helper.h index 55a229b697eeac5d292d9e4d73296665fb44c7ef..ef4cb8383eb384cd058a3f210c9d27f99b199658 100644 --- a/include/caosdb/protobuf_helper.h +++ b/include/caosdb/protobuf_helper.h @@ -22,9 +22,8 @@ #ifndef CAOSDB_PROTOBUF_HELPER_H #define CAOSDB_PROTOBUF_HELPER_H -#include <google/protobuf/arena.h> // for Arena -// IWYU pragma: no_include "google/protobuf/extension_set.h" -// IWYU pragma: no_include "google/protobuf/generated_message_util.h" +// IWYU pragma: no_include <google/protobuf/extension_set.h> +#include <google/protobuf/arena.h> // for Arena #include <google/protobuf/util/json_util.h> // for JsonOptions, MessageToJs... #include <string> // for string diff --git a/include/caosdb/status_code.h b/include/caosdb/status_code.h index e1a382191b5bd4559c554e2fc3e084103c27c3cc..41dad5bddd918ac5cc42e577798676bcf8b6bea4 100644 --- a/include/caosdb/status_code.h +++ b/include/caosdb/status_code.h @@ -67,7 +67,7 @@ enum StatusCode { TRANSACTION_TYPE_ERROR = 26, UNSUPPORTED_FEATURE = 27, ORIGINAL_ENTITY_MISSING_ID = 28, - EXTERN_C_ASSIGNMENT_ERROR = 29, + // EXTERN_C_ASSIGNMENT_ERROR = 29, ENTITY_CANNOT_HAVE_A_DATA_TYPE = 30, ENTITY_CANNOT_HAVE_A_VALUE = 31, NOT_A_FILE_ENTITY = 32, diff --git a/include/caosdb/transaction.h b/include/caosdb/transaction.h index 3ff5e077f4aa144c7dfa453ce13fe1a01836810e..6fc429ad0cb10c9df88c705e2874834da628ff6f 100644 --- a/include/caosdb/transaction.h +++ b/include/caosdb/transaction.h @@ -55,12 +55,12 @@ return StatusCode::TRANSACTION_STATUS_ERROR; \ } \ switch (this->transaction_type) { \ - case NONE: \ + case TransactionType::NONE: \ this->transaction_type = TransactionType::READ_ONLY; \ break; \ - case READ_ONLY: \ + case TransactionType::READ_ONLY: \ break; \ - case MIXED_READ_AND_WRITE: \ + case TransactionType::MIXED_READ_AND_WRITE: \ break; \ default: \ CAOSDB_LOG_ERROR_AND_RETURN_STATUS( \ @@ -91,11 +91,11 @@ return StatusCode::TRANSACTION_STATUS_ERROR; \ } \ switch (this->transaction_type) { \ - case NONE: \ + case TransactionType::NONE: \ this->transaction_type = TransactionType::MIXED_WRITE; \ - case DELETE: \ - case MIXED_WRITE: \ - case MIXED_READ_AND_WRITE: \ + case TransactionType::DELETE_ONLY: \ + case TransactionType::MIXED_WRITE: \ + case TransactionType::MIXED_READ_AND_WRITE: \ break; \ default: \ CAOSDB_LOG_ERROR_AND_RETURN_STATUS( \ @@ -113,11 +113,11 @@ return StatusCode::TRANSACTION_STATUS_ERROR; \ } \ switch (this->transaction_type) { \ - case NONE: \ + case TransactionType::NONE: \ this->transaction_type = TransactionType::MIXED_WRITE; \ - case INSERT: \ - case MIXED_WRITE: \ - case MIXED_READ_AND_WRITE: \ + case TransactionType::INSERT_ONLY: \ + case TransactionType::MIXED_WRITE: \ + case TransactionType::MIXED_READ_AND_WRITE: \ break; \ default: \ CAOSDB_LOG_ERROR_AND_RETURN_STATUS( \ @@ -135,11 +135,11 @@ return StatusCode::TRANSACTION_STATUS_ERROR; \ } \ switch (this->transaction_type) { \ - case NONE: \ + case TransactionType::NONE: \ this->transaction_type = TransactionType::MIXED_WRITE; \ - case UPDATE: \ - case MIXED_WRITE: \ - case MIXED_READ_AND_WRITE: \ + case TransactionType::UPDATE_ONLY: \ + case TransactionType::MIXED_WRITE: \ + case TransactionType::MIXED_READ_AND_WRITE: \ break; \ default: \ CAOSDB_LOG_ERROR_AND_RETURN_STATUS( \ @@ -287,9 +287,9 @@ public: enum TransactionType { NONE, //!< Unspecified or not specified yet. READ_ONLY, //!< Only retrievals (by id, by query) - INSERT, //!< Only insertions - UPDATE, //!< Only updates - DELETE, //!< Only deletions + INSERT_ONLY, //!< Only insertions + UPDATE_ONLY, //!< Only updates + DELETE_ONLY, //!< Only deletions MIXED_WRITE, //!< Only insertions, deletions, updates MIXED_READ_AND_WRITE //!< all kind of transaction. }; diff --git a/include/caosdb/utility.h b/include/caosdb/utility.h index 5af1b491c0b5b9d48606ba6b46130b3ef3de1d9c..0a4d65e883ccfb6cc8f41d1c412bef5433b89417 100644 --- a/include/caosdb/utility.h +++ b/include/caosdb/utility.h @@ -25,15 +25,13 @@ #include "caosdb/entity.h" // for Importance, Role #include <boost/beast/core/detail/base64.hpp> // for encoded_size #include <boost/beast/core/detail/base64.ipp> // for encode -#include <boost/filesystem/operations.hpp> // for exists -#include <boost/filesystem/path.hpp> // for path -#include <boost/filesystem/fstream.hpp> // for basic_ifstream, ifstream #include <boost/filesystem/string_file.hpp> // for load_string_file #include <boost/json/stream_parser.hpp> // for stream_parser #include <boost/json/value.hpp> // for value #include <boost/lexical_cast.hpp> // for lexical_cast #include <cassert> // for assert #include <cstdlib> // for getenv +#include <filesystem> // for path #include <fstream> // for basic_istream<>::__ist... #include <memory> // for allocator, unique_ptr #include <stdexcept> // for logic_error @@ -42,11 +40,11 @@ #include <typeinfo> // for type_info namespace caosdb::utility { -using boost::filesystem::exists; -using boost::filesystem::ifstream; -using boost::filesystem::path; using boost::json::stream_parser; using boost::json::value; +using std::ifstream; +using std::filesystem::exists; +using std::filesystem::path; /** * @brief Get the name of the enum value. May be useful for higher-order CaosDB clients. @@ -86,9 +84,9 @@ auto getEnumValueFromName<caosdb::entity::Role>(const std::string &name) -> caos /** * @brief Read a text file into a string and return the file's content. */ -inline auto load_string_file(const path &path) -> std::string { +inline auto load_string_file(const path &file_path) -> std::string { std::string result; - boost::filesystem::load_string_file(path, result); + boost::filesystem::load_string_file(file_path.string(), result); return result; } diff --git a/include/ccaosdb.h b/include/ccaosdb.h index 4d1b99dd151fbf09a53d9b80c0963ee3d3368c67..48d0da757351508ed194e52635670d0c24e53164 100644 --- a/include/ccaosdb.h +++ b/include/ccaosdb.h @@ -20,10 +20,14 @@ * */ -#include <cstdint> // for int64_t - +#ifndef CCAOSDB_H +#define CCAOSDB_H #ifdef __cplusplus +#include <cstdint> // for int64_t extern "C" { +#else +#include <stdint.h> // for int64_t +#include <stdbool.h> // for bool #endif /** @@ -70,7 +74,7 @@ int caosdb_status_code_OTHER_CLIENT_ERROR(); */ typedef struct caosdb_connection_connection { void *wrapped_connection; - bool _deletable = false; + bool _deletable; } caosdb_connection_connection; /** @@ -82,7 +86,7 @@ typedef struct caosdb_connection_connection { */ typedef struct caosdb_connection_connection_configuration { void *wrapped_connection_configuration; - bool _deletable = false; + bool _deletable; } caosdb_connection_connection_configuration; /** @@ -102,12 +106,12 @@ typedef struct caosdb_info_version_info { typedef struct caosdb_connection_certificate_provider { void *wrapped_certificate_provider; - bool _deletable = false; + bool _deletable; } caosdb_connection_certificate_provider; typedef struct caosdb_authentication_authenticator { void *wrapped_authenticator; - bool _deletable = false; + bool _deletable; } caosdb_authentication_authenticator; /** @@ -266,7 +270,7 @@ int caosdb_connection_connection_manager_get_connection(caosdb_connection_connec typedef struct caosdb_transaction_transaction { void *wrapped_transaction; - bool _deletable = false; + bool _deletable; } caosdb_transaction_transaction; /** @@ -292,12 +296,12 @@ int caosdb_transaction_transaction_execute(caosdb_transaction_transaction *trans typedef struct caosdb_transaction_result_set { void *wrapped_result_set; - bool _deletable = false; + bool _deletable; } caosdb_transaction_result_set; typedef struct caosdb_entity_entity { void *wrapped_entity; - bool _deletable = false; + bool _deletable; } caosdb_entity_entity; int caosdb_transaction_transaction_get_result_set(caosdb_transaction_transaction *transaction, @@ -348,27 +352,27 @@ int caosdb_transaction_transaction_delete_by_id(caosdb_transaction_transaction * typedef struct caosdb_entity_property { void *wrapped_property; - bool _deletable = false; + bool _deletable; } caosdb_entity_property; typedef struct caosdb_entity_parent { void *wrapped_parent; - bool _deletable = false; + bool _deletable; } caosdb_entity_parent; typedef struct caosdb_entity_message { void *wrapped_message; - bool _deletable = false; + bool _deletable; } caosdb_entity_message; typedef struct caosdb_entity_value { void *wrapped_value; - bool _deletable = false; + bool _deletable; } caosdb_entity_value; typedef struct caosdb_entity_datatype { void *wrapped_datatype; - bool _deletable = false; + bool _deletable; } caosdb_entity_datatype; // GETTERS FOR EVERYTHING @@ -494,3 +498,4 @@ int caosdb_entity_parent_set_name(caosdb_entity_parent *parent, const char *name #ifdef __cplusplus } #endif +#endif diff --git a/src/caosdb/configuration.cpp b/src/caosdb/configuration.cpp index aa35901c9bd116dba17c4ceed164e4ccbac6dfe7..90cc97b3cebc1b39a1b376805ae73cc068173ef7 100644 --- a/src/caosdb/configuration.cpp +++ b/src/caosdb/configuration.cpp @@ -26,9 +26,6 @@ #include "caosdb/log_level.h" // for CAOSDB_DEFAULT... #include "caosdb/status_code.h" // for StatusCode #include "caosdb/utility.h" // for get_home_direc... -#include <boost/filesystem/operations.hpp> // for exists -#include <boost/filesystem/path.hpp> // for path, path::i... -#include <boost/iterator/iterator_facade.hpp> // for iterator_facad... #include <boost/json/impl/object.hpp> // for object::at #include <boost/json/object.hpp> // for object, objec... #include <boost/json/string.hpp> // for string @@ -46,15 +43,13 @@ #include <exception> // IWYU pragma: keep // IWYU pragma: no_include <bits/exception.h> #include <grpcpp/security/credentials.h> // for SslCredentials -#include <iostream> -#include <iterator> // for next -#include <map> // for map -#include <stdexcept> // for out_of_range -#include <string> // for string, operator+ +#include <iterator> // for next +#include <map> // for map +#include <sstream> // for basic_stringb... +#include <stdexcept> // for out_of_range +#include <string> // for string, operator+ namespace caosdb::configuration { -using boost::filesystem::exists; -using boost::filesystem::path; using boost::json::object; using boost::json::value; using caosdb::authentication::Authenticator; @@ -72,6 +67,8 @@ using caosdb::utility::load_string_file; using grpc::InsecureChannelCredentials; using grpc::SslCredentials; using grpc::SslCredentialsOptions; +using std::filesystem::exists; +using std::filesystem::path; PemFileCertificateProvider::PemFileCertificateProvider(const path &path) { this->certificate_provider = load_string_file(path); @@ -477,12 +474,12 @@ auto ConfigurationManager::InitializeDefaults() -> int { // NOLINT configuration_file_path = std::make_unique<path>(); const path raw(configuration_file); // resolve home directory - for (auto segment = raw.begin(); segment != raw.end(); ++segment) { - if (segment->string() == "$HOME") { + for (const auto &segment : raw) { + if (segment.string() == "$HOME") { path expanded_home(get_home_directory()); *configuration_file_path /= expanded_home; } else { - *configuration_file_path /= *segment; + *configuration_file_path /= segment; } } if (exists(*configuration_file_path)) { diff --git a/src/caosdb/file_transmission/download_request_handler.cpp b/src/caosdb/file_transmission/download_request_handler.cpp index e915075bdc5c8583c3e2ed2a5b7d979811e34942..23520e0d78c5c8c8606ad5acf7611ba7c4806fc4 100644 --- a/src/caosdb/file_transmission/download_request_handler.cpp +++ b/src/caosdb/file_transmission/download_request_handler.cpp @@ -51,7 +51,6 @@ #include "caosdb/protobuf_helper.h" // for get_arena #include "caosdb/status_code.h" // for GENERIC_RPC_E... #include "caosdb/transaction_status.h" // for TransactionStatus -#include <boost/filesystem/path.hpp> // for operator<<, path #include <boost/log/core/record.hpp> // for record #include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring... #include <boost/log/sources/record_ostream.hpp> // for basic_record_... @@ -59,13 +58,14 @@ #include <boost/preprocessor/seq/limits/size_256.hpp> // for BOOST_PP_SEQ_... #include <exception> // IWYU pragma: keep // IWYU pragma: no_include <bits/exception.h> +#include <filesystem> // for operator<<, path #include <google/protobuf/arena.h> // for Arena #include <grpcpp/impl/codegen/async_stream.h> // for ClientAsyncRe... #include <grpcpp/impl/codegen/client_context.h> // for ClientContext #include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue #include <grpcpp/impl/codegen/status.h> // for Status #include <grpcpp/impl/codegen/status_code_enum.h> // for OK, UNAUTHENT... -#include <iostream> // for char_traits +#include <sstream> // for streamsize #include <stdexcept> // for runtime_error #include <string> // for string, opera... #include <utility> // for move diff --git a/src/caosdb/file_transmission/file_reader.cpp b/src/caosdb/file_transmission/file_reader.cpp index 1a78e5a76513ae0aaf94b2ae4967af5d7b66e0c0..e943153ca7cfcc87907ed88afb1995ad31cde71d 100644 --- a/src/caosdb/file_transmission/file_reader.cpp +++ b/src/caosdb/file_transmission/file_reader.cpp @@ -48,13 +48,12 @@ */ #include "caosdb/file_transmission/file_reader.h" #include "caosdb/file_transmission/file_error.h" // for FileIOError -#include <boost/filesystem/path.hpp> // for path +#include <filesystem> // for path #include <utility> // for move namespace caosdb::transaction { -FileReader::FileReader(boost::filesystem::path filename) - : filename_(std::move(filename)), size_(0) { +FileReader::FileReader(std::filesystem::path filename) : filename_(std::move(filename)), size_(0) { this->openFile(); } diff --git a/src/caosdb/file_transmission/file_writer.cpp b/src/caosdb/file_transmission/file_writer.cpp index 2c7f2a6000718366f846a4be61dd5c2144370a65..0f0161fbcafe1df7f6ffa271dcce8af9cc10fe82 100644 --- a/src/caosdb/file_transmission/file_writer.cpp +++ b/src/caosdb/file_transmission/file_writer.cpp @@ -48,12 +48,12 @@ */ #include "caosdb/file_transmission/file_writer.h" #include "caosdb/file_transmission/file_error.h" // for FileIOError -#include <boost/filesystem/path.hpp> // for path +#include <filesystem> // for path #include <utility> // for move namespace caosdb::transaction { -FileWriter::FileWriter(boost::filesystem::path filename) : filename_(std::move(filename)) { +FileWriter::FileWriter(std::filesystem::path filename) : filename_(std::move(filename)) { this->openFile(); } diff --git a/src/caosdb/file_transmission/upload_request_handler.cpp b/src/caosdb/file_transmission/upload_request_handler.cpp index bc74391753a0c7c3dce01f80d8fa67acc9e782cd..71f1106b78397a435638a0a1695bb86cb02a3edc 100644 --- a/src/caosdb/file_transmission/upload_request_handler.cpp +++ b/src/caosdb/file_transmission/upload_request_handler.cpp @@ -52,7 +52,6 @@ #include "caosdb/status_code.h" // for GENERIC_RPC_E... #include "caosdb/transaction_status.h" // for TransactionStatus #include <algorithm> // for min -#include <boost/filesystem/path.hpp> // for operator<<, path #include <boost/log/core/record.hpp> // for record #include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring... #include <boost/log/sources/record_ostream.hpp> // for basic_record_... @@ -61,6 +60,7 @@ #include <cstdint> // for uint64_t #include <exception> // IWYU pragma: keep // IWYU pragma: no_include <bits/exception.h> +#include <filesystem> // for operator<<, path #include <google/protobuf/arena.h> // for Arena #include <grpcpp/impl/codegen/async_stream.h> // for ClientAsyncWr... #include <grpcpp/impl/codegen/call_op_set.h> // for WriteOptions @@ -68,7 +68,7 @@ #include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue #include <grpcpp/impl/codegen/status.h> // for Status #include <grpcpp/impl/codegen/status_code_enum.h> // for OK, UNAUTHENT... -#include <iostream> // for endl, streamsize +#include <sstream> // for streamsize #include <string> // for basic_string #include <utility> // for move diff --git a/src/caosdb/logging.cpp b/src/caosdb/logging.cpp index ead331da4f91d0053d413846158425f2bdb0667e..51b4118515b4ddeda10411e5966b03c21f29449e 100644 --- a/src/caosdb/logging.cpp +++ b/src/caosdb/logging.cpp @@ -26,6 +26,7 @@ #include <boost/log/attributes/clock.hpp> #include <boost/log/core/core.hpp> // for core #include <boost/log/core/record.hpp> +#include <boost/log/sources/global_logger_storage.hpp> #include <boost/log/sources/record_ostream.hpp> #include <boost/log/sources/severity_channel_logger.hpp> #include <boost/log/utility/setup/from_settings.hpp> diff --git a/src/caosdb/status_code_description.cpp b/src/caosdb/status_code_description.cpp index 5823943cfd7f79416cabb61662f778bac5de9bf8..a18c3fbcba3c93f66b837bbfe0d7e0ff725ff4ca 100644 --- a/src/caosdb/status_code_description.cpp +++ b/src/caosdb/status_code_description.cpp @@ -152,9 +152,9 @@ auto get_status_description(int code) -> const std::string & { {StatusCode::FILE_UPLOAD_ERROR, "The transaction failed during the upload of the files"}, {StatusCode::UNSUPPORTED_FEATURE, "This feature is not available in the this client implementation."}, - {StatusCode::EXTERN_C_ASSIGNMENT_ERROR, - "You tried to assign a new object to the wrapped void pointer. You have " - "to delete the old pointee first."}, + //{StatusCode::EXTERN_C_ASSIGNMENT_ERROR, + //"You tried to assign a new object to the wrapped void pointer. You have " + //"to delete the old pointee first."}, {StatusCode::ENUM_MAPPING_ERROR, "The role, importance, or datatype you specified does not exist."}, {StatusCode::SPOILED, diff --git a/src/caosdb/transaction.cpp b/src/caosdb/transaction.cpp index 99569d07d89b45da10c4e0f71a68ddbec7f4c130..5ed366ac4285511fc1907b8b1db06628fd35359f 100644 --- a/src/caosdb/transaction.cpp +++ b/src/caosdb/transaction.cpp @@ -28,7 +28,6 @@ #include "caosdb/status_code.h" // for StatusCode #include "caosdb/transaction_handler.h" // for EntityTransactionHandler #include <algorithm> // for max -#include <boost/filesystem/path.hpp> // for operator<<, path #include <boost/log/core/record.hpp> // for record #include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring... #include <boost/log/sources/record_ostream.hpp> // for basic_record_... @@ -36,13 +35,14 @@ #include <boost/preprocessor/seq/limits/size_256.hpp> // for BOOST_PP_SEQ_... // IWYU pragma: no_include <bits/exception.h> #include <exception> // IWYU pragma: keep +#include <filesystem> // for operator<<, path #include <google/protobuf/arena.h> // for Arena #include <grpc/impl/codegen/gpr_types.h> // for gpr_timespec #include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue -#include <iosfwd> // for streamsize #include <map> // for map, operator!= #include <memory> // for unique_ptr -#include <utility> // for move, pair +#include <sstream> +#include <utility> // for move, pair namespace caosdb::transaction { using caosdb::entity::v1::EntityTransactionService; @@ -195,7 +195,7 @@ auto Transaction::ExecuteAsynchronously() noexcept -> StatusCode { // NOLINT case MIXED_READ_AND_WRITE: CAOSDB_LOG_ERROR_AND_RETURN_STATUS( logger_name, StatusCode::UNSUPPORTED_FEATURE, - "MIXED_WRITE UNSUPPORTED: The current implementation does not support " + "MIXED_READ_AND_WRITE UNSUPPORTED: The current implementation does not support " "mixed read and write transactions (containing retrievals, insertions, " "deletions, and updates in one transaction).") default: diff --git a/src/ccaosdb.cpp b/src/ccaosdb.cpp index 77759fce1d216f215dfccd343aa8202b2ec911fa..ae1a728f62b7cdfb293eb347d1a1966b86bfd3b2 100644 --- a/src/ccaosdb.cpp +++ b/src/ccaosdb.cpp @@ -58,11 +58,6 @@ extern "C" { #define ENUM_VALUE_FROM_NAME(arg, etype) \ caosdb::utility::getEnumValueFromName<caosdb::entity::etype>(arg) -#define RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(name) \ - if (name->_deletable) { \ - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; \ - } - /* * Macro for wrapping every function into a try-catch clause. If an exception * occurs, the given StatusCode is being returned. @@ -163,7 +158,6 @@ extern "C" { #define CREATE_VALUE(fname, arg) \ ERROR_RETURN_CODE(GENERIC_ERROR, \ int caosdb_entity_create_##fname(caosdb_entity_value *out, arg), { \ - RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(out) \ out->wrapped_value = new caosdb::entity::Value(value); \ out->_deletable = true; \ return 0; \ @@ -175,9 +169,6 @@ extern "C" { ERROR_RETURN_CODE( \ GENERIC_ERROR, \ int caosdb_entity_create_##fname(caosdb_entity_value *out, arg, const int length), { \ - if (out->_deletable) { \ - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; \ - } \ std::vector<type> value_vec; \ for (int i = 0; i < length; i++) { \ value_vec.push_back(assign); \ @@ -245,9 +236,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_connection_create_pem_file_certificate_provider( caosdb_connection_certificate_provider *out, const char *path), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } out->wrapped_certificate_provider = new caosdb::configuration::PemFileCertificateProvider(std::string(path)); out->_deletable = true; @@ -258,10 +246,11 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_connection_delete_certificate_provider( caosdb_connection_certificate_provider *provider), { - if (provider->_deletable) { + if (provider->_deletable && provider->wrapped_certificate_provider) { delete static_cast<caosdb::configuration::CertificateProvider *>( provider->wrapped_certificate_provider); } + provider->wrapped_certificate_provider = nullptr; provider->_deletable = false; return 0; }) @@ -271,9 +260,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, caosdb_authentication_authenticator *out, const char *username, const char *password), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } out->wrapped_authenticator = new caosdb::authentication::PlainPasswordAuthenticator(std::string(username), std::string(password)); @@ -285,10 +271,11 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_authentication_delete_authenticator( caosdb_authentication_authenticator *authenticator), { - if (authenticator->_deletable) { + if (authenticator->_deletable && authenticator->wrapped_authenticator) { delete static_cast<caosdb::authentication::Authenticator *>( authenticator->wrapped_authenticator); } + authenticator->wrapped_authenticator = nullptr; authenticator->_deletable = false; return 0; }) @@ -300,9 +287,6 @@ ERROR_RETURN_CODE( caosdb_authentication_authenticator *authenticator, caosdb_connection_certificate_provider *provider), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } auto host_str = std::string(host); if (authenticator != nullptr && provider != nullptr) { auto wrapped_provider = static_cast<caosdb::configuration::CertificateProvider *>( @@ -334,9 +318,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, caosdb_connection_connection_configuration *out, const char *host, const int port), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } out->wrapped_connection_configuration = new caosdb::configuration::InsecureConnectionConfiguration(host, port); out->_deletable = true; @@ -347,10 +328,12 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_connection_delete_connection_configuration( caosdb_connection_connection_configuration *configuration), { - if (configuration->_deletable) { + if (configuration->_deletable && + configuration->wrapped_connection_configuration) { delete static_cast<caosdb::configuration::ConnectionConfiguration *>( configuration->wrapped_connection_configuration); } + configuration->wrapped_connection_configuration = nullptr; configuration->_deletable = false; return 0; }) @@ -360,9 +343,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, caosdb_connection_connection *out, const caosdb_connection_connection_configuration *configuration), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } caosdb::configuration::ConnectionConfiguration *config = static_cast<caosdb::configuration::ConnectionConfiguration *>( configuration->wrapped_connection_configuration); @@ -374,10 +354,11 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_connection_delete_connection(caosdb_connection_connection *connection), { - if (connection->_deletable) { + if (connection->_deletable && connection->wrapped_connection) { delete static_cast<caosdb::connection::Connection *>( connection->wrapped_connection); } + connection->wrapped_connection = nullptr; connection->_deletable = false; return 0; }) @@ -417,9 +398,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_connection_connection_manager_get_default_connection( caosdb_connection_connection *out), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } out->wrapped_connection = caosdb::connection::ConnectionManager::GetDefaultConnection().get(); out->_deletable = false; @@ -430,9 +408,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_connection_connection_manager_get_connection( caosdb_connection_connection *out, const char *name), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } out->wrapped_connection = caosdb::connection::ConnectionManager::GetConnection(std::string(name)).get(); // managed by the connection manager now, so not @@ -448,9 +423,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_connection_connection_create_transaction( caosdb_connection_connection *connection, caosdb_transaction_transaction *out), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } auto *wrapped_connection = static_cast<caosdb::connection::Connection *>(connection->wrapped_connection); out->wrapped_transaction = wrapped_connection->CreateTransaction().release(); @@ -461,9 +433,11 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE( GENERIC_ERROR, int caosdb_transaction_delete_transaction(caosdb_transaction_transaction *transaction), { - if (transaction->_deletable) { + if (transaction->_deletable && transaction->wrapped_transaction) { delete static_cast<caosdb::transaction::Transaction *>(transaction->wrapped_transaction); } + transaction->wrapped_transaction = nullptr; + transaction->_deletable = false; return 0; }) @@ -553,9 +527,6 @@ ERROR_RETURN_CODE( int caosdb_transaction_transaction_get_result_set(caosdb_transaction_transaction *transaction, caosdb_transaction_result_set *out), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } auto *wrapped_transaction = static_cast<caosdb::transaction::Transaction *>(transaction->wrapped_transaction); out->wrapped_result_set = (void *)(&(wrapped_transaction->GetResultSet())); @@ -568,9 +539,6 @@ ERROR_RETURN_CODE( int caosdb_transaction_transaction_release_result_set(caosdb_transaction_transaction *transaction, caosdb_transaction_result_set *out), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } auto *wrapped_transaction = static_cast<caosdb::transaction::Transaction *>(transaction->wrapped_transaction); out->wrapped_result_set = (void *)(wrapped_transaction->ReleaseResultSet()); @@ -582,9 +550,10 @@ ERROR_RETURN_CODE( ERROR_RETURN_CODE( GENERIC_ERROR, int caosdb_transaction_delete_result_set(caosdb_transaction_result_set *result_set), { - if (result_set->_deletable) { + if (result_set->_deletable && result_set->wrapped_result_set) { delete static_cast<caosdb::entity::Entity *>(result_set->wrapped_result_set); } + result_set->wrapped_result_set = nullptr; result_set->_deletable = false; return 0; }) @@ -615,9 +584,6 @@ ERROR_RETURN_CODE( int caosdb_transaction_result_set_release_at(caosdb_transaction_result_set *result_set, caosdb_entity_entity *entity, int index), { - if (entity->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } auto *wrapped_result_set = static_cast<caosdb::transaction::MultiResultSet *>(result_set->wrapped_result_set); entity->wrapped_entity = wrapped_result_set->release_at(index); @@ -638,52 +604,46 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_create_entity(caosdb_entity_entity *out), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } out->wrapped_entity = new caosdb::entity::Entity(); out->_deletable = true; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_entity(caosdb_entity_entity *out), { - if (out->_deletable) { + if (out->_deletable && out->wrapped_entity) { delete static_cast<caosdb::entity::Entity *>(out->wrapped_entity); } + out->wrapped_entity = nullptr; out->_deletable = false; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_create_property(caosdb_entity_property *out), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } out->wrapped_property = new caosdb::entity::Property(); out->_deletable = true; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_property(caosdb_entity_property *out), { - if (out->_deletable) { + if (out->_deletable && out->wrapped_property) { delete static_cast<caosdb::entity::Property *>(out->wrapped_property); } + out->wrapped_property = nullptr; out->_deletable = false; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_create_parent(caosdb_entity_parent *out), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } out->wrapped_parent = new caosdb::entity::Parent(); out->_deletable = true; return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_parent(caosdb_entity_parent *out), { - if (out->_deletable) { + if (out->_deletable && out->wrapped_parent) { delete static_cast<caosdb::entity::Parent *>(out->wrapped_parent); } + out->wrapped_parent = nullptr; out->_deletable = false; return 0; }) @@ -692,7 +652,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_create_atomic_datatype(caosdb_entity_datatype *out, const char *name), { - RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(out) try { auto enum_value = ENUM_VALUE_FROM_NAME(std::string(name), AtomicDataType); out->wrapped_datatype = new caosdb::entity::DataType(enum_value); @@ -707,7 +666,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_create_reference_datatype(caosdb_entity_datatype *out, const char *name), { - RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(out) out->wrapped_datatype = new caosdb::entity::DataType(std::string(name)); out->_deletable = true; return 0; @@ -716,7 +674,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_create_atomic_list_datatype(caosdb_entity_datatype *out, const char *name), { - RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(out) try { auto enum_value = ENUM_VALUE_FROM_NAME(std::string(name), AtomicDataType); out->wrapped_datatype = @@ -732,7 +689,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_create_reference_list_datatype(caosdb_entity_datatype *out, const char *name), { - RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(out) out->wrapped_datatype = new caosdb::entity::DataType( caosdb::entity::DataType::ListOf(std::string(name))); out->_deletable = true; @@ -740,9 +696,10 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_datatype(caosdb_entity_datatype *out), { - if (out->_deletable) { + if (out->_deletable && out->wrapped_datatype) { delete WRAPPED_DATATYPE_CAST(out); } + out->wrapped_datatype = nullptr; out->_deletable = false; return 0; }) @@ -757,9 +714,10 @@ CREATE_VECTOR_VALUE(double_vector_value, double, const double *value, value[i]) CREATE_VECTOR_VALUE(bool_vector_value, bool, const bool *value, value[i]) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_value(caosdb_entity_value *out), { - if (out->_deletable) { + if (out->_deletable && out->wrapped_value) { delete WRAPPED_VALUE_CAST(out); } + out->wrapped_value = nullptr; out->_deletable = false; return 0; }) @@ -793,7 +751,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, caosdb_entity_datatype *out), { - RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(out) auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); out->wrapped_datatype = (void *)(&(wrapped_entity->GetDataType())); out->_deletable = false; @@ -803,7 +760,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_get_value(caosdb_entity_entity *entity, caosdb_entity_value *out), { - RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(out) auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); out->wrapped_value = (void *)(&(wrapped_entity->GetValue())); out->_deletable = false; @@ -826,9 +782,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_get_error(caosdb_entity_entity *entity, caosdb_entity_message *out, int index), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); out->wrapped_message = wrapped_entity->GetErrors().mutable_at(index); @@ -850,9 +803,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_get_warning(caosdb_entity_entity *entity, caosdb_entity_message *out, int index), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); out->wrapped_message = wrapped_entity->GetWarnings().mutable_at(index); @@ -872,9 +822,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_get_info(caosdb_entity_entity *entity, caosdb_entity_message *out, int index), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); out->wrapped_message = wrapped_entity->GetInfos().mutable_at(index); @@ -896,9 +843,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_get_property(caosdb_entity_entity *entity, caosdb_entity_property *out, int index), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); out->wrapped_property = wrapped_entity->GetProperties().mutable_at(index); @@ -919,9 +863,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_get_parent(caosdb_entity_entity *entity, caosdb_entity_parent *out, int index), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); out->wrapped_parent = wrapped_entity->GetParents().mutable_at(index); @@ -954,7 +895,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_property_get_datatype(caosdb_entity_property *property, caosdb_entity_datatype *out), { - RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(out) auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); out->wrapped_datatype = (void *)(&(wrapped_property->GetDataType())); out->_deletable = false; @@ -964,7 +904,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_property_get_value(caosdb_entity_property *property, caosdb_entity_value *out), { - RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(out) auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); out->wrapped_value = (void *)(&(wrapped_property->GetValue())); out->_deletable = false; @@ -1092,9 +1031,6 @@ ERROR_RETURN_CODE(GENERIC_ERROR, caosdb_entity_value *out, const int index), { - if (out->_deletable) { - return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; - } auto *wrapped_value = WRAPPED_VALUE_CAST(value); out->wrapped_value = (void *)(&(wrapped_value->GetAsVector().at(index))); out->_deletable = false; @@ -1115,7 +1051,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) CAOSDB_ENTITY_SET(name, name, wrapped_entity->SetName(std::string(name));) CAOSDB_ENTITY_SET(local_path, local_path, - return wrapped_entity->SetLocalPath(boost::filesystem::path(local_path));) + return wrapped_entity->SetLocalPath(std::filesystem::path(local_path));) CAOSDB_ENTITY_SET(file_path, file_path, wrapped_entity->SetFilePath(std::string(file_path));) CAOSDB_ENTITY_SET(description, description, wrapped_entity->SetDescription(std::string(description));) diff --git a/src/cxxcaosdbcli.cpp b/src/cxxcaosdbcli.cpp index bb60696e8a0f3b10d2b29e54cac034b89907f9c3..e6e5cee66e6c90ab7719434d7667cd6ad20ccbb8 100644 --- a/src/cxxcaosdbcli.cpp +++ b/src/cxxcaosdbcli.cpp @@ -21,16 +21,23 @@ */ // A simple caosdb client -#include "caosdb/connection.h" // for Connection, ConnectionManager -#include "caosdb/constants.h" // for LIBCAOSDB_VERSION_MINOR, LIBCAOSDB_V... -#include "caosdb/entity.h" // for Entity -#include "caosdb/exceptions.h" // for ConfigurationError -#include "caosdb/info.h" // for VersionInfo -#include "caosdb/logging.h" // for CAOSDB_LOG_TRACE -#include "caosdb/transaction.h" // for Transaction, ResultSet -#include <iostream> // for operator<<, basic_ostream, basic_ost... -#include <memory> // for unique_ptr, allocator, __shared_ptr_... -#include <string> // for operator<<, char_traits +#include "caosdb/connection.h" // for Connection, ConnectionManager +#include "caosdb/constants.h" // for LIBCAOSDB_VERSION_MINOR, LIBCAOSDB_V... +#include "caosdb/entity.h" // for Entity +#include "caosdb/exceptions.h" // for ConfigurationError +#include "caosdb/info.h" // for VersionInfo +#include "caosdb/logging.h" // for CAOSDB_LOG_TRACE +#include "caosdb/transaction.h" // for Transaction, ResultSet +#include "caosdb/transaction_status.h" // for TransactionSt... +#include <boost/log/core/record.hpp> // for record +#include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring... +#include <boost/log/sources/record_ostream.hpp> // for operator<< +#include <boost/preprocessor/seq/limits/enum_256.hpp> // for BOOST_PP_SEQ_... +#include <boost/preprocessor/seq/limits/size_256.hpp> // for BOOST_PP_SEQ_... +#include <exception> // for exception +#include <iostream> // for operator<<, basic_ostream, basic_ost... +#include <memory> // for unique_ptr, allocator, __shared_ptr_... +#include <string> // for operator<<, char_traits const auto logger_name = "libcaosdb"; @@ -53,24 +60,14 @@ auto main() -> int { // retrieve an entity auto transaction(connection->CreateTransaction()); - transaction->RetrieveById("120"); + transaction->RetrieveById("21"); transaction->ExecuteAsynchronously(); auto t_stat = transaction->WaitForIt(); CAOSDB_LOG_INFO(logger_name) << "status: " << t_stat.GetCode() << " // " << t_stat.GetDescription(); const auto &result_set = transaction->GetResultSet(); - if (result_set.size() > 0) { - // print information - const auto &ent = result_set.at(0); - const auto &props = ent.GetProperties(); - std::cout << "Entity Name: " << ent.GetName() << std::endl; - std::cout << "Entity Description: " << ent.GetDescription() << std::endl; - std::cout << "Entity Properties: " << std::endl; - for (const auto &prop : props) { - std::cout << "----------\n" << prop.ToString() << std::endl; - } - } else { - std::cout << "No entity \"120\" retrieved, maybe it does not exist?\n" << std::endl; + for (const auto &entity : result_set) { + std::cout << entity.ToString() << std::endl; } // execute a query @@ -82,6 +79,11 @@ auto main() -> int { t_stat = q_transaction->WaitForIt(); CAOSDB_LOG_INFO(logger_name) << "status: " << t_stat.GetCode() << " // " << t_stat.GetDescription(); + const auto &result_set_2 = q_transaction->GetResultSet(); + for (const auto &entity : result_set_2) { + std::cout << entity.ToString() << std::endl; + } + return 0; } catch (const caosdb::exceptions::ConfigurationError &exc) { std::cout << "ConfigurationError: " << exc.what() << std::endl; diff --git a/test/test_ccaosdb.cpp b/test/test_ccaosdb.cpp index 1059f161525d513389efd4df95cdd04ec5a088db..71c2a829316b5b5418702686c6ea0fdfa48e5198 100644 --- a/test/test_ccaosdb.cpp +++ b/test/test_ccaosdb.cpp @@ -386,8 +386,8 @@ TEST_F(test_ccaosdb, test_entity) { EXPECT_EQ(return_code, 0); // cannot be created again without deletion - return_code = caosdb_entity_create_entity(&entity); - EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); + // return_code = caosdb_entity_create_entity(&entity); + // EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); // deletion and re-creation is ok return_code = caosdb_entity_delete_entity(&entity); @@ -431,8 +431,8 @@ TEST_F(test_ccaosdb, test_entity) { caosdb_entity_entity_set_datatype(&entity, &in_type); // verify that this doesn't work ... - return_code = caosdb_entity_entity_get_datatype(&entity, &in_type); - EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); + // return_code = caosdb_entity_entity_get_datatype(&entity, &in_type); + // EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); caosdb_entity_datatype out_type; // ... but does with a clean property return_code = caosdb_entity_entity_get_datatype(&entity, &out_type); @@ -827,8 +827,8 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) { char *out = nullptr; // NOLINT // cannot assign an already assigned property - return_code = caosdb_entity_entity_get_property(&entity, &input_property, 0); - EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); + // return_code = caosdb_entity_entity_get_property(&entity, &input_property, 0); + // EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); caosdb_entity_property output_property; return_code = caosdb_entity_entity_get_property(&entity, &output_property, 0); EXPECT_EQ(return_code, 0); diff --git a/test/test_file_transmission.cpp b/test/test_file_transmission.cpp index 7c5eb745e8f451b0282fa844510dc71ad402ed18..c5847a0842ae8a3bb46a8126e42b31bb5b1d6451 100644 --- a/test/test_file_transmission.cpp +++ b/test/test_file_transmission.cpp @@ -19,15 +19,14 @@ */ #include "caosdb/file_transmission/file_writer.h" #include "caosdb/file_transmission/file_reader.h" -#include <boost/filesystem/operations.hpp> // for exists, file_size, remove -#include <boost/filesystem/path.hpp> // for path -#include <boost/filesystem/path_traits.hpp> // for filesystem -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver -#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, AssertionResult -#include <string> // for string - -namespace fs = boost::filesystem; +#include <chrono> // for filesystem +#include <filesystem> // for path +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver +#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, AssertionResult +#include <string> // for string + +namespace fs = std::filesystem; namespace caosdb::transaction { diff --git a/test/test_transaction.cpp b/test/test_transaction.cpp index ac0934f10563f0fdb2c5145fe88ab6c2fdb0c5ca..a95b481deae1bc7a2caedf952193a182ee3807c9 100644 --- a/test/test_transaction.cpp +++ b/test/test_transaction.cpp @@ -22,11 +22,12 @@ #include "caosdb/entity.h" // for Entity #include "caosdb/entity/v1/main.pb.h" // for Entity #include "caosdb/exceptions.h" // for ConnectionError -#include "caosdb/status_code.h" +#include "caosdb/status_code.h" // for StatusCode #include "caosdb/transaction.h" // for Transaction #include "caosdb/transaction_handler.h" // for MultiTransactionResponse #include "caosdb/transaction_status.h" // for ConnectionError #include "caosdb_test_utility.h" // for EXPECT_THROW_MESSAGE +#include <algorithm> // for max #include <google/protobuf/arena.h> // for Arena #include <gtest/gtest-message.h> // for Message #include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPa...