Files
ArduinoJson/JsonParser/JsonArray.h

103 lines
2.6 KiB
C
Raw Permalink Normal View History

2014-07-03 13:58:08 +02:00
/*
* Arduino JSON library
* Benoit Blanchon 2014 - MIT License
*/
2014-01-11 15:05:35 +01:00
2014-07-03 13:58:08 +02:00
#pragma once
2014-01-11 15:05:35 +01:00
#include "JsonValue.h"
#include "JsonArrayIterator.h"
2014-07-03 14:00:51 +02:00
namespace ArduinoJson
2014-01-11 15:05:35 +01:00
{
2014-07-03 14:00:51 +02:00
namespace Parser
{
2014-07-18 16:46:01 +02:00
class JsonObject;
2014-07-21 14:14:31 +02:00
2014-07-21 15:20:02 +02:00
// A JSON array
class JsonArray : JsonValue
2014-07-18 15:43:20 +02:00
{
2014-07-03 14:00:51 +02:00
public:
2014-01-11 15:05:35 +01:00
2014-07-21 15:20:02 +02:00
// Create an invalid array
2014-07-19 12:44:27 +02:00
JsonArray()
{
2014-07-18 15:43:20 +02:00
}
2014-07-21 14:14:31 +02:00
2014-07-21 15:20:02 +02:00
// Convert a JsonValue into a JsonArray
JsonArray(JsonValue value)
: JsonValue(value)
{
}
2014-07-21 14:14:31 +02:00
2014-07-21 15:20:02 +02:00
// Tell if the array is valid
bool success()
{
2014-07-19 12:44:27 +02:00
return isArray();
}
2014-07-21 14:14:31 +02:00
2014-07-21 15:20:02 +02:00
// Get the JsonValue at specified index
JsonValue operator[](int index)
{
return JsonValue::operator[](index);
}
2014-07-21 14:14:31 +02:00
2014-07-21 15:20:02 +02:00
// Get the size of the array
int size()
2014-07-03 14:00:51 +02:00
{
return isArray() ? childrenCount() : 0;
2014-07-03 14:00:51 +02:00
}
2014-07-21 14:14:31 +02:00
2014-07-21 15:20:02 +02:00
// Get an iterator pointing to the beginning of the array
JsonArrayIterator begin()
{
return isArray() ? firstChild() : null();
}
2014-07-21 14:14:31 +02:00
2014-07-21 15:20:02 +02:00
// Gets an iterator pointing to the end of the array
JsonArrayIterator end()
{
return isArray() ? nextSibling() : null();
}
2014-07-21 14:14:31 +02:00
2014-07-21 15:20:02 +02:00
// Obsolete: Use size() instead
DEPRECATED int getLength()
{
return size();
}
2014-07-21 14:14:31 +02:00
2014-07-21 15:20:02 +02:00
// Obsolete: Use operator[] instead
2014-07-16 13:53:56 +02:00
DEPRECATED JsonArray getArray(int index)
{
return operator[](index);
}
2014-07-21 15:20:02 +02:00
// Obsolete: Use operator[] instead
2014-07-16 13:53:56 +02:00
DEPRECATED bool getBool(int index)
{
return operator[](index);
}
2014-07-21 15:20:02 +02:00
// Obsolete: Use operator[] instead
2014-07-16 13:53:56 +02:00
DEPRECATED double getDouble(int index)
{
return operator[](index);
}
2014-07-21 15:20:02 +02:00
// Obsolete: Use operator[] instead
2014-07-18 16:46:01 +02:00
DEPRECATED JsonObject getHashTable(int index);
2014-07-21 15:20:02 +02:00
// Obsolete: Use operator[] instead
2014-07-16 13:53:56 +02:00
DEPRECATED long getLong(int index)
{
return operator[](index);
}
2014-07-21 15:20:02 +02:00
// Obsolete: Use operator[] instead
2014-07-16 13:53:56 +02:00
DEPRECATED char* getString(int index)
{
return operator[](index);
2014-07-18 15:43:20 +02:00
}
2014-07-03 14:00:51 +02:00
};
}
}