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

Implement move for JsonValue

parent 51c5b069
Branches
Tags
2 merge requests!42Release 0.2.0,!39F remove boost rdep
This commit is part of merge request !39. Comments created here will be created in the context of that merge request.
...@@ -137,14 +137,14 @@ public: ...@@ -137,14 +137,14 @@ public:
* *
* Also moves the `wrapped` object. * Also moves the `wrapped` object.
*/ */
JsonValue(JsonValue &&other) = default; JsonValue(JsonValue &&other);
/** /**
* Move Assigment. * Move Assigment.
* *
* Also moves the `wrapped` object. * Also moves the `wrapped` object.
*/ */
auto operator=(JsonValue &&other) -> JsonValue & = default; auto operator=(JsonValue &&other) -> JsonValue &;
/** /**
* Return true if the `wrapped` object is the nullptr. * Return true if the `wrapped` object is the nullptr.
......
...@@ -147,10 +147,11 @@ auto load_json_file(const path &json_file) -> JsonValue { ...@@ -147,10 +147,11 @@ auto load_json_file(const path &json_file) -> JsonValue {
JsonValue::~JsonValue() { this->Reset(); } JsonValue::~JsonValue() { this->Reset(); }
auto JsonValue::Reset() -> void { auto JsonValue::Reset() -> void {
if (!IsNull()) { void * tmp = std::move(this->wrapped);
delete static_cast<value *>(this->wrapped);
}
this->wrapped = nullptr; this->wrapped = nullptr;
if (tmp != nullptr) {
delete static_cast<value *>(tmp);
}
} }
JsonValue::JsonValue(const JsonValue &other) : wrapped(nullptr) { JsonValue::JsonValue(const JsonValue &other) : wrapped(nullptr) {
...@@ -169,4 +170,21 @@ auto JsonValue::operator=(const JsonValue &other) -> JsonValue & { ...@@ -169,4 +170,21 @@ auto JsonValue::operator=(const JsonValue &other) -> JsonValue & {
return *this; return *this;
} }
JsonValue::JsonValue(JsonValue &&other) : wrapped(nullptr) {
std::cout << "MoveConstructor" << std::endl;
if (!other.IsNull()) {
this->wrapped = other.wrapped;
other.wrapped = nullptr;
}
}
auto JsonValue::operator=(JsonValue &&other) -> JsonValue & {
std::cout << "MoveAssignment" << std::endl;
if (this != &other) {
this->wrapped = other.wrapped;
other.wrapped = nullptr;
}
return *this;
}
} // namespace caosdb::utility } // namespace caosdb::utility
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment