ListConstIterator.hpp 841 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright Benoit Blanchon 2014-2015
  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-only forward itertor for List<T>
  11. template <typename T>
  12. class ListConstIterator {
  13. public:
  14. explicit ListConstIterator(const ListNode<T> *node = NULL) : _node(node) {}
  15. const T &operator*() const { return _node->content; }
  16. const T *operator->() { return &_node->content; }
  17. bool operator==(const ListConstIterator<T> &other) const {
  18. return _node == other._node;
  19. }
  20. bool operator!=(const ListConstIterator<T> &other) const {
  21. return _node != other._node;
  22. }
  23. ListConstIterator<T> &operator++() {
  24. if (_node) _node = _node->next;
  25. return *this;
  26. }
  27. private:
  28. const ListNode<T> *_node;
  29. };
  30. }
  31. }