forked from bblanchon/ArduinoJson
Replaced public inheritance by protected and private
This commit is contained in:
@ -10,17 +10,17 @@ using namespace ArduinoJson::Parser;
|
|||||||
|
|
||||||
DEPRECATED JsonObject JsonArray::getHashTable(int index)
|
DEPRECATED JsonObject JsonArray::getHashTable(int index)
|
||||||
{
|
{
|
||||||
return (JsonObject) (*this)[index];
|
return operator[](index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the token for the value at the specified index
|
* Returns the token for the value at the specified index
|
||||||
*/
|
*/
|
||||||
JsonValue JsonArray::getValue(int index)
|
JsonValue JsonArray::operator[](int index)
|
||||||
{
|
{
|
||||||
// sanity check
|
// sanity check
|
||||||
if (index < 0 || !isArray() || index >= size())
|
if (index < 0 || !isArray() || index >= size())
|
||||||
return JsonValue::null();
|
return null();
|
||||||
|
|
||||||
// skip first token, it's the whole object
|
// skip first token, it's the whole object
|
||||||
JsonToken runningToken = firstChild();
|
JsonToken runningToken = firstChild();
|
||||||
|
@ -15,7 +15,7 @@ namespace ArduinoJson
|
|||||||
{
|
{
|
||||||
class JsonObject;
|
class JsonObject;
|
||||||
|
|
||||||
class JsonArray : public JsonToken
|
class JsonArray : JsonValue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -23,8 +23,8 @@ namespace ArduinoJson
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonArray(JsonToken token)
|
JsonArray(JsonValue value)
|
||||||
: JsonToken(token)
|
: JsonValue(value)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,10 +38,7 @@ namespace ArduinoJson
|
|||||||
return isArray() ? JsonToken::size() : 0;
|
return isArray() ? JsonToken::size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonValue operator[](int index)
|
JsonValue operator[](int index);
|
||||||
{
|
|
||||||
return getValue(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonArrayIterator begin()
|
JsonArrayIterator begin()
|
||||||
{
|
{
|
||||||
@ -60,34 +57,30 @@ namespace ArduinoJson
|
|||||||
|
|
||||||
DEPRECATED JsonArray getArray(int index)
|
DEPRECATED JsonArray getArray(int index)
|
||||||
{
|
{
|
||||||
return getValue(index);
|
return operator[](index);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEPRECATED bool getBool(int index)
|
DEPRECATED bool getBool(int index)
|
||||||
{
|
{
|
||||||
return getValue(index);
|
return operator[](index);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEPRECATED double getDouble(int index)
|
DEPRECATED double getDouble(int index)
|
||||||
{
|
{
|
||||||
return getValue(index);
|
return operator[](index);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEPRECATED JsonObject getHashTable(int index);
|
DEPRECATED JsonObject getHashTable(int index);
|
||||||
|
|
||||||
DEPRECATED long getLong(int index)
|
DEPRECATED long getLong(int index)
|
||||||
{
|
{
|
||||||
return getValue(index);
|
return operator[](index);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEPRECATED char* getString(int index)
|
DEPRECATED char* getString(int index)
|
||||||
{
|
{
|
||||||
return getValue(index);
|
return operator[](index);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
JsonValue getValue(int index);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,7 +12,7 @@ namespace ArduinoJson
|
|||||||
{
|
{
|
||||||
namespace Parser
|
namespace Parser
|
||||||
{
|
{
|
||||||
class JsonArrayIterator : public JsonToken
|
class JsonArrayIterator : JsonToken
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -31,6 +31,11 @@ namespace ArduinoJson
|
|||||||
{
|
{
|
||||||
return JsonValue(*this);
|
return JsonValue(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator!= (const JsonArrayIterator& other) const
|
||||||
|
{
|
||||||
|
return JsonToken::operator!=(other);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,17 +12,17 @@ using namespace ArduinoJson::Parser;
|
|||||||
|
|
||||||
DEPRECATED JsonArray JsonObject::getArray(const char* key)
|
DEPRECATED JsonArray JsonObject::getArray(const char* key)
|
||||||
{
|
{
|
||||||
return (*this)[key];
|
return operator[](key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the token for the value associated with the specified key
|
* Returns the token for the value associated with the specified key
|
||||||
*/
|
*/
|
||||||
JsonValue JsonObject::getValue(const char* desiredKey)
|
JsonValue JsonObject::operator[](const char* desiredKey)
|
||||||
{
|
{
|
||||||
// sanity check
|
// sanity check
|
||||||
if (desiredKey == 0 || !isObject())
|
if (desiredKey == 0 || !isObject())
|
||||||
return JsonValue::null();
|
return null();
|
||||||
|
|
||||||
// skip first token, it's the whole object
|
// skip first token, it's the whole object
|
||||||
JsonToken runningToken = firstChild();
|
JsonToken runningToken = firstChild();
|
||||||
|
@ -14,7 +14,7 @@ namespace ArduinoJson
|
|||||||
{
|
{
|
||||||
class JsonArray;
|
class JsonArray;
|
||||||
|
|
||||||
class JsonObject : public JsonToken
|
class JsonObject : JsonValue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JsonObject()
|
JsonObject()
|
||||||
@ -22,8 +22,8 @@ namespace ArduinoJson
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonObject(JsonToken token)
|
JsonObject(JsonValue value)
|
||||||
: JsonToken(token)
|
: JsonValue(value)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -33,14 +33,11 @@ namespace ArduinoJson
|
|||||||
return isObject();
|
return isObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonValue operator[](const char* key)
|
JsonValue operator[](const char* key);
|
||||||
{
|
|
||||||
return getValue(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool containsKey(const char* key)
|
bool containsKey(const char* key)
|
||||||
{
|
{
|
||||||
return getValue(key).success();
|
return operator[](key).success();
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonObjectIterator begin()
|
JsonObjectIterator begin()
|
||||||
@ -57,37 +54,33 @@ namespace ArduinoJson
|
|||||||
|
|
||||||
DEPRECATED bool getBool(const char* key)
|
DEPRECATED bool getBool(const char* key)
|
||||||
{
|
{
|
||||||
return getValue(key);
|
return operator[](key);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEPRECATED double getDouble(const char* key)
|
DEPRECATED double getDouble(const char* key)
|
||||||
{
|
{
|
||||||
return getValue(key);
|
return operator[](key);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEPRECATED JsonObject getHashTable(const char* key)
|
DEPRECATED JsonObject getHashTable(const char* key)
|
||||||
{
|
{
|
||||||
return getValue(key);
|
return operator[](key);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEPRECATED long getLong(const char* key)
|
DEPRECATED long getLong(const char* key)
|
||||||
{
|
{
|
||||||
return getValue(key);
|
return operator[](key);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEPRECATED char* getString(const char* key)
|
DEPRECATED char* getString(const char* key)
|
||||||
{
|
{
|
||||||
return getValue(key);
|
return operator[](key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static JsonObject null()
|
static JsonObject null()
|
||||||
{
|
{
|
||||||
return JsonObject(JsonToken::null());
|
return JsonObject(JsonToken::null());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
JsonValue getValue(const char* key);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef JsonObject JsonHashTable;
|
typedef JsonObject JsonHashTable;
|
||||||
|
@ -13,7 +13,7 @@ namespace ArduinoJson
|
|||||||
{
|
{
|
||||||
namespace Parser
|
namespace Parser
|
||||||
{
|
{
|
||||||
class JsonObjectIterator : public JsonToken
|
class JsonObjectIterator : JsonToken
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -31,6 +31,11 @@ namespace ArduinoJson
|
|||||||
{
|
{
|
||||||
return JsonPair(*this);
|
return JsonPair(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator!= (const JsonObjectIterator& other) const
|
||||||
|
{
|
||||||
|
return JsonToken::operator!=(other);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,7 +11,7 @@ namespace ArduinoJson
|
|||||||
{
|
{
|
||||||
namespace Parser
|
namespace Parser
|
||||||
{
|
{
|
||||||
class JsonPair : public JsonToken
|
class JsonPair : JsonToken
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JsonPair(JsonToken token)
|
JsonPair(JsonToken token)
|
||||||
@ -27,7 +27,7 @@ namespace ArduinoJson
|
|||||||
|
|
||||||
JsonValue value()
|
JsonValue value()
|
||||||
{
|
{
|
||||||
return JsonValue(nextSibling());
|
return nextSibling();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,13 @@
|
|||||||
|
|
||||||
using namespace ArduinoJson::Parser;
|
using namespace ArduinoJson::Parser;
|
||||||
|
|
||||||
JsonValue JsonParserBase::parse(char* json)
|
JsonToken JsonParserBase::parseToken(char* json)
|
||||||
{
|
{
|
||||||
jsmn_parser parser;
|
jsmn_parser parser;
|
||||||
jsmn_init(&parser);
|
jsmn_init(&parser);
|
||||||
|
|
||||||
if (JSMN_SUCCESS != jsmn_parse(&parser, json, tokens, maxTokens))
|
if (JSMN_SUCCESS != jsmn_parse(&parser, json, tokens, maxTokens))
|
||||||
return JsonValue::null();
|
return JsonToken::null();
|
||||||
|
|
||||||
return JsonToken(json, tokens);
|
return JsonToken(json, tokens);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,10 @@ namespace ArduinoJson
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonValue parse(char* json);
|
JsonValue parse(char* json)
|
||||||
|
{
|
||||||
|
return parseToken(json);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse the JSON string and return a array.
|
* Parse the JSON string and return a array.
|
||||||
@ -31,7 +34,7 @@ namespace ArduinoJson
|
|||||||
*/
|
*/
|
||||||
DEPRECATED JsonArray parseArray(char* json)
|
DEPRECATED JsonArray parseArray(char* json)
|
||||||
{
|
{
|
||||||
return parse(json);
|
return parseToken(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -42,12 +45,14 @@ namespace ArduinoJson
|
|||||||
*/
|
*/
|
||||||
DEPRECATED JsonObject parseHashTable(char* json)
|
DEPRECATED JsonObject parseHashTable(char* json)
|
||||||
{
|
{
|
||||||
return parse(json);
|
return parseToken(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
jsmntok_t* tokens;
|
jsmntok_t* tokens;
|
||||||
int maxTokens;
|
int maxTokens;
|
||||||
|
|
||||||
|
JsonToken parseToken(char* json);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,16 +33,14 @@ namespace ArduinoJson
|
|||||||
return json + token->start;
|
return json + token->start;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: should be protected
|
|
||||||
JsonToken firstChild() const
|
JsonToken firstChild() const
|
||||||
{
|
{
|
||||||
return JsonToken(json, token + 1);
|
return JsonToken(json, token + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: should be protected
|
|
||||||
JsonToken nextSibling() const;
|
JsonToken nextSibling() const;
|
||||||
|
|
||||||
bool operator!= (const JsonToken& other)
|
bool operator!= (const JsonToken& other) const
|
||||||
{
|
{
|
||||||
return token != other.token;
|
return token != other.token;
|
||||||
}
|
}
|
||||||
@ -52,8 +50,6 @@ namespace ArduinoJson
|
|||||||
return JsonToken(0, 0);
|
return JsonToken(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
bool isValid()
|
bool isValid()
|
||||||
{
|
{
|
||||||
return token != 0;
|
return token != 0;
|
||||||
|
@ -24,10 +24,15 @@ namespace ArduinoJson
|
|||||||
class JsonArray;
|
class JsonArray;
|
||||||
class JsonObject;
|
class JsonObject;
|
||||||
|
|
||||||
class JsonValue : public JsonToken
|
class JsonValue : protected JsonToken
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
JsonValue()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
JsonValue(JsonToken token)
|
JsonValue(JsonToken token)
|
||||||
: JsonToken(token)
|
: JsonToken(token)
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,8 @@ namespace JsonParserTests
|
|||||||
long expected [] = { 1, 2, 3 };
|
long expected [] = { 1, 2, 3 };
|
||||||
JsonParser<4> parser;
|
JsonParser<4> parser;
|
||||||
|
|
||||||
JsonArray a = parser.parse(json);
|
JsonValue v = parser.parse(json);
|
||||||
|
JsonArray a = (ArduinoJson::Parser::JsonArray)v;
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user