mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-02-25 15:46:03 +01:00
Merge pull request #635 from Dark-Passenger/master
Add move assignment operator for Json::Value class and overload append member function for RValue references resolves #621
This commit is contained in:
commit
414b179d86
@ -23,7 +23,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Conditional NORETURN attribute on the throw functions would:
|
//Conditional NORETURN attribute on the throw functions would:
|
||||||
// a) suppress false positives from static code analysis
|
// a) suppress false positives from static code analysis
|
||||||
// b) possibly improve optimization opportunities.
|
// b) possibly improve optimization opportunities.
|
||||||
#if !defined(JSONCPP_NORETURN)
|
#if !defined(JSONCPP_NORETURN)
|
||||||
# if defined(_MSC_VER)
|
# if defined(_MSC_VER)
|
||||||
@ -64,7 +64,7 @@ protected:
|
|||||||
/** Exceptions which the user cannot easily avoid.
|
/** Exceptions which the user cannot easily avoid.
|
||||||
*
|
*
|
||||||
* E.g. out-of-memory (when we use malloc), stack-overflow, malicious input
|
* E.g. out-of-memory (when we use malloc), stack-overflow, malicious input
|
||||||
*
|
*
|
||||||
* \remark derived from Json::Exception
|
* \remark derived from Json::Exception
|
||||||
*/
|
*/
|
||||||
class JSON_API RuntimeError : public Exception {
|
class JSON_API RuntimeError : public Exception {
|
||||||
@ -75,7 +75,7 @@ public:
|
|||||||
/** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
|
/** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
|
||||||
*
|
*
|
||||||
* These are precondition-violations (user bugs) and internal errors (our bugs).
|
* These are precondition-violations (user bugs) and internal errors (our bugs).
|
||||||
*
|
*
|
||||||
* \remark derived from Json::Exception
|
* \remark derived from Json::Exception
|
||||||
*/
|
*/
|
||||||
class JSON_API LogicError : public Exception {
|
class JSON_API LogicError : public Exception {
|
||||||
@ -233,7 +233,12 @@ private:
|
|||||||
CZString(CZString&& other);
|
CZString(CZString&& other);
|
||||||
#endif
|
#endif
|
||||||
~CZString();
|
~CZString();
|
||||||
CZString& operator=(CZString other);
|
CZString& operator=(const CZString& other);
|
||||||
|
|
||||||
|
#if JSON_HAS_RVALUE_REFERENCES
|
||||||
|
CZString& operator=(CZString&& other);
|
||||||
|
#endif
|
||||||
|
|
||||||
bool operator<(CZString const& other) const;
|
bool operator<(CZString const& other) const;
|
||||||
bool operator==(CZString const& other) const;
|
bool operator==(CZString const& other) const;
|
||||||
ArrayIndex index() const;
|
ArrayIndex index() const;
|
||||||
@ -322,12 +327,21 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
|
|
||||||
/// Deep copy, then swap(other).
|
/// Deep copy, then swap(other).
|
||||||
/// \note Over-write existing comments. To preserve comments, use #swapPayload().
|
/// \note Over-write existing comments. To preserve comments, use #swapPayload().
|
||||||
Value& operator=(Value other);
|
Value& operator=(const Value& other);
|
||||||
|
#if JSON_HAS_RVALUE_REFERENCES
|
||||||
|
Value& operator=(Value&& other);
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Swap everything.
|
/// Swap everything.
|
||||||
void swap(Value& other);
|
void swap(Value& other);
|
||||||
/// Swap values but leave comments and source offsets in place.
|
/// Swap values but leave comments and source offsets in place.
|
||||||
void swapPayload(Value& other);
|
void swapPayload(Value& other);
|
||||||
|
|
||||||
|
/// copy everything.
|
||||||
|
void copy(const Value& other);
|
||||||
|
/// copy values but leave comments and source offsets in place.
|
||||||
|
void copyPayload(const Value& other);
|
||||||
|
|
||||||
ValueType type() const;
|
ValueType type() const;
|
||||||
|
|
||||||
/// Compare payload only, not comments etc.
|
/// Compare payload only, not comments etc.
|
||||||
@ -438,6 +452,10 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
/// Equivalent to jsonvalue[jsonvalue.size()] = value;
|
/// Equivalent to jsonvalue[jsonvalue.size()] = value;
|
||||||
Value& append(const Value& value);
|
Value& append(const Value& value);
|
||||||
|
|
||||||
|
#if JSON_HAS_RVALUE_REFERENCES
|
||||||
|
Value& append(Value&& value);
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Access an object value by name, create a null member if it does not exist.
|
/// Access an object value by name, create a null member if it does not exist.
|
||||||
/// \note Because of our implementation, keys are limited to 2^30 -1 chars.
|
/// \note Because of our implementation, keys are limited to 2^30 -1 chars.
|
||||||
/// Exceeding that will cause an exception.
|
/// Exceeding that will cause an exception.
|
||||||
|
@ -292,11 +292,21 @@ void Value::CZString::swap(CZString& other) {
|
|||||||
std::swap(index_, other.index_);
|
std::swap(index_, other.index_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::CZString& Value::CZString::operator=(CZString other) {
|
Value::CZString& Value::CZString::operator=(const CZString& other) {
|
||||||
swap(other);
|
cstr_ = other.cstr_;
|
||||||
|
index_ = other.index_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if JSON_HAS_RVALUE_REFERENCES
|
||||||
|
Value::CZString& Value::CZString::operator=(CZString&& other) {
|
||||||
|
cstr_ = other.cstr_;
|
||||||
|
index_ = other.index_;
|
||||||
|
other.cstr_ = nullptr;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool Value::CZString::operator<(const CZString& other) const {
|
bool Value::CZString::operator<(const CZString& other) const {
|
||||||
if (!cstr_) return index_ < other.index_;
|
if (!cstr_) return index_ < other.index_;
|
||||||
//return strcmp(cstr_, other.cstr_) < 0;
|
//return strcmp(cstr_, other.cstr_) < 0;
|
||||||
@ -398,7 +408,7 @@ Value::Value(double value) {
|
|||||||
|
|
||||||
Value::Value(const char* value) {
|
Value::Value(const char* value) {
|
||||||
initBasic(stringValue, true);
|
initBasic(stringValue, true);
|
||||||
JSON_ASSERT_MESSAGE(value != NULL, "Null Value Passed to Value Constructor");
|
JSON_ASSERT_MESSAGE(value != NULL, "Null Value Passed to Value Constructor");
|
||||||
value_.string_ = duplicateAndPrefixStringValue(value, static_cast<unsigned>(strlen(value)));
|
value_.string_ = duplicateAndPrefixStringValue(value, static_cast<unsigned>(strlen(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,10 +518,18 @@ Value::~Value() {
|
|||||||
value_.uint_ = 0;
|
value_.uint_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value& Value::operator=(Value other) {
|
Value& Value::operator=(const Value& other) {
|
||||||
|
swap(const_cast<Value&>(other));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if JSON_HAS_RVALUE_REFERENCES
|
||||||
|
Value& Value::operator=(Value&& other) {
|
||||||
|
initBasic(nullValue);
|
||||||
swap(other);
|
swap(other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void Value::swapPayload(Value& other) {
|
void Value::swapPayload(Value& other) {
|
||||||
ValueType temp = type_;
|
ValueType temp = type_;
|
||||||
@ -523,6 +541,12 @@ void Value::swapPayload(Value& other) {
|
|||||||
other.allocated_ = temp2 & 0x1;
|
other.allocated_ = temp2 & 0x1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Value::copyPayload(const Value& other) {
|
||||||
|
type_ = other.type_;
|
||||||
|
value_ = other.value_;
|
||||||
|
allocated_ = other.allocated_;
|
||||||
|
}
|
||||||
|
|
||||||
void Value::swap(Value& other) {
|
void Value::swap(Value& other) {
|
||||||
swapPayload(other);
|
swapPayload(other);
|
||||||
std::swap(comments_, other.comments_);
|
std::swap(comments_, other.comments_);
|
||||||
@ -530,6 +554,13 @@ void Value::swap(Value& other) {
|
|||||||
std::swap(limit_, other.limit_);
|
std::swap(limit_, other.limit_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Value::copy(const Value& other) {
|
||||||
|
copyPayload(other);
|
||||||
|
comments_ = other.comments_;
|
||||||
|
start_ = other.start_;
|
||||||
|
limit_ = other.limit_;
|
||||||
|
}
|
||||||
|
|
||||||
ValueType Value::type() const { return type_; }
|
ValueType Value::type() const { return type_; }
|
||||||
|
|
||||||
int Value::compare(const Value& other) const {
|
int Value::compare(const Value& other) const {
|
||||||
@ -1124,6 +1155,10 @@ Value const& Value::operator[](CppTL::ConstString const& key) const
|
|||||||
|
|
||||||
Value& Value::append(const Value& value) { return (*this)[size()] = value; }
|
Value& Value::append(const Value& value) { return (*this)[size()] = value; }
|
||||||
|
|
||||||
|
#if JSON_HAS_RVALUE_REFERENCES
|
||||||
|
Value& Value::append(Value&& value) { return (*this)[size()] = value; }
|
||||||
|
#endif
|
||||||
|
|
||||||
Value Value::get(char const* key, char const* cend, Value const& defaultValue) const
|
Value Value::get(char const* key, char const* cend, Value const& defaultValue) const
|
||||||
{
|
{
|
||||||
Value const* found = find(key, cend);
|
Value const* found = find(key, cend);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user