Added JsonObjectIterator

This commit is contained in:
Benoit Blanchon
2014-10-22 21:56:38 +02:00
parent 7e98d136f4
commit 40ac60b941
5 changed files with 121 additions and 1 deletions

View File

@ -1,6 +1,7 @@
#pragma once
#include "JsonContainer.hpp"
#include "ArduinoJson/JsonContainer.hpp"
#include "ArduinoJson/JsonObjectIterator.hpp"
namespace ArduinoJson
{
@ -28,6 +29,13 @@ namespace ArduinoJson
return _node && _node->isObject();
}
JsonObjectIterator begin();
JsonObjectIterator end()
{
return JsonObjectIterator(0);
}
private:
Internals::JsonNode* getOrCreateNodeAt(const char* key);
};

View File

@ -0,0 +1,52 @@
#pragma once
#include "ArduinoJson/JsonObjectKeyValue.hpp"
namespace ArduinoJson
{
class JsonObject;
class JsonObjectIterator
{
friend class JsonObject;
public:
explicit JsonObjectIterator(Internals::JsonNode* node)
: _node(node)
{
}
const char* key() const
{
return operator*().key();
}
JsonValue value() const
{
return operator*().value();
}
void operator++()
{
_node = _node->next;
}
JsonObjectKeyValue operator*() const
{
return JsonObjectKeyValue(_node);
}
bool operator==(const JsonObjectIterator& other) const
{
return _node == other._node;
}
bool operator!=(const JsonObjectIterator& other) const
{
return _node != other._node;
}
private:
Internals::JsonNode* _node;
};
}

View File

@ -0,0 +1,28 @@
#pragma once
#include "ArduinoJson/JsonValue.hpp"
namespace ArduinoJson
{
class JsonObjectKeyValue
{
public:
explicit JsonObjectKeyValue(Internals::JsonNode* node)
: _node(node)
{
}
const char* key()
{
return _node->getAsObjectKey();
}
JsonValue value()
{
return JsonValue(_node->getAsObjectValue());
}
private:
Internals::JsonNode* _node;
};
}