Skip to content

Commit 30d4cf0

Browse files
author
Christopher Dawes
committed
All tests fixed, issue with missing swap of string value
1 parent ecf832b commit 30d4cf0

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

include/json/value.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ class JSON_API Value {
219219
class StringValueHolder {
220220
public:
221221
StringValueHolder();
222+
StringValueHolder(const StringValueHolder& other);
223+
StringValueHolder(StringValueHolder&& other);
222224
StringValueHolder(StringDataPtr&& value);
223225
StringValueHolder(char* value);
224226
~StringValueHolder();
@@ -228,6 +230,11 @@ class JSON_API Value {
228230
void SetString(char* value);
229231
bool IsRaw() const;
230232

233+
StringValueHolder& operator=(const StringValueHolder& other);
234+
StringValueHolder& operator=(StringValueHolder&& other);
235+
void copy(const StringValueHolder& other);
236+
void swap(StringValueHolder&& other);
237+
231238
private:
232239
char* valueStringRaw_ = nullptr; // the value that was passed in, this does not belong to value
233240
StringDataPtr valueStringCopy_; // a copy of the value that was passed in

include/json/value.inl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ void Value<_Alloc, _String>::swapPayload(Value<_Alloc, _String>& other) {
511511
int temp2 = allocated_;
512512
allocated_ = other.allocated_;
513513
other.allocated_ = temp2 & 0x1;
514+
std::swap(stringValue_, other.stringValue_);
514515
}
515516

516517
template<class _Alloc, class _String>
@@ -1525,6 +1526,16 @@ Value<_Alloc, _String>::StringValueHolder::StringValueHolder() {
15251526
/* Not used */
15261527
}
15271528

1529+
template<class _Alloc, class _String>
1530+
Value<_Alloc, _String>::StringValueHolder::StringValueHolder(const StringValueHolder& other) {
1531+
copy(other);
1532+
}
1533+
1534+
template<class _Alloc, class _String>
1535+
Value<_Alloc, _String>::StringValueHolder::StringValueHolder(StringValueHolder&& other) {
1536+
swap(std::move(other));
1537+
}
1538+
15281539
template<class _Alloc, class _String>
15291540
Value<_Alloc, _String>::StringValueHolder::StringValueHolder(StringDataPtr&& value) {
15301541
SetString(std::move(value));
@@ -1579,6 +1590,33 @@ bool Value<_Alloc, _String>::StringValueHolder::IsRaw() const {
15791590
return raw_;
15801591
}
15811592

1593+
template<class _Alloc, class _String>
1594+
typename Value<_Alloc, _String>::StringValueHolder& Value<_Alloc, _String>::StringValueHolder::operator=(const StringValueHolder& other) {
1595+
copy(other);
1596+
return *this;
1597+
}
1598+
1599+
template<class _Alloc, class _String>
1600+
typename Value<_Alloc, _String>::StringValueHolder& Value<_Alloc, _String>::StringValueHolder::operator=(StringValueHolder&& other) {
1601+
swap(std::move(other));
1602+
return *this;
1603+
}
1604+
1605+
template<class _Alloc, class _String>
1606+
void Value<_Alloc, _String>::StringValueHolder::copy(const StringValueHolder& other) {
1607+
valueStringRaw_ = other.valueStringRaw_;
1608+
if (other.valueStringCopy_)
1609+
valueStringCopy_ = StringDataPtr(new StringData(*other.valueStringCopy_));
1610+
raw_ = other.raw_;
1611+
}
1612+
1613+
template<class _Alloc, class _String>
1614+
void Value<_Alloc, _String>::StringValueHolder::swap(StringValueHolder&& other) {
1615+
std::swap(valueStringRaw_, other.valueStringRaw_);
1616+
std::swap(valueStringCopy_, other.valueStringCopy_);
1617+
std::swap(raw_, other.raw_);
1618+
}
1619+
15821620
// class PathArgument
15831621
// //////////////////////////////////////////////////////////////////
15841622

0 commit comments

Comments
 (0)