Added JsonArrayIterator (tests are failing)

This commit is contained in:
Benoît Blanchon
2014-07-17 13:58:30 +02:00
parent ca01ecfb49
commit c329572d24
6 changed files with 109 additions and 1 deletions

View File

@ -6,13 +6,14 @@
#pragma once
#include "JsonValue.h"
#include "JsonArrayIterator.h"
namespace ArduinoJson
{
namespace Parser
{
class JsonHashTable;
class JsonArray
{
public:
@ -40,6 +41,16 @@ namespace ArduinoJson
return value[index];
}
JsonArrayIterator begin()
{
return JsonArrayIterator(value);
}
JsonArrayIterator end()
{
return JsonArrayIterator();
}
DEPRECATED int getLength()
{
return size();

View File

@ -0,0 +1,56 @@
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
#pragma once
#include "JsonValue.h"
namespace ArduinoJson
{
namespace Parser
{
class JsonHashTable;
class JsonArrayIterator
{
friend class JsonArray;
public:
JsonArrayIterator operator++()
{
tokens++;
return *this;
}
JsonValue operator*()
{
return JsonValue(json, tokens);
}
bool operator !=(const JsonArrayIterator& other)
{
return tokens != other.tokens || json != other.json;
}
private:
char* json;
jsmntok_t* tokens;
JsonArrayIterator()
: json(0), tokens(0)
{
}
JsonArrayIterator(JsonValue& value)
: json(value.json), tokens(value.tokens)
{
}
};
}
}

View File

@ -26,6 +26,8 @@ namespace ArduinoJson
class JsonValue
{
friend class JsonArrayIterator;
public:
JsonValue()
: json(0), tokens(0)