diff --git a/CMakeLists.txt b/CMakeLists.txt index 09d03a7a78fc5b9bd3b49f242a32d97debccfe3a..6ead99620d8075d6f722602439e46059dceab557 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -323,7 +323,7 @@ if(_LINTING) else() message(STATUS "clang-tidy: ${clang_tidy}") set(_CMAKE_CXX_CLANG_TIDY_CHECKS - "--checks=*,-fuchsia-*,-llvmlibc-*,-readability-convert-member-functions-to-static,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-hicpp-no-array-decay,-llvm-else-after-return,-readability-else-after-return,-modernize-use-trailing-return-type,-bugprone-branch-clone,-altera-*,-cppcoreguidelines-macro-usage,-*-avoid-c-arrays") + "--checks=*,-fuchsia-*,-llvmlibc-*,-readability-convert-member-functions-to-static,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-hicpp-no-array-decay,-llvm-else-after-return,-readability-else-after-return,-modernize-use-trailing-return-type,-bugprone-branch-clone,-altera-*,-cppcoreguidelines-macro-usage") set(_CMAKE_C_CLANG_TIDY_CHECKS "${_CMAKE_CXX_CLANG_TIDY_CHECKS}") set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}" "--header-filter=caosdb/.*[^\(\.pb\.h\)]$" diff --git a/include/caosdb/utility.h b/include/caosdb/utility.h index 1a6bcf2e6c164ab9a42a701aa7e9ba5a2769d1fc..13e3dfeb99dc5415a733d5b6dcea852705b1662d 100644 --- a/include/caosdb/utility.h +++ b/include/caosdb/utility.h @@ -147,11 +147,6 @@ public: */ auto operator=(JsonValue &&other) noexcept -> JsonValue &; - /** - * Return true if the `wrapped` object is the nullptr. - */ - inline auto IsNull() const -> bool { return this->wrapped == nullptr; } - /** * Reset this object. * diff --git a/src/caosdb/configuration.cpp b/src/caosdb/configuration.cpp index 410351f6f7b26ce8d3fb910998cc48b792b9a080..a8dd6509c09aaaedc54d5693b3e21e9fb226dd1c 100644 --- a/src/caosdb/configuration.cpp +++ b/src/caosdb/configuration.cpp @@ -45,10 +45,11 @@ #include <string> // for string, operator+ #include <utility> // for move -#define WRAPPED_JSON_CONFIGURATION(obj) (static_cast<value *>((obj)->json_configuration.wrapped.get())) +#define WRAPPED_JSON_CONFIGURATION(obj) \ + (static_cast<value *>((obj)->json_configuration.wrapped.get())) #define GET_CONNECTIONS \ - if (this->json_configuration.IsNull()) { \ + if (!this->json_configuration.wrapped) { \ throw ConfigurationError("This CaosDB client has not been configured."); \ } \ assert(WRAPPED_JSON_CONFIGURATION(this)->is_object()); \ @@ -379,7 +380,7 @@ auto ConfigurationManager::mClear() noexcept -> int { } auto ConfigurationManager::mLoadSingleJSONConfiguration(const path &json_file) -> void { - if (!json_configuration.IsNull()) { + if (json_configuration.wrapped) { throw ConfigurationError("This CaosDB client has already been configured."); } if (!exists(json_file)) { @@ -468,7 +469,7 @@ auto ConfigurationManager::InitializeDefaults() -> int { // NOLINT } // Logging in the configuration leads to additional content. - if (!this->json_configuration.IsNull() && WRAPPED_JSON_CONFIGURATION(this)->is_object() && + if (this->json_configuration.wrapped && WRAPPED_JSON_CONFIGURATION(this)->is_object() && WRAPPED_JSON_CONFIGURATION(this)->as_object().contains("logging")) { LoggingConfiguration logging_configuration = CreateLoggingConfiguration(WRAPPED_JSON_CONFIGURATION(this)->at("logging").as_object()); @@ -479,7 +480,7 @@ auto ConfigurationManager::InitializeDefaults() -> int { // NOLINT "We are using the default configuration"; } - if (configuration_file_path != nullptr && !this->json_configuration.IsNull() && + if (configuration_file_path != nullptr && this->json_configuration.wrapped && WRAPPED_JSON_CONFIGURATION(this)->is_object()) { CAOSDB_LOG_INFO(logger_name) << "Loaded configuration from " << *(configuration_file_path) << "."; diff --git a/src/caosdb/utility.cpp b/src/caosdb/utility.cpp index 9b5b5ec056193dbe3a1cdd77451b4b645f503073..ca7e1cbe9102763ed54763f7ca1dd271ed0b06db 100644 --- a/src/caosdb/utility.cpp +++ b/src/caosdb/utility.cpp @@ -114,11 +114,10 @@ auto base64_encode(const std::string &plain) -> std::string { auto size_plain = plain.size(); auto size_encoded = boost::beast::detail::base64::encoded_size(size_plain); - std::unique_ptr<char[]> encoded(new char[size_encoded]); - boost::beast::detail::base64::encode(encoded.get(), plain.c_str(), size_plain); + std::string result = std::string(size_encoded, '\0'); + boost::beast::detail::base64::encode(&result[0], plain.c_str(), size_plain); - // the encoded char[] is not null terminated, so explicitely set the length - return {encoded.get(), encoded.get() + size_encoded}; + return result; } auto _load_json_file(const path &json_file) -> value { @@ -144,38 +143,40 @@ auto load_json_file(const path &json_file) -> JsonValue { return {new value(_load_json_file(json_file))}; } -JsonValue::JsonValue(void *wrapped) { - this->wrapped = std::make_shared<value>(*static_cast<value *>(wrapped)); -} +JsonValue::JsonValue(void *wrapped) { this->wrapped.reset(static_cast<value *>(wrapped)); } -JsonValue::~JsonValue() { this->Reset(); } +JsonValue::~JsonValue() = default; -auto JsonValue::Reset() -> void { this->wrapped .reset(); } +auto JsonValue::Reset() -> void { + if (this->wrapped) { + this->wrapped.reset(); + } +} JsonValue::JsonValue(const JsonValue &other) { - if (!other.IsNull()) { - this->wrapped = std::make_shared<value>(*static_cast<value *>(other.wrapped.get())); + if (other.wrapped) { + this->wrapped.reset(static_cast<value *>(other.wrapped.get())); } } auto JsonValue::operator=(const JsonValue &other) -> JsonValue & { if (this != &other) { - Reset(); - if (!other.IsNull()) { - this->wrapped = std::make_shared<value>(*static_cast<value *>(other.wrapped.get())); + if (other.wrapped) { + this->wrapped = std::make_shared<value>(*(static_cast<value *>(other.wrapped.get()))); } } return *this; } -JsonValue::JsonValue(JsonValue &&other) noexcept : wrapped(nullptr) { - if (!other.IsNull()) { +JsonValue::JsonValue(JsonValue &&other) noexcept { + if (other.wrapped) { this->wrapped = std::move(other.wrapped); } } auto JsonValue::operator=(JsonValue &&other) noexcept -> JsonValue & { if (this != &other) { + Reset(); this->wrapped = std::move(other.wrapped); } return *this;