Added comments

This commit is contained in:
Benoit Blanchon
2014-07-21 15:20:02 +02:00
parent d3d0da2d7f
commit df72419f09
3 changed files with 36 additions and 20 deletions

View File

@ -14,86 +14,86 @@ namespace ArduinoJson
{ {
class JsonObject; class JsonObject;
// A JSON array. // A JSON array
class JsonArray : JsonValue class JsonArray : JsonValue
{ {
public: public:
// Create an invalid array. // Create an invalid array
JsonArray() JsonArray()
{ {
} }
// Convert a JsonValue into a JsonArray. // Convert a JsonValue into a JsonArray
JsonArray(JsonValue value) JsonArray(JsonValue value)
: JsonValue(value) : JsonValue(value)
{ {
} }
// Tell if the array is valid. // Tell if the array is valid
bool success() bool success()
{ {
return isArray(); return isArray();
} }
// Get the JsonValue at specified index. // Get the JsonValue at specified index
JsonValue operator[](int index) JsonValue operator[](int index)
{ {
return JsonValue::operator[](index); return JsonValue::operator[](index);
} }
// Get the size of the array. // Get the size of the array
int size() int size()
{ {
return isArray() ? childrenCount() : 0; return isArray() ? childrenCount() : 0;
} }
// Get an iterator pointing to the beginning of the array. // Get an iterator pointing to the beginning of the array
JsonArrayIterator begin() JsonArrayIterator begin()
{ {
return isArray() ? firstChild() : null(); return isArray() ? firstChild() : null();
} }
// Gets an iterator pointing to the end of the array. // Gets an iterator pointing to the end of the array
JsonArrayIterator end() JsonArrayIterator end()
{ {
return isArray() ? nextSibling() : null(); return isArray() ? nextSibling() : null();
} }
// Obsolete. Use size() instead. // Obsolete: Use size() instead
DEPRECATED int getLength() DEPRECATED int getLength()
{ {
return size(); return size();
} }
// Obsolete. Use operator[] instead. // Obsolete: Use operator[] instead
DEPRECATED JsonArray getArray(int index) DEPRECATED JsonArray getArray(int index)
{ {
return operator[](index); return operator[](index);
} }
// Obsolete. Use operator[] instead. // Obsolete: Use operator[] instead
DEPRECATED bool getBool(int index) DEPRECATED bool getBool(int index)
{ {
return operator[](index); return operator[](index);
} }
// Obsolete. Use operator[] instead. // Obsolete: Use operator[] instead
DEPRECATED double getDouble(int index) DEPRECATED double getDouble(int index)
{ {
return operator[](index); return operator[](index);
} }
// Obsolete. Use operator[] instead. // Obsolete: Use operator[] instead
DEPRECATED JsonObject getHashTable(int index); DEPRECATED JsonObject getHashTable(int index);
// Obsolete. Use operator[] instead. // Obsolete: Use operator[] instead
DEPRECATED long getLong(int index) DEPRECATED long getLong(int index)
{ {
return operator[](index); return operator[](index);
} }
// Obsolete. Use operator[] instead. // Obsolete: Use operator[] instead
DEPRECATED char* getString(int index) DEPRECATED char* getString(int index)
{ {
return operator[](index); return operator[](index);

View File

@ -12,31 +12,31 @@ namespace ArduinoJson
{ {
namespace Parser namespace Parser
{ {
// An iterator for JsonArray. // An iterator for JsonArray
class JsonArrayIterator : JsonToken class JsonArrayIterator : JsonToken
{ {
public: public:
// Create an iterator pointing at the specified JsonToken. // Create an iterator pointing at the specified JsonToken
JsonArrayIterator(JsonToken token) JsonArrayIterator(JsonToken token)
: JsonToken(token) : JsonToken(token)
{ {
} }
// Move iterator forward. // Move iterator forward
void operator++() void operator++()
{ {
*this = JsonArrayIterator(nextSibling()); *this = JsonArrayIterator(nextSibling());
} }
// Get the value pointed by the iterator. // Get the value pointed by the iterator
JsonValue operator*() const JsonValue operator*() const
{ {
return JsonValue(*this); return JsonValue(*this);
} }
// Test iterator equality. // Test iterator equality
bool operator!= (const JsonArrayIterator& other) const bool operator!= (const JsonArrayIterator& other) const
{ {
return JsonToken::operator!=(other); return JsonToken::operator!=(other);

View File

@ -14,73 +14,89 @@ namespace ArduinoJson
{ {
class JsonArray; class JsonArray;
// A JSON Object (ie hash-table/dictionary)
class JsonObject : JsonValue class JsonObject : JsonValue
{ {
public: public:
// Create an invalid JsonObject
JsonObject() JsonObject()
{ {
} }
// Convert a JsonValue into a JsonObject
JsonObject(JsonValue value) JsonObject(JsonValue value)
: JsonValue(value) : JsonValue(value)
{ {
} }
// Tell if the object is valid
bool success() bool success()
{ {
return isObject(); return isObject();
} }
// Get the value associated with the specified key.
JsonValue operator[](const char* key) JsonValue operator[](const char* key)
{ {
return JsonValue::operator[](key); return JsonValue::operator[](key);
} }
// Tell if the specified key exists in the object.
bool containsKey(const char* key) bool containsKey(const char* key)
{ {
return operator[](key).success(); return operator[](key).success();
} }
// Get an iterator pointing at the beginning of the object
JsonObjectIterator begin() JsonObjectIterator begin()
{ {
return isObject() ? firstChild() : null(); return isObject() ? firstChild() : null();
} }
// Get an iterator pointing at the end of the object
JsonObjectIterator end() JsonObjectIterator end()
{ {
return isObject() ? nextSibling() : null(); return isObject() ? nextSibling() : null();
} }
// Obsolete: Use operator[] instead
DEPRECATED JsonArray getArray(const char* key); DEPRECATED JsonArray getArray(const char* key);
// Obsolete: Use operator[] instead
DEPRECATED bool getBool(const char* key) DEPRECATED bool getBool(const char* key)
{ {
return operator[](key); return operator[](key);
} }
// Obsolete: Use operator[] instead
DEPRECATED double getDouble(const char* key) DEPRECATED double getDouble(const char* key)
{ {
return operator[](key); return operator[](key);
} }
// Obsolete: Use operator[] instead
DEPRECATED JsonObject getHashTable(const char* key) DEPRECATED JsonObject getHashTable(const char* key)
{ {
return operator[](key); return operator[](key);
} }
// Obsolete: Use operator[] instead
DEPRECATED long getLong(const char* key) DEPRECATED long getLong(const char* key)
{ {
return operator[](key); return operator[](key);
} }
// Obsolete: Use operator[] instead
DEPRECATED char* getString(const char* key) DEPRECATED char* getString(const char* key)
{ {
return operator[](key); return operator[](key);
} }
}; };
// Obsolete: Use JsonObject instead
typedef JsonObject JsonHashTable; typedef JsonObject JsonHashTable;
} }
} }