JsonArrayBase.h 1.0 KB

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