Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions src/JSONValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,25 +410,50 @@ JSONValue::JSONValue(const JSONObject &m_object_value)
*/
JSONValue::JSONValue(const JSONValue &m_source)
{
type = m_source.type;
DeepAssignment (m_source);
}

/**
* Assignment operator to perform a deep copy of array / object values
*
* @access public
*
* @param JSONValue m_source The source JSONValue that is being copied
*/
JSONValue& JSONValue::operator= (const JSONValue &m_source)
{
if (this == &m_source)
{
// Self-assignment, return without doing anything
return *this;
}

DeepAssignment (m_source);

return *this;
}

void JSONValue::DeepAssignment (const JSONValue &source)
{
type = source.type;

switch (type)
{
case JSONType_String:
string_value = m_source.string_value;
string_value = source.string_value;
break;

case JSONType_Bool:
bool_value = m_source.bool_value;
bool_value = source.bool_value;
break;

case JSONType_Number:
number_value = m_source.number_value;
number_value = source.number_value;
break;

case JSONType_Array:
{
JSONArray source_array = m_source.array_value;
JSONArray source_array = source.array_value;
JSONArray::iterator iter;
for (iter = source_array.begin(); iter != source_array.end(); iter++)
array_value.push_back(new JSONValue(**iter));
Expand All @@ -437,7 +462,7 @@ JSONValue::JSONValue(const JSONValue &m_source)

case JSONType_Object:
{
JSONObject source_object = m_source.object_value;
JSONObject source_object = source.object_value;
JSONObject::iterator iter;
for (iter = source_object.begin(); iter != source_object.end(); iter++)
{
Expand Down
2 changes: 2 additions & 0 deletions src/JSONValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class JSONValue
JSONValue(const JSONArray &m_array_value);
JSONValue(const JSONObject &m_object_value);
JSONValue(const JSONValue &m_source);
JSONValue& operator= (const JSONValue &m_source);
~JSONValue();

bool IsNull() const;
Expand Down Expand Up @@ -74,6 +75,7 @@ class JSONValue
static JSONValue *Parse(const wchar_t **data);

private:
void DeepAssignment (const JSONValue &source);
static std::wstring StringifyString(const std::wstring &str);
std::wstring StringifyImpl(size_t const indentDepth) const;
static std::wstring Indent(size_t depth);
Expand Down