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
Branches
Tags
2 merge requests!42Release 0.2.0,!39F remove boost rdep
Pipeline #24620 failed
This commit is part of merge request !42. Comments created here will be created in the context of that merge request.
...@@ -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,-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_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\)]$"
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <cstdlib> // for getenv #include <cstdlib> // for getenv
#include <filesystem> // for path #include <filesystem> // for path
#include <fstream> // for basic_istream<>::__ist... #include <fstream> // for basic_istream<>::__ist...
#include <memory> // for shared_ptr
#include <string> // for string, operator+, cha... #include <string> // for string, operator+, cha...
namespace caosdb::utility { namespace caosdb::utility {
...@@ -110,7 +111,7 @@ public: ...@@ -110,7 +111,7 @@ public:
* By calling this constructor the ownership of the `wrapped` parameter is * By calling this constructor the ownership of the `wrapped` parameter is
* transferred to this object. * transferred to this object.
*/ */
JsonValue(void *wrapped) : wrapped(wrapped) {} JsonValue(void *wrapped);
/** /**
* Destructor. * Destructor.
* *
...@@ -162,7 +163,7 @@ public: ...@@ -162,7 +163,7 @@ public:
* An object which represents a JSON value. The object's class is an * An object which represents a JSON value. The object's class is an
* implementation detail. * implementation detail.
*/ */
void *wrapped; std::shared_ptr<void> wrapped;
}; };
/** /**
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
#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)) #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.IsNull()) { \
......
...@@ -144,19 +144,17 @@ auto load_json_file(const path &json_file) -> JsonValue { ...@@ -144,19 +144,17 @@ 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) {
this->wrapped = std::make_shared<value>(*static_cast<value *>(wrapped));
}
JsonValue::~JsonValue() { this->Reset(); } JsonValue::~JsonValue() { this->Reset(); }
auto JsonValue::Reset() -> void { auto JsonValue::Reset() -> void { this->wrapped .reset(); }
void *tmp = this->wrapped;
this->wrapped = nullptr;
if (tmp != nullptr) {
delete static_cast<value *>(tmp);
}
}
JsonValue::JsonValue(const JsonValue &other) : wrapped(nullptr) { JsonValue::JsonValue(const JsonValue &other) {
if (!other.IsNull()) { 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 & { ...@@ -164,7 +162,7 @@ auto JsonValue::operator=(const JsonValue &other) -> JsonValue & {
if (this != &other) { if (this != &other) {
Reset(); Reset();
if (!other.IsNull()) { 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; return *this;
...@@ -172,15 +170,13 @@ auto JsonValue::operator=(const JsonValue &other) -> JsonValue & { ...@@ -172,15 +170,13 @@ auto JsonValue::operator=(const JsonValue &other) -> JsonValue & {
JsonValue::JsonValue(JsonValue &&other) noexcept : wrapped(nullptr) { JsonValue::JsonValue(JsonValue &&other) noexcept : wrapped(nullptr) {
if (!other.IsNull()) { if (!other.IsNull()) {
this->wrapped = other.wrapped; this->wrapped = std::move(other.wrapped);
other.wrapped = nullptr;
} }
} }
auto JsonValue::operator=(JsonValue &&other) noexcept -> JsonValue & { auto JsonValue::operator=(JsonValue &&other) noexcept -> JsonValue & {
if (this != &other) { if (this != &other) {
this->wrapped = other.wrapped; this->wrapped = std::move(other.wrapped);
other.wrapped = nullptr;
} }
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