ListIterator.hpp 974 B

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