Skip to content

Commit 1a30498

Browse files
define cast overrides
1 parent 3515db1 commit 1a30498

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

include/json/value.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ Json::Value obj_value(Json::objectValue); // {}
273273
double asDouble() const;
274274
bool asBool() const;
275275

276+
operator const char*() const;
277+
operator std::string() const;
278+
operator Int() const;
279+
operator UInt() const;
280+
operator Int64() const;
281+
operator UInt64() const;
282+
operator float() const;
283+
operator double() const;
284+
operator bool() const;
285+
276286
bool isNull() const;
277287
bool isBool() const;
278288
bool isInt() const;

src/lib_json/json_value.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,42 @@ bool Value::asBool() const {
795795
JSON_FAIL_MESSAGE("Value is not convertible to bool.");
796796
}
797797

798+
Value::operator const char*() const {
799+
return Value::asCString();
800+
}
801+
802+
Value::operator std::string() const {
803+
return Value::asString();
804+
}
805+
806+
Value::operator Int() const {
807+
return Value::asInt();
808+
}
809+
810+
Value::operator UInt() const {
811+
return Value::asUInt();
812+
}
813+
814+
Value::operator Int64() const {
815+
return Value::asInt64();
816+
}
817+
818+
Value::operator UInt64() const {
819+
return Value::asUInt64();
820+
}
821+
822+
Value::operator float() const {
823+
return Value::asFloat();
824+
}
825+
826+
Value::operator double() const {
827+
return Value::asDouble();
828+
}
829+
830+
Value::operator bool() const {
831+
return Value::asBool();
832+
}
833+
798834
bool Value::isConvertibleTo(ValueType other) const {
799835
switch (other) {
800836
case nullValue:

0 commit comments

Comments
 (0)