forked from bblanchon/ArduinoJson
Added JsonObjectIterator
This commit is contained in:
@ -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);
|
||||
};
|
||||
|
52
include/ArduinoJson/JsonObjectIterator.hpp
Normal file
52
include/ArduinoJson/JsonObjectIterator.hpp
Normal 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;
|
||||
};
|
||||
}
|
28
include/ArduinoJson/JsonObjectKeyValue.hpp
Normal file
28
include/ArduinoJson/JsonObjectKeyValue.hpp
Normal 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;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user