From 1a3049846689e9844a5721dbc7b331a275741992 Mon Sep 17 00:00:00 2001 From: Ryo Miyajima Date: Thu, 28 Aug 2014 09:53:23 +0900 Subject: [PATCH] define cast overrides --- include/json/value.h | 10 ++++++++++ src/lib_json/json_value.cpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/include/json/value.h b/include/json/value.h index 1ad006fd4..34ea4cca2 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -273,6 +273,16 @@ Json::Value obj_value(Json::objectValue); // {} double asDouble() const; bool asBool() const; + operator const char*() const; + operator std::string() const; + operator Int() const; + operator UInt() const; + operator Int64() const; + operator UInt64() const; + operator float() const; + operator double() const; + operator bool() const; + bool isNull() const; bool isBool() const; bool isInt() const; diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 637016f3b..26b68b171 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -795,6 +795,42 @@ bool Value::asBool() const { JSON_FAIL_MESSAGE("Value is not convertible to bool."); } +Value::operator const char*() const { + return Value::asCString(); +} + +Value::operator std::string() const { + return Value::asString(); +} + +Value::operator Int() const { + return Value::asInt(); +} + +Value::operator UInt() const { + return Value::asUInt(); +} + +Value::operator Int64() const { + return Value::asInt64(); +} + +Value::operator UInt64() const { + return Value::asUInt64(); +} + +Value::operator float() const { + return Value::asFloat(); +} + +Value::operator double() const { + return Value::asDouble(); +} + +Value::operator bool() const { + return Value::asBool(); +} + bool Value::isConvertibleTo(ValueType other) const { switch (other) { case nullValue: