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) ...@@ -323,7 +323,7 @@ if(_LINTING)
    else() else()
    message(STATUS "clang-tidy: ${clang_tidy}") message(STATUS "clang-tidy: ${clang_tidy}")
    set(_CMAKE_CXX_CLANG_TIDY_CHECKS 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_C_CLANG_TIDY_CHECKS "${_CMAKE_CXX_CLANG_TIDY_CHECKS}")
    set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}" set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}"
    "--header-filter=caosdb/.*[^\(\.pb\.h\)]$" "--header-filter=caosdb/.*[^\(\.pb\.h\)]$"
    ......
    ...@@ -147,11 +147,6 @@ public: ...@@ -147,11 +147,6 @@ public:
    */ */
    auto operator=(JsonValue &&other) noexcept -> JsonValue &; 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. * Reset this object.
    * *
    ......
    ...@@ -45,10 +45,11 @@ ...@@ -45,10 +45,11 @@
    #include <string> // for string, operator+ #include <string> // for string, operator+
    #include <utility> // for move #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 \ #define GET_CONNECTIONS \
    if (this->json_configuration.IsNull()) { \ if (!this->json_configuration.wrapped) { \
    throw ConfigurationError("This CaosDB client has not been configured."); \ throw ConfigurationError("This CaosDB client has not been configured."); \
    } \ } \
    assert(WRAPPED_JSON_CONFIGURATION(this)->is_object()); \ assert(WRAPPED_JSON_CONFIGURATION(this)->is_object()); \
    ...@@ -379,7 +380,7 @@ auto ConfigurationManager::mClear() noexcept -> int { ...@@ -379,7 +380,7 @@ auto ConfigurationManager::mClear() noexcept -> int {
    } }
    auto ConfigurationManager::mLoadSingleJSONConfiguration(const path &json_file) -> void { 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."); throw ConfigurationError("This CaosDB client has already been configured.");
    } }
    if (!exists(json_file)) { if (!exists(json_file)) {
    ...@@ -468,7 +469,7 @@ auto ConfigurationManager::InitializeDefaults() -> int { // NOLINT ...@@ -468,7 +469,7 @@ auto ConfigurationManager::InitializeDefaults() -> int { // NOLINT
    } }
    // Logging in the configuration leads to additional content. // 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")) { WRAPPED_JSON_CONFIGURATION(this)->as_object().contains("logging")) {
    LoggingConfiguration logging_configuration = LoggingConfiguration logging_configuration =
    CreateLoggingConfiguration(WRAPPED_JSON_CONFIGURATION(this)->at("logging").as_object()); CreateLoggingConfiguration(WRAPPED_JSON_CONFIGURATION(this)->at("logging").as_object());
    ...@@ -479,7 +480,7 @@ auto ConfigurationManager::InitializeDefaults() -> int { // NOLINT ...@@ -479,7 +480,7 @@ auto ConfigurationManager::InitializeDefaults() -> int { // NOLINT
    "We are using the default configuration"; "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()) { WRAPPED_JSON_CONFIGURATION(this)->is_object()) {
    CAOSDB_LOG_INFO(logger_name) << "Loaded configuration from " << *(configuration_file_path) CAOSDB_LOG_INFO(logger_name) << "Loaded configuration from " << *(configuration_file_path)
    << "."; << ".";
    ......
    ...@@ -114,11 +114,10 @@ auto base64_encode(const std::string &plain) -> std::string { ...@@ -114,11 +114,10 @@ auto base64_encode(const std::string &plain) -> std::string {
    auto size_plain = plain.size(); auto size_plain = plain.size();
    auto size_encoded = boost::beast::detail::base64::encoded_size(size_plain); auto size_encoded = boost::beast::detail::base64::encoded_size(size_plain);
    std::unique_ptr<char[]> encoded(new char[size_encoded]); std::string result = std::string(size_encoded, '\0');
    boost::beast::detail::base64::encode(encoded.get(), plain.c_str(), size_plain); 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 result;
    return {encoded.get(), encoded.get() + size_encoded};
    } }
    auto _load_json_file(const path &json_file) -> value { auto _load_json_file(const path &json_file) -> value {
    ...@@ -144,38 +143,40 @@ auto load_json_file(const path &json_file) -> JsonValue { ...@@ -144,38 +143,40 @@ auto load_json_file(const path &json_file) -> JsonValue {
    return {new value(_load_json_file(json_file))}; return {new value(_load_json_file(json_file))};
    } }
    JsonValue::JsonValue(void *wrapped) { JsonValue::JsonValue(void *wrapped) { this->wrapped.reset(static_cast<value *>(wrapped)); }
    this->wrapped = std::make_shared<value>(*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) { JsonValue::JsonValue(const JsonValue &other) {
    if (!other.IsNull()) { if (other.wrapped) {
    this->wrapped = std::make_shared<value>(*static_cast<value *>(other.wrapped.get())); this->wrapped.reset(static_cast<value *>(other.wrapped.get()));
    } }
    } }
    auto JsonValue::operator=(const JsonValue &other) -> JsonValue & { auto JsonValue::operator=(const JsonValue &other) -> JsonValue & {
    if (this != &other) { if (this != &other) {
    Reset(); if (other.wrapped) {
    if (!other.IsNull()) { this->wrapped = std::make_shared<value>(*(static_cast<value *>(other.wrapped.get())));
    this->wrapped = std::make_shared<value>(*static_cast<value *>(other.wrapped.get()));
    } }
    } }
    return *this; return *this;
    } }
    JsonValue::JsonValue(JsonValue &&other) noexcept : wrapped(nullptr) { JsonValue::JsonValue(JsonValue &&other) noexcept {
    if (!other.IsNull()) { if (other.wrapped) {
    this->wrapped = std::move(other.wrapped); this->wrapped = std::move(other.wrapped);
    } }
    } }
    auto JsonValue::operator=(JsonValue &&other) noexcept -> JsonValue & { auto JsonValue::operator=(JsonValue &&other) noexcept -> JsonValue & {
    if (this != &other) { if (this != &other) {
    Reset();
    this->wrapped = std::move(other.wrapped); this->wrapped = std::move(other.wrapped);
    } }
    return *this; return *this;
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment