Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Commit

Permalink
Добавил семантику перемещения для JSONValue
Browse files Browse the repository at this point in the history
  • Loading branch information
orefkov committed Dec 7, 2022
1 parent 5d6703b commit 07ac2f9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Source/Urho3D/Resource/JSONValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,17 @@ VariantVector JSONValue::GetVariantVector() const
return variantVector;
}

void JSONValue::Swap(JSONValue& other)
{
unsigned t = type_;
type_ = other.type_;
other.type_ = t;

double n = numberValue_;
numberValue_ = other.numberValue_;
other.numberValue_ = n;
}

String JSONValue::GetValueTypeName(JSONValueType type)
{
return valueTypeNames[type];
Expand Down
12 changes: 12 additions & 0 deletions Source/Urho3D/Resource/JSONValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ class URHO3D_API JSONValue
{
*this = value;
}
/// Move-construct from another JSON value.
/// @nobind
JSONValue(JSONValue&& value)
: type_(0)
{
Swap(value);
}
/// Destruct.
~JSONValue()
{
Expand All @@ -158,6 +165,9 @@ class URHO3D_API JSONValue
JSONValue& operator =(const JSONObject& rhs);
/// Assign from another JSON value.
JSONValue& operator =(const JSONValue& rhs);
/// Move from another JSON value.
/// @nobind
JSONValue& operator=(JSONValue&& rhs) { Swap(rhs); return *this; }

/// Return value type.
/// @property
Expand Down Expand Up @@ -273,6 +283,8 @@ class URHO3D_API JSONValue
void SetVariantVector(const VariantVector& variantVector, Context* context = nullptr);
/// Return a variant vector.
VariantVector GetVariantVector() const;
/// Swap content of two values
void Swap(JSONValue& other);

/// Empty JSON value.
static const JSONValue EMPTY;
Expand Down

0 comments on commit 07ac2f9

Please sign in to comment.