move-only: Move UniValue::getInt definition to keep class with definitions only

Can be reviewed with the git options

--color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
This commit is contained in:
MacroFake 2022-07-14 18:03:22 +02:00
parent 4e2929e987
commit fafab147e7
No known key found for this signature in database
GPG key ID: CE2B75697E69A548

View file

@ -116,19 +116,7 @@ public:
const std::vector<std::string>& getKeys() const;
const std::vector<UniValue>& getValues() const;
template <typename Int>
auto getInt() const
{
static_assert(std::is_integral<Int>::value);
if (typ != VNUM) {
throw std::runtime_error("JSON value is not an integer as expected");
}
Int result;
const auto [first_nonmatching, error_condition] = std::from_chars(val.data(), val.data() + val.size(), result);
if (first_nonmatching != val.data() + val.size() || error_condition != std::errc{}) {
throw std::runtime_error("JSON integer out of range");
}
return result;
}
Int getInt() const;
bool get_bool() const;
const std::string& get_str() const;
double get_real() const;
@ -146,6 +134,21 @@ void UniValue::push_backV(It first, It last)
values.insert(values.end(), first, last);
}
template <typename Int>
Int UniValue::getInt() const
{
static_assert(std::is_integral<Int>::value);
if (typ != VNUM) {
throw std::runtime_error("JSON value is not an integer as expected");
}
Int result;
const auto [first_nonmatching, error_condition] = std::from_chars(val.data(), val.data() + val.size(), result);
if (first_nonmatching != val.data() + val.size() || error_condition != std::errc{}) {
throw std::runtime_error("JSON integer out of range");
}
return result;
}
enum jtokentype {
JTOK_ERR = -1,
JTOK_NONE = 0, // eof