JsonObjectIterator.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Arduino JSON library
  3. * Benoit Blanchon 2014 - MIT License
  4. */
  5. #pragma once
  6. #include "JsonValue.h"
  7. #include "JsonPair.h"
  8. #include "JsonToken.h"
  9. namespace ArduinoJson
  10. {
  11. namespace Parser
  12. {
  13. // An iterator for JsonObject
  14. class JsonObjectIterator : JsonToken
  15. {
  16. public:
  17. // Create an iterator pointing at the specified token
  18. JsonObjectIterator(JsonToken token)
  19. : JsonToken(token)
  20. {
  21. }
  22. // Move to the next JsonPair
  23. void operator++()
  24. {
  25. *this = JsonObjectIterator(nextSibling().nextSibling());
  26. }
  27. // Get the JsonPair pointed by the iterator
  28. JsonPair operator*() const
  29. {
  30. return JsonPair(*this);
  31. }
  32. // Test iterator equality
  33. bool operator!= (const JsonObjectIterator& other) const
  34. {
  35. return JsonToken::operator!=(other);
  36. }
  37. // Get the key of the JsonPair pointed by the iterator
  38. const char* key() const
  39. {
  40. return operator*().key();
  41. }
  42. // Get the key of the JsonPair pointed by the iterator
  43. JsonValue value() const
  44. {
  45. return operator*().value();
  46. }
  47. };
  48. }
  49. }