Test that integers in JsonValue are copied

This commit is contained in:
Benoit Blanchon
2014-09-28 21:18:43 +02:00
parent e190b20ae1
commit 42ce5ab31f
3 changed files with 66 additions and 18 deletions

View File

@ -36,13 +36,36 @@ void JsonValue::operator=(int value)
void JsonValue::operator=(const JsonObject& object)
{
if (_node)
setAsProxyTo(object._node);
}
void JsonValue::operator=(JsonValue const& value)
{
if (!_node)
{
_node->type = JSON_PROXY;
_node->content.asProxy.target = object._node;
_node = value._node;
return;
}
_node = object._node;
JsonNodeType nodeType = value._node ? value._node->type : JSON_UNDEFINED;
switch (nodeType)
{
case JSON_UNDEFINED:
_node->type = JSON_UNDEFINED;
break;
case JSON_INTEGER:
_node->type = JSON_INTEGER;
_node->content.asInteger = value._node->content.asInteger;
break;
case JSON_OBJECT:
case JSON_ARRAY:
case JSON_PROXY:
setAsProxyTo(value._node);
}
}
JsonValue::operator bool() const
@ -86,6 +109,17 @@ JsonValue::operator JsonObject() const
return JsonObject(getActualNode());
}
void JsonValue::setAsProxyTo(JsonNode* target)
{
if (_node)
{
_node->type = JSON_PROXY;
_node->content.asProxy.target = target;
}
_node = target;
}
JsonNode* JsonValue::getActualNode() const
{
JsonNode* target = _node;