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

MAINT: use smart pointer instead of raw

parent a4b928a3
No related branches found
No related tags found
2 merge requests!42Release 0.2.0,!39F remove boost rdep
Pipeline #24620 failed
......@@ -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,-cppcoreguidelines-owning-memory")
"--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")
set(_CMAKE_C_CLANG_TIDY_CHECKS "${_CMAKE_CXX_CLANG_TIDY_CHECKS}")
set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}"
"--header-filter=caosdb/.*[^\(\.pb\.h\)]$"
......
......@@ -26,6 +26,7 @@
#include <cstdlib> // for getenv
#include <filesystem> // for path
#include <fstream> // for basic_istream<>::__ist...
#include <memory> // for shared_ptr
#include <string> // for string, operator+, cha...
namespace caosdb::utility {
......@@ -110,7 +111,7 @@ public:
* By calling this constructor the ownership of the `wrapped` parameter is
* transferred to this object.
*/
JsonValue(void *wrapped) : wrapped(wrapped) {}
JsonValue(void *wrapped);
/**
* Destructor.
*
......@@ -162,7 +163,7 @@ public:
* An object which represents a JSON value. The object's class is an
* implementation detail.
*/
void *wrapped;
std::shared_ptr<void> wrapped;
};
/**
......
......@@ -45,7 +45,7 @@
#include <string> // for string, operator+
#include <utility> // for move
#define WRAPPED_JSON_CONFIGURATION(obj) (static_cast<value *>((obj)->json_configuration.wrapped))
#define WRAPPED_JSON_CONFIGURATION(obj) (static_cast<value *>((obj)->json_configuration.wrapped.get()))
#define GET_CONNECTIONS \
if (this->json_configuration.IsNull()) { \
......
......@@ -144,19 +144,17 @@ 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() { this->Reset(); }
auto JsonValue::Reset() -> void {
void *tmp = this->wrapped;
this->wrapped = nullptr;
if (tmp != nullptr) {
delete static_cast<value *>(tmp);
}
}
auto JsonValue::Reset() -> void { this->wrapped .reset(); }
JsonValue::JsonValue(const JsonValue &other) : wrapped(nullptr) {
JsonValue::JsonValue(const JsonValue &other) {
if (!other.IsNull()) {
this->wrapped = new value(*static_cast<value *>(other.wrapped));
this->wrapped = std::make_shared<value>(*static_cast<value *>(other.wrapped.get()));
}
}
......@@ -164,7 +162,7 @@ auto JsonValue::operator=(const JsonValue &other) -> JsonValue & {
if (this != &other) {
Reset();
if (!other.IsNull()) {
this->wrapped = new value(*static_cast<value *>(other.wrapped));
this->wrapped = std::make_shared<value>(*static_cast<value *>(other.wrapped.get()));
}
}
return *this;
......@@ -172,15 +170,13 @@ auto JsonValue::operator=(const JsonValue &other) -> JsonValue & {
JsonValue::JsonValue(JsonValue &&other) noexcept : wrapped(nullptr) {
if (!other.IsNull()) {
this->wrapped = other.wrapped;
other.wrapped = nullptr;
this->wrapped = std::move(other.wrapped);
}
}
auto JsonValue::operator=(JsonValue &&other) noexcept -> JsonValue & {
if (this != &other) {
this->wrapped = other.wrapped;
other.wrapped = nullptr;
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