mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58:09 +08:00
feat: enable to change region of value
To allow the following toml file, we need to replace the region after the more precise region is found. ```toml [a.b.c] d = 42 [a] e = 2.71 ``` If the precise region (here, [a]) is found, the region of `a` should be `[a]`, not `[a.b.c]`. After `[a]` is defined, toml does not allow to write `[a]` twice. To check it, we need to replace the region of values to the precise one.
This commit is contained in:
@@ -21,6 +21,8 @@ namespace detail
|
|||||||
{
|
{
|
||||||
// to show error messages. not recommended for users.
|
// to show error messages. not recommended for users.
|
||||||
region_base const& get_region(const value&);
|
region_base const& get_region(const value&);
|
||||||
|
template<typename Region>
|
||||||
|
void change_region(value&, Region&&);
|
||||||
}// detail
|
}// detail
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -560,6 +562,9 @@ class value
|
|||||||
// for error messages
|
// for error messages
|
||||||
friend region_base const& detail::get_region(const value&);
|
friend region_base const& detail::get_region(const value&);
|
||||||
|
|
||||||
|
template<typename Region>
|
||||||
|
friend void detail::change_region(value&, Region&&);
|
||||||
|
|
||||||
template<value_t T>
|
template<value_t T>
|
||||||
struct switch_cast;
|
struct switch_cast;
|
||||||
|
|
||||||
@@ -594,6 +599,20 @@ inline region_base const& get_region(const value& v)
|
|||||||
{
|
{
|
||||||
return *(v.region_info_);
|
return *(v.region_info_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Region>
|
||||||
|
void change_region(value& v, Region&& reg)
|
||||||
|
{
|
||||||
|
using region_type = typename std::remove_reference<
|
||||||
|
typename std::remove_cv<Region>::type
|
||||||
|
>::type;
|
||||||
|
|
||||||
|
std::shared_ptr<region_base> new_reg =
|
||||||
|
std::make_shared<region_type>(std::forward<region_type>(reg));
|
||||||
|
v.region_info_ = new_reg;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
}// detail
|
}// detail
|
||||||
|
|
||||||
template<> struct value::switch_cast<value_t::Boolean>
|
template<> struct value::switch_cast<value_t::Boolean>
|
||||||
|
Reference in New Issue
Block a user