Added handy converter functions to JSON.
This commit is contained in:
parent
a36ce260ac
commit
5562bea8a0
2 changed files with 17 additions and 0 deletions
14
lib/json.cpp
14
lib/json.cpp
|
@ -295,6 +295,20 @@ JSON::Value::operator bool(){
|
||||||
return false;//unimplemented? should never happen...
|
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.
|
/// Retrieves or sets the JSON::Value at this position in the object.
|
||||||
/// Converts destructively to object if not already an object.
|
/// Converts destructively to object if not already an object.
|
||||||
JSON::Value & JSON::Value::operator[](const std::string i){
|
JSON::Value & JSON::Value::operator[](const std::string i){
|
||||||
|
|
|
@ -51,6 +51,9 @@ namespace JSON{
|
||||||
operator long long int();
|
operator long long int();
|
||||||
operator std::string();
|
operator std::string();
|
||||||
operator bool();
|
operator bool();
|
||||||
|
const std::string asString();
|
||||||
|
const long long int asInt();
|
||||||
|
const bool asBool();
|
||||||
//array operator for maps and arrays
|
//array operator for maps and arrays
|
||||||
Value & operator[](const std::string i);
|
Value & operator[](const std::string i);
|
||||||
Value & operator[](const char * i);
|
Value & operator[](const char * i);
|
||||||
|
|
Loading…
Add table
Reference in a new issue