Added missing JSON "operator bool()" and size() methods.

This commit is contained in:
Thulinma 2012-07-12 01:03:40 +02:00
parent 49fe8afb84
commit b9a75a320f
2 changed files with 18 additions and 3 deletions

View file

@ -1,3 +1 @@
All code was written by DDVTECH employees specifically for this project, with the exception of:
* tinythread++ library taken verbatim from: http://tinythread.sourceforge.net
All code so far was written by DDVTECH employees.

View file

@ -283,6 +283,18 @@ JSON::Value::operator std::string(){
}
}
/// Automatic conversion to bool.
/// Returns true if there is anything meaningful stored into this value.
JSON::Value::operator bool(){
if (myType == STRING){return strVal == "";}
if (myType == INTEGER){return intVal == 0;}
if (myType == BOOL){return intVal == 0;}
if (myType == OBJECT){return size() > 0;}
if (myType == ARRAY){return size() > 0;}
if (myType == EMPTY){return false;}
return false;//unimplemented? should never happen...
}
/// Retrieves or sets the JSON::Value at this position in the object.
/// Converts destructively to object if not already an object.
JSON::Value & JSON::Value::operator[](const std::string i){
@ -433,6 +445,11 @@ JSON::ArrIter JSON::Value::ArrEnd(){
return arrVal.end();
}
/// Returns the total of the objects and array size combined.
unsigned int JSON::Value::size(){
return objVal.size() + arrVal.size();
}
/// Completely clears the contents of this value,
/// changing its type to NULL in the process.
void JSON::Value::null(){