Skip to content

cast override suggestion #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/json/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 36 additions & 0 deletions src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down