JsonValue.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "JsonObject.h"
  2. #include "JsonNode.h"
  3. #include "JsonValue.h"
  4. void JsonValue::operator=(bool value)
  5. {
  6. if (!_node) return;
  7. _node->type = JSON_BOOLEAN;
  8. _node->content.asBoolean = value;
  9. }
  10. void JsonValue::operator=(char const* value)
  11. {
  12. if (!_node) return;
  13. _node->type = JSON_STRING;
  14. _node->content.asString = value;
  15. }
  16. void JsonValue::operator=(double value)
  17. {
  18. if (!_node) return;
  19. _node->type = JSON_DOUBLE_2_DECIMALS;
  20. _node->content.asDouble = value;
  21. }
  22. void JsonValue::operator=(int value)
  23. {
  24. if (!_node) return;
  25. _node->type = JSON_INTEGER;
  26. _node->content.asInteger = value;
  27. }
  28. void JsonValue::operator=(const JsonObject& object)
  29. {
  30. if (!_node) return;
  31. _node = object._node;
  32. }
  33. JsonValue::operator bool() const
  34. {
  35. if (!_node || _node->type != JSON_BOOLEAN) return 0;
  36. return _node->content.asBoolean;
  37. }
  38. JsonValue::operator char const*() const
  39. {
  40. if (!_node || _node->type != JSON_STRING) return 0;
  41. return _node->content.asString;
  42. }
  43. JsonValue::operator double() const
  44. {
  45. if (!_node || _node->type < JSON_DOUBLE_0_DECIMALS) return 0;
  46. return _node->content.asDouble;
  47. }
  48. JsonValue::operator int() const
  49. {
  50. if (!_node || _node->type != JSON_INTEGER) return 0;
  51. return _node->content.asInteger;
  52. }
  53. JsonValue::operator JsonObject() const
  54. {
  55. return JsonObject(_node);
  56. }