ListIterator.hpp 789 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright Benoit Blanchon 2014
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://github.com/bblanchon/ArduinoJson
  6. #pragma once
  7. #include "ListNode.hpp"
  8. namespace ArduinoJson {
  9. namespace Internals {
  10. // A read-write forward iterator for List<T>
  11. template <typename T>
  12. class ListIterator {
  13. public:
  14. explicit ListIterator(ListNode<T> *node = NULL) : _node(node) {}
  15. T &operator*() const { return _node->content; }
  16. T *operator->() { return &_node->content; }
  17. bool operator==(const ListIterator<T> &other) const {
  18. return _node == other._node;
  19. }
  20. bool operator!=(const ListIterator<T> &other) const {
  21. return _node != other._node;
  22. }
  23. ListIterator<T> &operator++() {
  24. if (_node) _node = _node->next;
  25. return *this;
  26. }
  27. private:
  28. ListNode<T> *_node;
  29. };
  30. }
  31. }