2014-09-27 14:51:50 +02:00
|
|
|
#include "JsonValue.h"
|
2014-10-05 15:13:00 +02:00
|
|
|
|
|
|
|
#include "JsonArray.h"
|
|
|
|
#include "JsonObject.h"
|
2014-10-01 16:08:32 +02:00
|
|
|
#include "Internals/JsonNode.h"
|
2014-09-27 14:51:50 +02:00
|
|
|
|
2014-09-27 15:04:06 +02:00
|
|
|
void JsonValue::operator=(bool value)
|
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
if (_node)
|
|
|
|
_node->setAsBoolean(value);
|
2014-09-27 15:04:06 +02:00
|
|
|
}
|
|
|
|
|
2014-09-27 15:24:16 +02:00
|
|
|
void JsonValue::operator=(char const* value)
|
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
if (_node)
|
|
|
|
_node->setAsString(value);
|
2014-09-30 17:32:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void JsonValue::set(double value, int decimals)
|
2014-09-27 14:59:02 +02:00
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
if (_node)
|
|
|
|
_node->setAsDouble(value, decimals);
|
2014-09-27 14:59:02 +02:00
|
|
|
}
|
2014-09-27 14:51:50 +02:00
|
|
|
|
|
|
|
void JsonValue::operator=(int value)
|
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
if (_node)
|
|
|
|
_node->setAsLong(value);
|
2014-09-27 14:51:50 +02:00
|
|
|
}
|
|
|
|
|
2014-10-09 12:14:10 +02:00
|
|
|
// TODO: it's a duplicate
|
2014-10-05 15:13:00 +02:00
|
|
|
void JsonValue::operator=(const JsonContainer& object)
|
2014-09-27 16:18:40 +02:00
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
if (!_node)
|
|
|
|
{
|
|
|
|
_node = object._node;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*_node = *object._node;
|
|
|
|
}
|
2014-09-28 21:18:43 +02:00
|
|
|
}
|
|
|
|
|
2014-10-09 12:14:10 +02:00
|
|
|
// TODO: it's a duplicate
|
2014-09-28 21:18:43 +02:00
|
|
|
void JsonValue::operator=(JsonValue const& value)
|
|
|
|
{
|
|
|
|
if (!_node)
|
2014-09-28 21:04:59 +02:00
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
_node = value._node;
|
2014-09-28 21:04:59 +02:00
|
|
|
}
|
2014-10-09 12:14:10 +02:00
|
|
|
else
|
2014-09-28 21:18:43 +02:00
|
|
|
{
|
2014-09-28 21:22:20 +02:00
|
|
|
*_node = *value._node;
|
2014-10-09 12:14:10 +02:00
|
|
|
}
|
2014-09-27 16:18:40 +02:00
|
|
|
}
|
|
|
|
|
2014-09-27 15:25:00 +02:00
|
|
|
JsonValue::operator bool() const
|
2014-09-27 15:04:06 +02:00
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
return _node ? _node->getAsBoolean() : false;
|
2014-09-27 15:04:06 +02:00
|
|
|
}
|
|
|
|
|
2014-09-27 15:25:00 +02:00
|
|
|
JsonValue::operator char const*() const
|
2014-09-27 15:24:16 +02:00
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
return _node ? _node->getAsString() : 0;
|
2014-09-27 15:24:16 +02:00
|
|
|
}
|
|
|
|
|
2014-09-27 15:25:00 +02:00
|
|
|
JsonValue::operator double() const
|
2014-09-27 14:59:02 +02:00
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
return _node ? _node->getAsDouble() : 0;
|
2014-09-27 14:59:02 +02:00
|
|
|
}
|
2014-09-27 14:51:50 +02:00
|
|
|
|
2014-10-09 12:14:10 +02:00
|
|
|
JsonValue::operator long() const
|
2014-09-27 14:51:50 +02:00
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
return _node ? _node->getAsInteger() : 0;
|
2014-09-27 16:18:40 +02:00
|
|
|
}
|
|
|
|
|
2014-10-05 15:13:00 +02:00
|
|
|
JsonValue::operator JsonArray() const
|
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
return JsonArray(_node);
|
2014-10-05 15:13:00 +02:00
|
|
|
}
|
|
|
|
|
2014-09-27 16:18:40 +02:00
|
|
|
JsonValue::operator JsonObject() const
|
|
|
|
{
|
2014-10-09 12:14:10 +02:00
|
|
|
return JsonObject(_node);
|
2014-09-27 14:51:50 +02:00
|
|
|
}
|