JsonValue.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "JsonValue.h"
  2. #include "JsonArray.h"
  3. #include "JsonObject.h"
  4. #include "Internals/JsonNode.h"
  5. void JsonValue::operator=(bool value)
  6. {
  7. if (_node)
  8. _node->setAsBoolean(value);
  9. }
  10. void JsonValue::operator=(char const* value)
  11. {
  12. if (_node)
  13. _node->setAsString(value);
  14. }
  15. void JsonValue::set(double value, int decimals)
  16. {
  17. if (_node)
  18. _node->setAsDouble(value, decimals);
  19. }
  20. void JsonValue::operator=(int value)
  21. {
  22. if (_node)
  23. _node->setAsLong(value);
  24. }
  25. // TODO: it's a duplicate
  26. void JsonValue::operator=(const JsonContainer& object)
  27. {
  28. if (!_node)
  29. {
  30. _node = object._node;
  31. }
  32. else
  33. {
  34. *_node = *object._node;
  35. }
  36. }
  37. // TODO: it's a duplicate
  38. void JsonValue::operator=(JsonValue const& value)
  39. {
  40. if (!_node)
  41. {
  42. _node = value._node;
  43. }
  44. else
  45. {
  46. *_node = *value._node;
  47. }
  48. }
  49. JsonValue::operator bool() const
  50. {
  51. return _node ? _node->getAsBoolean() : false;
  52. }
  53. JsonValue::operator char const*() const
  54. {
  55. return _node ? _node->getAsString() : 0;
  56. }
  57. JsonValue::operator double() const
  58. {
  59. return _node ? _node->getAsDouble() : 0;
  60. }
  61. JsonValue::operator long() const
  62. {
  63. return _node ? _node->getAsInteger() : 0;
  64. }
  65. JsonValue::operator JsonArray() const
  66. {
  67. return JsonArray(_node);
  68. }
  69. JsonValue::operator JsonObject() const
  70. {
  71. return JsonObject(_node);
  72. }