mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-18 04:52:22 +02:00
Added JsonArrayIterator (tests are failing)
This commit is contained in:
@ -6,13 +6,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "JsonValue.h"
|
#include "JsonValue.h"
|
||||||
|
#include "JsonArrayIterator.h"
|
||||||
|
|
||||||
namespace ArduinoJson
|
namespace ArduinoJson
|
||||||
{
|
{
|
||||||
namespace Parser
|
namespace Parser
|
||||||
{
|
{
|
||||||
class JsonHashTable;
|
class JsonHashTable;
|
||||||
|
|
||||||
class JsonArray
|
class JsonArray
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -40,6 +41,16 @@ namespace ArduinoJson
|
|||||||
return value[index];
|
return value[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonArrayIterator begin()
|
||||||
|
{
|
||||||
|
return JsonArrayIterator(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonArrayIterator end()
|
||||||
|
{
|
||||||
|
return JsonArrayIterator();
|
||||||
|
}
|
||||||
|
|
||||||
DEPRECATED int getLength()
|
DEPRECATED int getLength()
|
||||||
{
|
{
|
||||||
return size();
|
return size();
|
||||||
|
56
JsonParser/JsonArrayIterator.h
Normal file
56
JsonParser/JsonArrayIterator.h
Normal 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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -26,6 +26,8 @@ namespace ArduinoJson
|
|||||||
|
|
||||||
class JsonValue
|
class JsonValue
|
||||||
{
|
{
|
||||||
|
friend class JsonArrayIterator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
JsonValue()
|
JsonValue()
|
||||||
: json(0), tokens(0)
|
: json(0), tokens(0)
|
||||||
|
31
JsonParserTests/JsonArrayIteratorTests.cpp
Normal file
31
JsonParserTests/JsonArrayIteratorTests.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "CppUnitTest.h"
|
||||||
|
#include "JsonParser.h"
|
||||||
|
|
||||||
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||||
|
using namespace ArduinoJson::Parser;
|
||||||
|
|
||||||
|
|
||||||
|
namespace JsonParserTests
|
||||||
|
{
|
||||||
|
TEST_CLASS(JsonArrayIteratorTests)
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
TEST_METHOD(TestMethod1)
|
||||||
|
{
|
||||||
|
char json [] = "[1,2,3]";
|
||||||
|
JsonParser<4> parser;
|
||||||
|
|
||||||
|
JsonArray a = parser.parse(json);
|
||||||
|
|
||||||
|
long expected = 1;
|
||||||
|
|
||||||
|
for (auto i : a)
|
||||||
|
{
|
||||||
|
Assert::AreEqual(expected, (long)*i);
|
||||||
|
expected++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
@ -90,6 +90,7 @@
|
|||||||
<ClCompile Include="..\JsonParser\JsonHashTable.cpp" />
|
<ClCompile Include="..\JsonParser\JsonHashTable.cpp" />
|
||||||
<ClCompile Include="..\JsonParser\JsonParserBase.cpp" />
|
<ClCompile Include="..\JsonParser\JsonParserBase.cpp" />
|
||||||
<ClCompile Include="..\JsonParser\JsonValue.cpp" />
|
<ClCompile Include="..\JsonParser\JsonValue.cpp" />
|
||||||
|
<ClCompile Include="JsonArrayIteratorTests.cpp" />
|
||||||
<ClCompile Include="JsonArrayTests.cpp" />
|
<ClCompile Include="JsonArrayTests.cpp" />
|
||||||
<ClCompile Include="JsonHashTableTests.cpp" />
|
<ClCompile Include="JsonHashTableTests.cpp" />
|
||||||
<ClCompile Include="GbathreeBug.cpp" />
|
<ClCompile Include="GbathreeBug.cpp" />
|
||||||
@ -97,6 +98,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\JsonParser\jsmn.h" />
|
<ClInclude Include="..\JsonParser\jsmn.h" />
|
||||||
<ClInclude Include="..\JsonParser\JsonArray.h" />
|
<ClInclude Include="..\JsonParser\JsonArray.h" />
|
||||||
|
<ClInclude Include="..\JsonParser\JsonArrayIterator.h" />
|
||||||
<ClInclude Include="..\JsonParser\JsonHashTable.h" />
|
<ClInclude Include="..\JsonParser\JsonHashTable.h" />
|
||||||
<ClInclude Include="..\JsonParser\JsonParser.h" />
|
<ClInclude Include="..\JsonParser\JsonParser.h" />
|
||||||
<ClInclude Include="..\JsonParser\JsonParserBase.h" />
|
<ClInclude Include="..\JsonParser\JsonParserBase.h" />
|
||||||
|
@ -39,6 +39,9 @@
|
|||||||
<ClCompile Include="..\JsonParser\JsonValue.cpp">
|
<ClCompile Include="..\JsonParser\JsonValue.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="JsonArrayIteratorTests.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\JsonParser\jsmn.h">
|
<ClInclude Include="..\JsonParser\jsmn.h">
|
||||||
@ -59,5 +62,8 @@
|
|||||||
<ClInclude Include="..\JsonParser\JsonValue.h">
|
<ClInclude Include="..\JsonParser\JsonValue.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\JsonParser\JsonArrayIterator.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Reference in New Issue
Block a user