Skip to content
Snippets Groups Projects
Verified Commit 26b3d9e5 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

MAINT: replace char[] with string

parent ec5732e2
Branches
Tags
2 merge requests!42Release 0.2.0,!39F remove boost rdep
Pipeline #24629 passed
Pipeline: caosdb-cppinttest

#24630

    ......@@ -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\)]$"
    ......
    ......@@ -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.
    *
    ......
    ......@@ -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)
    << ".";
    ......
    ......@@ -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;
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment