JsonNode.h 1021 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. class JsonBuffer;
  3. enum JsonNodeType
  4. {
  5. JSON_UNDEFINED,
  6. JSON_PROXY,
  7. JSON_NULL,
  8. JSON_ARRAY,
  9. JSON_OBJECT,
  10. JSON_KEY,
  11. JSON_BOOLEAN,
  12. JSON_STRING,
  13. JSON_INTEGER,
  14. JSON_DOUBLE_0_DECIMALS,
  15. JSON_DOUBLE_1_DECIMAL,
  16. JSON_DOUBLE_2_DECIMALS,
  17. // etc.
  18. };
  19. class JsonWriter;
  20. struct JsonNode
  21. {
  22. JsonNode* next;
  23. JsonNodeType type; // <- TODO: hide
  24. void writeTo(JsonWriter&);
  25. union
  26. {
  27. bool asBoolean;
  28. double asDouble;
  29. long asInteger;
  30. const char* asString;
  31. struct
  32. {
  33. const char* key;
  34. JsonNode* value;
  35. } asKey;
  36. struct
  37. {
  38. JsonNode* child;
  39. JsonBuffer* buffer;
  40. } asContainer;
  41. struct
  42. {
  43. JsonNode* target;
  44. } asProxy;
  45. } content;
  46. private:
  47. inline void writeArrayTo(JsonWriter&);
  48. inline void writeObjectTo(JsonWriter&);
  49. };