Added handy converter functions to JSON.

This commit is contained in:
Thulinma 2012-07-20 17:48:57 +02:00
parent a36ce260ac
commit 5562bea8a0
2 changed files with 17 additions and 0 deletions

View file

@ -295,6 +295,20 @@ JSON::Value::operator bool(){
return false;//unimplemented? should never happen...
}
/// Explicit conversion to std::string.
const std::string JSON::Value::asString(){
return (std::string)*this;
}
/// Explicit conversion to long long int.
const long long int JSON::Value::asInt(){
return (long long int)*this;
}
/// Explicit conversion to bool.
const bool JSON::Value::asBool(){
return (bool)*this;
}
/// 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){

View file

@ -51,6 +51,9 @@ namespace JSON{
operator long long int();
operator std::string();
operator bool();
const std::string asString();
const long long int asInt();
const bool asBool();
//array operator for maps and arrays
Value & operator[](const std::string i);
Value & operator[](const char * i);