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