JsonObjectBase.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Arduino JSON library
  3. * Benoit Blanchon 2014 - MIT License
  4. */
  5. #pragma once
  6. #include "JsonPrintable.h"
  7. #include "EscapedString.h"
  8. namespace ArduinoJson
  9. {
  10. namespace Generator
  11. {
  12. class JsonObjectBase : public JsonPrintable
  13. {
  14. public:
  15. JsonValue& operator[](const char*);
  16. template<typename T>
  17. void add(const char* key, T value)
  18. {
  19. operator[](key) = value;
  20. }
  21. template<int DIGITS>
  22. void add(const char* key, double value)
  23. {
  24. operator[](key).set<DIGITS>(value);
  25. }
  26. using JsonPrintable::printTo;
  27. virtual size_t printTo(Print& p) const;
  28. protected:
  29. struct KeyValuePair
  30. {
  31. Internals::EscapedString key;
  32. JsonValue value;
  33. };
  34. JsonObjectBase(KeyValuePair* items, int capacity)
  35. : items(items), capacity(capacity), count(0)
  36. {
  37. }
  38. private:
  39. KeyValuePair* items;
  40. int capacity, count;
  41. };
  42. }
  43. }