🔀 Merge branch 'master' into recursive-find

This commit is contained in:
ToruNiina 2019-06-07 19:02:20 +09:00
commit 31debcb8aa
4 changed files with 88 additions and 59 deletions

View File

@ -576,20 +576,27 @@ if(v.is_integer())
The complete list of the functions is below.
```cpp
const toml::value v(/*...*/);
v.is_boolean();
v.is_integer();
v.is_float();
v.is_string();
v.is_offset_datetime();
v.is_local_datetime();
v.is_local_date();
v.is_local_time();
v.is_array();
v.is_table();
v.is_uninitialized();
namespace toml {
class value {
// ...
bool is_boolean() const noexcept;
bool is_integer() const noexcept;
bool is_floating() const noexcept;
bool is_string() const noexcept;
bool is_offset_datetime() const noexcept;
bool is_local_datetime() const noexcept;
bool is_local_date() const noexcept;
bool is_local_time() const noexcept;
bool is_array() const noexcept;
bool is_table() const noexcept;
bool is_uninitialized() const noexcept;
// ...
};
} // toml
```
__NOTE__: `is_float` is marked as deprecated since v2.4.0 to make the function names consistent with snake case typenames. Please use `is_floating` instead.
Also, you can get `enum class` value from `toml::value`.
```cpp
@ -629,20 +636,33 @@ if(v.is_integer() && v.as_integer() == 42)
The complete list of the functions is below.
```cpp
const toml::value v(/*...*/);
v.as_boolean();
v.as_integer();
v.as_float();
v.as_string();
v.as_offset_datetime();
v.as_local_datetime();
v.as_local_date();
v.as_local_time();
v.as_array();
v.as_table();
v.as_uninitialized();
namespace toml {
class value {
// ...
const boolean& as_boolean() const& noexcept;
const integer& as_integer() const& noexcept;
const floating& as_floating() const& noexcept;
const string& as_string() const& noexcept;
const offset_datetime& as_offset_datetime() const& noexcept;
const local_datetime& as_local_datetime() const& noexcept;
const local_date& as_local_date() const& noexcept;
const local_time& as_local_time() const& noexcept;
const array& as_array() const& noexcept;
const table& as_table() const& noexcept;
// --------------------------------------------------------
// non-const version
boolean& as_boolean() & noexcept;
// ditto...
// --------------------------------------------------------
// rvalue version
boolean&& as_boolean() && noexcept;
// ditto...
};
} // toml
```
__NOTE__: `as_float` is marked as deprecated since v2.4.0 to make the function names consistent with snake case typenames. Please use `as_floating` instead.
## Visiting a toml::value
toml11 provides `toml::visit` to apply a function to `toml::value` in the

View File

@ -78,8 +78,8 @@ BOOST_AUTO_TEST_CASE(test_value_as_literal)
const toml::value v1 = u8"3.1415"_toml;
const toml::value v2 = u8"6.02e+23"_toml;
BOOST_CHECK(v1.is_float());
BOOST_CHECK(v2.is_float());
BOOST_CHECK(v1.is_floating());
BOOST_CHECK(v2.is_floating());
BOOST_CHECK_CLOSE(toml::get<double>(v1), 3.1415, 0.00001);
BOOST_CHECK_CLOSE(toml::get<double>(v2), 6.02e23, 0.0001);
}

View File

@ -96,12 +96,12 @@ BOOST_AUTO_TEST_CASE(test_value_boolean)
BOOST_CHECK(v1.is<toml::Integer>());
BOOST_CHECK(v2.is<toml::Float>());
BOOST_CHECK(v1.is_integer());
BOOST_CHECK(v2.is_float());
BOOST_CHECK(v2.is_floating());
BOOST_CHECK_EQUAL(v1.cast<toml::value_t::Integer>(), 42);
BOOST_CHECK_EQUAL(v2.cast<toml::value_t::Float>(), 3.14);
BOOST_CHECK_EQUAL(v1.as_integer(), 42);
BOOST_CHECK_EQUAL(v2.as_float(), 3.14);
BOOST_CHECK_EQUAL(v2.as_floating(), 3.14);
}
BOOST_AUTO_TEST_CASE(test_value_integer)
@ -205,13 +205,13 @@ BOOST_AUTO_TEST_CASE(test_value_float)
BOOST_CHECK(v2.is(toml::value_t::Float));
BOOST_CHECK(v1.is<toml::Float>());
BOOST_CHECK(v2.is<toml::Float>());
BOOST_CHECK(v1.is_float());
BOOST_CHECK(v2.is_float());
BOOST_CHECK(v1.is_floating());
BOOST_CHECK(v2.is_floating());
BOOST_CHECK_EQUAL (v1.cast<toml::value_t::Float>(), 3.14);
BOOST_CHECK_CLOSE_FRACTION(v2.cast<toml::value_t::Float>(), 3.14, 1e-2);
BOOST_CHECK_EQUAL (v1.as_float(), 3.14);
BOOST_CHECK_CLOSE_FRACTION(v2.as_float(), 3.14, 1e-2);
BOOST_CHECK_EQUAL (v1.as_floating(), 3.14);
BOOST_CHECK_CLOSE_FRACTION(v2.as_floating(), 3.14, 1e-2);
v1 = 2.718f;
v2 = 2.718;
@ -222,13 +222,13 @@ BOOST_AUTO_TEST_CASE(test_value_float)
BOOST_CHECK(v2.is(toml::value_t::Float));
BOOST_CHECK(v1.is<toml::Float>());
BOOST_CHECK(v2.is<toml::Float>());
BOOST_CHECK(v1.is_float());
BOOST_CHECK(v2.is_float());
BOOST_CHECK(v1.is_floating());
BOOST_CHECK(v2.is_floating());
BOOST_CHECK_CLOSE_FRACTION(v1.cast<toml::value_t::Float>(), 2.718, 1e-3);
BOOST_CHECK_EQUAL (v2.cast<toml::value_t::Float>(), 2.718);
BOOST_CHECK_CLOSE_FRACTION(v1.as_float(), 2.718, 1e-3);
BOOST_CHECK_EQUAL (v2.as_float(), 2.718);
BOOST_CHECK_CLOSE_FRACTION(v1.as_floating(), 2.718, 1e-3);
BOOST_CHECK_EQUAL (v2.as_floating(), 2.718);
toml::value v3(v1);
toml::value v4(v2);
@ -241,13 +241,13 @@ BOOST_AUTO_TEST_CASE(test_value_float)
BOOST_CHECK(v4.is(toml::value_t::Float));
BOOST_CHECK(v3.is<toml::Float>());
BOOST_CHECK(v4.is<toml::Float>());
BOOST_CHECK(v3.is_float());
BOOST_CHECK(v4.is_float());
BOOST_CHECK(v3.is_floating());
BOOST_CHECK(v4.is_floating());
BOOST_CHECK_CLOSE_FRACTION(v3.cast<toml::value_t::Float>(), 2.718, 1e-3);
BOOST_CHECK_EQUAL (v4.cast<toml::value_t::Float>(), 2.718);
BOOST_CHECK_CLOSE_FRACTION(v3.as_float(), 2.718, 1e-3);
BOOST_CHECK_EQUAL (v4.as_float(), 2.718);
BOOST_CHECK_CLOSE_FRACTION(v3.as_floating(), 2.718, 1e-3);
BOOST_CHECK_EQUAL (v4.as_floating(), 2.718);
toml::value v5(std::move(v1));
toml::value v6(std::move(v2));
@ -258,13 +258,13 @@ BOOST_AUTO_TEST_CASE(test_value_float)
BOOST_CHECK(v6.is(toml::value_t::Float));
BOOST_CHECK(v5.is<toml::Float>());
BOOST_CHECK(v6.is<toml::Float>());
BOOST_CHECK(v5.is_float());
BOOST_CHECK(v6.is_float());
BOOST_CHECK(v5.is_floating());
BOOST_CHECK(v6.is_floating());
BOOST_CHECK_CLOSE_FRACTION(v5.cast<toml::value_t::Float>(), 2.718, 1e-3);
BOOST_CHECK_EQUAL (v6.cast<toml::value_t::Float>(), 2.718);
BOOST_CHECK_CLOSE_FRACTION(v5.as_float(), 2.718, 1e-3);
BOOST_CHECK_EQUAL (v6.as_float(), 2.718);
BOOST_CHECK_CLOSE_FRACTION(v5.as_floating(), 2.718, 1e-3);
BOOST_CHECK_EQUAL (v6.as_floating(), 2.718);
v1 = true;
v2 = false;
@ -792,7 +792,7 @@ BOOST_AUTO_TEST_CASE(test_value_table)
BOOST_CHECK_EQUAL(v1.cast<toml::value_t::Table>().at("bar").cast<toml::value_t::Float>(), 3.14);
BOOST_CHECK_EQUAL(v1.cast<toml::value_t::Table>().at("baz").cast<toml::value_t::String>().str, "qux");
BOOST_CHECK_EQUAL(v1.as_table().at("foo").as_integer(), 42);
BOOST_CHECK_EQUAL(v1.as_table().at("bar").as_float(), 3.14);
BOOST_CHECK_EQUAL(v1.as_table().at("bar").as_floating(), 3.14);
BOOST_CHECK_EQUAL(v1.as_table().at("baz").as_string().str, "qux");
@ -806,7 +806,7 @@ BOOST_AUTO_TEST_CASE(test_value_table)
BOOST_CHECK_EQUAL(v1.cast<toml::value_t::Table>().at("foo").cast<toml::value_t::Float>(), 2.71);
BOOST_CHECK_EQUAL(v1.cast<toml::value_t::Table>().at("bar").cast<toml::value_t::Integer>(), 54);
BOOST_CHECK_EQUAL(v1.cast<toml::value_t::Table>().at("baz").cast<toml::value_t::String>().str, "quux");
BOOST_CHECK_EQUAL(v1.as_table().at("foo").as_float(), 2.71);
BOOST_CHECK_EQUAL(v1.as_table().at("foo").as_floating(), 2.71);
BOOST_CHECK_EQUAL(v1.as_table().at("bar").as_integer(), 54);
BOOST_CHECK_EQUAL(v1.as_table().at("baz").as_string().str, "quux");
@ -822,7 +822,7 @@ BOOST_AUTO_TEST_CASE(test_value_table)
BOOST_CHECK_EQUAL(v3.cast<toml::value_t::Table>().at("foo").cast<toml::value_t::Float>(), 2.71);
BOOST_CHECK_EQUAL(v3.cast<toml::value_t::Table>().at("bar").cast<toml::value_t::Integer>(), 54);
BOOST_CHECK_EQUAL(v3.cast<toml::value_t::Table>().at("baz").cast<toml::value_t::String>().str, "quux");
BOOST_CHECK_EQUAL(v3.as_table().at("foo").as_float(), 2.71);
BOOST_CHECK_EQUAL(v3.as_table().at("foo").as_floating(), 2.71);
BOOST_CHECK_EQUAL(v3.as_table().at("bar").as_integer(), 54);
BOOST_CHECK_EQUAL(v3.as_table().at("baz").as_string().str, "quux");

View File

@ -616,7 +616,7 @@ class value
bool is_uninitialized() const noexcept {return this->is(value_t::Empty );}
bool is_boolean() const noexcept {return this->is(value_t::Boolean );}
bool is_integer() const noexcept {return this->is(value_t::Integer );}
bool is_float() const noexcept {return this->is(value_t::Float );}
bool is_floating() const noexcept {return this->is(value_t::Float );}
bool is_string() const noexcept {return this->is(value_t::String );}
bool is_offset_datetime() const noexcept {return this->is(value_t::OffsetDatetime);}
bool is_local_datetime() const noexcept {return this->is(value_t::LocalDatetime );}
@ -636,7 +636,7 @@ class value
boolean const& as_boolean() const& noexcept {return this->boolean_;}
integer const& as_integer() const& noexcept {return this->integer_;}
floating const& as_float() const& noexcept {return this->floating_;}
floating const& as_floating() const& noexcept {return this->floating_;}
string const& as_string() const& noexcept {return this->string_;}
offset_datetime const& as_offset_datetime() const& noexcept {return this->offset_datetime_;}
local_datetime const& as_local_datetime() const& noexcept {return this->local_datetime_;}
@ -647,7 +647,7 @@ class value
boolean & as_boolean() & noexcept {return this->boolean_;}
integer & as_integer() & noexcept {return this->integer_;}
floating & as_float() & noexcept {return this->floating_;}
floating & as_floating() & noexcept {return this->floating_;}
string & as_string() & noexcept {return this->string_;}
offset_datetime& as_offset_datetime() & noexcept {return this->offset_datetime_;}
local_datetime & as_local_datetime() & noexcept {return this->local_datetime_;}
@ -658,7 +658,7 @@ class value
boolean && as_boolean() && noexcept {return std::move(this->boolean_);}
integer && as_integer() && noexcept {return std::move(this->integer_);}
floating && as_float() && noexcept {return std::move(this->floating_);}
floating && as_floating() && noexcept {return std::move(this->floating_);}
string && as_string() && noexcept {return std::move(this->string_);}
offset_datetime&& as_offset_datetime() && noexcept {return std::move(this->offset_datetime_);}
local_datetime && as_local_datetime() && noexcept {return std::move(this->local_datetime_);}
@ -667,6 +667,15 @@ class value
array && as_array() && noexcept {return std::move(this->array_.value());}
table && as_table() && noexcept {return std::move(this->table_.value());}
TOML11_MARK_AS_DEPRECATED("use toml::value::is_floating() instead.")
bool is_float() const noexcept {return this->is(value_t::Float);}
TOML11_MARK_AS_DEPRECATED("use toml::value::is_floating() instead.")
floating& as_float() & noexcept {return this->floating_;}
TOML11_MARK_AS_DEPRECATED("use toml::value::is_floating() instead.")
floating&& as_float() && noexcept {return std::move(this->floating_);}
TOML11_MARK_AS_DEPRECATED("use toml::value::is_floating() instead.")
floating const& as_float() const& noexcept {return this->floating_;}
std::string comment() const
{
return this->region_info_->comment();
@ -773,9 +782,9 @@ struct switch_cast<value_t::Integer>
template<>
struct switch_cast<value_t::Float>
{
static ::toml::floating& invoke(value& v) {return v.as_float();}
static ::toml::floating const& invoke(value const& v) {return v.as_float();}
static ::toml::floating&& invoke(value&& v) {return std::move(v).as_float();}
static ::toml::floating& invoke(value& v) {return v.as_floating();}
static ::toml::floating const& invoke(value const& v) {return v.as_floating();}
static ::toml::floating&& invoke(value&& v) {return std::move(v).as_floating();}
};
template<>
struct switch_cast<value_t::String>
@ -871,7 +880,7 @@ inline bool operator==(const toml::value& lhs, const toml::value& rhs)
}
case value_t::Float :
{
return lhs.as_float() == rhs.as_float();
return lhs.as_floating() == rhs.as_floating();
}
case value_t::String :
{
@ -921,7 +930,7 @@ inline bool operator<(const toml::value& lhs, const toml::value& rhs)
}
case value_t::Float :
{
return lhs.as_float() < rhs.as_float();
return lhs.as_floating() < rhs.as_floating();
}
case value_t::String :
{
@ -1018,7 +1027,7 @@ visit(Visitor&& visitor, const toml::value& v)
{
case value_t::Boolean : {return visitor(v.as_boolean ());}
case value_t::Integer : {return visitor(v.as_integer ());}
case value_t::Float : {return visitor(v.as_float ());}
case value_t::Float : {return visitor(v.as_floating ());}
case value_t::String : {return visitor(v.as_string ());}
case value_t::OffsetDatetime: {return visitor(v.as_offset_datetime());}
case value_t::LocalDatetime : {return visitor(v.as_local_datetime ());}
@ -1042,7 +1051,7 @@ visit(Visitor&& visitor, toml::value& v)
{
case value_t::Boolean : {return visitor(v.as_boolean ());}
case value_t::Integer : {return visitor(v.as_integer ());}
case value_t::Float : {return visitor(v.as_float ());}
case value_t::Float : {return visitor(v.as_floating ());}
case value_t::String : {return visitor(v.as_string ());}
case value_t::OffsetDatetime: {return visitor(v.as_offset_datetime());}
case value_t::LocalDatetime : {return visitor(v.as_local_datetime ());}
@ -1066,7 +1075,7 @@ visit(Visitor&& visitor, toml::value&& v)
{
case value_t::Boolean : {return visitor(std::move(v.as_boolean ()));}
case value_t::Integer : {return visitor(std::move(v.as_integer ()));}
case value_t::Float : {return visitor(std::move(v.as_float ()));}
case value_t::Float : {return visitor(std::move(v.as_floating ()));}
case value_t::String : {return visitor(std::move(v.as_string ()));}
case value_t::OffsetDatetime: {return visitor(std::move(v.as_offset_datetime()));}
case value_t::LocalDatetime : {return visitor(std::move(v.as_local_datetime ()));}