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
......@@ -137,14 +137,14 @@ public:
*
* Also moves the `wrapped` object.
*/
JsonValue(JsonValue &&other) = default;
JsonValue(JsonValue &&other);
/**
* Move Assigment.
*
* 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.
......
......@@ -147,10 +147,11 @@ auto load_json_file(const path &json_file) -> JsonValue {
JsonValue::~JsonValue() { this->Reset(); }
auto JsonValue::Reset() -> void {
if (!IsNull()) {
delete static_cast<value *>(this->wrapped);
}
void * tmp = std::move(this->wrapped);
this->wrapped = nullptr;
if (tmp != nullptr) {
delete static_cast<value *>(tmp);
}
}
JsonValue::JsonValue(const JsonValue &other) : wrapped(nullptr) {
......@@ -169,4 +170,21 @@ auto JsonValue::operator=(const JsonValue &other) -> JsonValue & {
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment