JsonIterator.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright Benoit Blanchon 2014
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://github.com/bblanchon/ArduinoJson
  6. #pragma once
  7. #include "ForwardDeclarations.hpp"
  8. #include "JsonValue.hpp"
  9. namespace ArduinoJson {
  10. template <typename T>
  11. class JsonIterator {
  12. friend class JsonArray;
  13. public:
  14. explicit JsonIterator(Internals::JsonNode *node) : _value(node) {}
  15. T operator*() const { return _value; }
  16. T *operator->() { return &_value; }
  17. bool operator==(const JsonIterator &other) const {
  18. return _value._node == other._value._node;
  19. }
  20. bool operator!=(const JsonIterator &other) const {
  21. return _value._node != other._value._node;
  22. }
  23. JsonIterator &operator++() {
  24. _value._node = _value._node->next;
  25. return *this;
  26. }
  27. private:
  28. T _value;
  29. };
  30. template <typename T>
  31. class JsonConstIterator {
  32. friend class JsonArray;
  33. public:
  34. explicit JsonConstIterator(Internals::JsonNode *node) : _value(node) {}
  35. const JsonValue operator*() const { return _value; }
  36. const JsonValue *operator->() { return &_value; }
  37. bool operator==(const JsonConstIterator &other) const {
  38. return _value._node == other._value._node;
  39. }
  40. bool operator!=(const JsonConstIterator &other) const {
  41. return _value._node != other._value._node;
  42. }
  43. JsonConstIterator &operator++() {
  44. _value._node = _value._node->next;
  45. return *this;
  46. }
  47. private:
  48. JsonValue _value;
  49. };
  50. }