JsonValue.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. JsonValue::operator bool()
  29. {
  30. if (!_node || _node->type != JSON_BOOLEAN) return 0;
  31. return _node->content.asBoolean;
  32. }
  33. JsonValue::operator char const*()
  34. {
  35. if (!_node || _node->type != JSON_STRING) return 0;
  36. return _node->content.asString;
  37. }
  38. JsonValue::operator double()
  39. {
  40. if (!_node || _node->type < JSON_DOUBLE_0_DECIMALS) return 0;
  41. return _node->content.asDouble;
  42. }
  43. JsonValue::operator int()
  44. {
  45. if (!_node || _node->type != JSON_INTEGER) return 0;
  46. return _node->content.asInteger;
  47. }