mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 19:10:11 +08:00
feat: add accessed() flag
This commit is contained in:
@@ -17,6 +17,10 @@
|
||||
#include <string_view>
|
||||
#endif
|
||||
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
#include <atomic>
|
||||
#endif
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace toml
|
||||
@@ -86,6 +90,9 @@ class basic_value
|
||||
|
||||
basic_value() noexcept
|
||||
: type_(value_t::empty), empty_('\0'), region_{}, comments_{}
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
~basic_value() noexcept {this->cleanup();}
|
||||
|
||||
@@ -93,6 +100,9 @@ class basic_value
|
||||
|
||||
basic_value(const basic_value& v)
|
||||
: type_(v.type_), region_(v.region_), comments_(v.comments_)
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{v.accessed()}
|
||||
#endif
|
||||
{
|
||||
switch(this->type_)
|
||||
{
|
||||
@@ -112,6 +122,9 @@ class basic_value
|
||||
basic_value(basic_value&& v)
|
||||
: type_(v.type()), region_(std::move(v.region_)),
|
||||
comments_(std::move(v.comments_))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{v.accessed()}
|
||||
#endif
|
||||
{
|
||||
switch(this->type_)
|
||||
{
|
||||
@@ -137,6 +150,9 @@ class basic_value
|
||||
this->type_ = v.type_;
|
||||
this->region_ = v.region_;
|
||||
this->comments_ = v.comments_;
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = v.accessed();
|
||||
#endif
|
||||
switch(this->type_)
|
||||
{
|
||||
case value_t::boolean : assigner(boolean_ , v.boolean_ ); break;
|
||||
@@ -161,6 +177,9 @@ class basic_value
|
||||
this->type_ = v.type_;
|
||||
this->region_ = std::move(v.region_);
|
||||
this->comments_ = std::move(v.comments_);
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = v.accessed();
|
||||
#endif
|
||||
switch(this->type_)
|
||||
{
|
||||
case value_t::boolean : assigner(boolean_ , std::move(v.boolean_ )); break;
|
||||
@@ -184,6 +203,9 @@ class basic_value
|
||||
basic_value(basic_value v, std::vector<std::string> com)
|
||||
: type_(v.type()), region_(std::move(v.region_)),
|
||||
comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{v.accessed()}
|
||||
#endif
|
||||
{
|
||||
switch(this->type_)
|
||||
{
|
||||
@@ -209,6 +231,9 @@ class basic_value
|
||||
: type_(other.type_),
|
||||
region_(std::move(other.region_)),
|
||||
comments_(std::move(other.comments_))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{other.accessed()}
|
||||
#endif
|
||||
{
|
||||
switch(other.type_)
|
||||
{
|
||||
@@ -254,6 +279,9 @@ class basic_value
|
||||
: type_(other.type_),
|
||||
region_(std::move(other.region_)),
|
||||
comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{other.accessed()}
|
||||
#endif
|
||||
{
|
||||
switch(other.type_)
|
||||
{
|
||||
@@ -300,6 +328,10 @@ class basic_value
|
||||
this->region_ = other.region_;
|
||||
this->comments_ = comment_type(other.comments_);
|
||||
this->type_ = other.type_;
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = other.accessed();
|
||||
#endif
|
||||
|
||||
switch(other.type_)
|
||||
{
|
||||
// use auto-convert in constructor
|
||||
@@ -359,6 +391,9 @@ class basic_value
|
||||
std::vector<std::string> com, region_type reg)
|
||||
: type_(value_t::boolean), boolean_(boolean_storage(x, fmt)),
|
||||
region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
basic_value& operator=(boolean_type x)
|
||||
{
|
||||
@@ -370,6 +405,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::boolean;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->boolean_, boolean_storage(x, fmt));
|
||||
return *this;
|
||||
}
|
||||
@@ -393,6 +431,9 @@ class basic_value
|
||||
basic_value(integer_type x, integer_format_info fmt, std::vector<std::string> com, region_type reg)
|
||||
: type_(value_t::integer), integer_(integer_storage(std::move(x), std::move(fmt))),
|
||||
region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
basic_value& operator=(integer_type x)
|
||||
{
|
||||
@@ -404,6 +445,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::integer;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->integer_, integer_storage(std::move(x), std::move(fmt)));
|
||||
return *this;
|
||||
}
|
||||
@@ -439,6 +483,9 @@ class basic_value
|
||||
basic_value(T x, integer_format_info fmt, std::vector<std::string> com, region_type reg)
|
||||
: type_(value_t::integer), integer_(integer_storage(std::move(x), std::move(fmt))),
|
||||
region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
template<typename T, enable_if_integer_like_t<T> = nullptr>
|
||||
basic_value& operator=(T x)
|
||||
@@ -451,6 +498,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::integer;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->integer_, integer_storage(x, std::move(fmt)));
|
||||
return *this;
|
||||
}
|
||||
@@ -474,6 +524,9 @@ class basic_value
|
||||
basic_value(floating_type x, floating_format_info fmt, std::vector<std::string> com, region_type reg)
|
||||
: type_(value_t::floating), floating_(floating_storage(std::move(x), std::move(fmt))),
|
||||
region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
basic_value& operator=(floating_type x)
|
||||
{
|
||||
@@ -485,6 +538,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::floating;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->floating_, floating_storage(std::move(x), std::move(fmt)));
|
||||
return *this;
|
||||
}
|
||||
@@ -523,6 +579,9 @@ class basic_value
|
||||
basic_value(T x, floating_format_info fmt, std::vector<std::string> com, region_type reg)
|
||||
: type_(value_t::floating), floating_(floating_storage(x, std::move(fmt))),
|
||||
region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
|
||||
template<typename T, enable_if_floating_like_t<T> = nullptr>
|
||||
@@ -536,6 +595,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::floating;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->floating_, floating_storage(x, std::move(fmt)));
|
||||
return *this;
|
||||
}
|
||||
@@ -560,6 +622,9 @@ class basic_value
|
||||
std::vector<std::string> com, region_type reg)
|
||||
: type_(value_t::string), string_(string_storage(std::move(x), std::move(fmt))),
|
||||
region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
basic_value& operator=(string_type x)
|
||||
{
|
||||
@@ -571,6 +636,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::string;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->string_, string_storage(x, std::move(fmt)));
|
||||
return *this;
|
||||
}
|
||||
@@ -593,6 +661,9 @@ class basic_value
|
||||
std::vector<std::string> com, region_type reg)
|
||||
: type_(value_t::string), string_(string_storage(string_type(x), std::move(fmt))),
|
||||
region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
basic_value& operator=(const typename string_type::value_type* x)
|
||||
{
|
||||
@@ -604,6 +675,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::string;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->string_, string_storage(string_type(x), std::move(fmt)));
|
||||
return *this;
|
||||
}
|
||||
@@ -628,6 +702,9 @@ class basic_value
|
||||
std::vector<std::string> com, region_type reg)
|
||||
: type_(value_t::string), string_(string_storage(string_type(x), std::move(fmt))),
|
||||
region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
basic_value& operator=(string_view_type x)
|
||||
{
|
||||
@@ -639,6 +716,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::string;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->string_, string_storage(string_type(x), std::move(fmt)));
|
||||
return *this;
|
||||
}
|
||||
@@ -682,6 +762,9 @@ class basic_value
|
||||
: type_(value_t::string),
|
||||
string_(string_storage(detail::string_conv<string_type>(x), std::move(fmt))),
|
||||
region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
template<typename T, cxx::enable_if_t<cxx::conjunction<
|
||||
cxx::negation<std::is_same<cxx::remove_cvref_t<T>, string_type>>,
|
||||
@@ -697,6 +780,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::string;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->string_, string_storage(detail::string_conv<string_type>(x), std::move(fmt)));
|
||||
return *this;
|
||||
}
|
||||
@@ -721,6 +807,9 @@ class basic_value
|
||||
std::vector<std::string> com, region_type reg)
|
||||
: type_(value_t::local_date), local_date_(local_date_storage(x, fmt)),
|
||||
region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
basic_value& operator=(local_date_type x)
|
||||
{
|
||||
@@ -732,6 +821,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::local_date;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->local_date_, local_date_storage(x, fmt));
|
||||
return *this;
|
||||
}
|
||||
@@ -756,6 +848,9 @@ class basic_value
|
||||
std::vector<std::string> com, region_type reg)
|
||||
: type_(value_t::local_time), local_time_(local_time_storage(x, fmt)),
|
||||
region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
basic_value& operator=(local_time_type x)
|
||||
{
|
||||
@@ -767,6 +862,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::local_time;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->local_time_, local_time_storage(x, fmt));
|
||||
return *this;
|
||||
}
|
||||
@@ -804,6 +902,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::local_time;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->local_time_, local_time_storage(local_time_type(x), std::move(fmt)));
|
||||
return *this;
|
||||
}
|
||||
@@ -828,6 +929,9 @@ class basic_value
|
||||
std::vector<std::string> com, region_type reg)
|
||||
: type_(value_t::local_datetime), local_datetime_(local_datetime_storage(x, fmt)),
|
||||
region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
basic_value& operator=(local_datetime_type x)
|
||||
{
|
||||
@@ -839,6 +943,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::local_datetime;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->local_datetime_, local_datetime_storage(x, fmt));
|
||||
return *this;
|
||||
}
|
||||
@@ -863,6 +970,9 @@ class basic_value
|
||||
std::vector<std::string> com, region_type reg)
|
||||
: type_(value_t::offset_datetime), offset_datetime_(offset_datetime_storage(x, fmt)),
|
||||
region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
basic_value& operator=(offset_datetime_type x)
|
||||
{
|
||||
@@ -874,6 +984,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::offset_datetime;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->offset_datetime_, offset_datetime_storage(x, fmt));
|
||||
return *this;
|
||||
}
|
||||
@@ -906,6 +1019,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::offset_datetime;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->offset_datetime_, offset_datetime_storage(offset_datetime_type(x), fmt));
|
||||
return *this;
|
||||
}
|
||||
@@ -931,6 +1047,9 @@ class basic_value
|
||||
: type_(value_t::array), array_(array_storage(
|
||||
detail::storage<array_type>(std::move(x)), std::move(fmt)
|
||||
)), region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
basic_value& operator=(array_type x)
|
||||
{
|
||||
@@ -942,6 +1061,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::array;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->array_, array_storage(
|
||||
detail::storage<array_type>(std::move(x)), std::move(fmt)));
|
||||
return *this;
|
||||
@@ -988,6 +1110,9 @@ class basic_value
|
||||
std::make_move_iterator(x.end()))
|
||||
), std::move(fmt)
|
||||
)), region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
template<typename T, enable_if_array_like_t<T> = nullptr>
|
||||
basic_value& operator=(T x)
|
||||
@@ -1000,7 +1125,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::array;
|
||||
this->region_ = region_type{};
|
||||
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
array_type a(std::make_move_iterator(x.begin()),
|
||||
std::make_move_iterator(x.end()));
|
||||
assigner(this->array_, array_storage(
|
||||
@@ -1029,6 +1156,9 @@ class basic_value
|
||||
: type_(value_t::table), table_(table_storage(
|
||||
detail::storage<table_type>(std::move(x)), std::move(fmt)
|
||||
)), region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
basic_value& operator=(table_type x)
|
||||
{
|
||||
@@ -1040,6 +1170,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::table;
|
||||
this->region_ = region_type{};
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
assigner(this->table_, table_storage(
|
||||
detail::storage<table_type>(std::move(x)), std::move(fmt)));
|
||||
return *this;
|
||||
@@ -1084,6 +1217,9 @@ class basic_value
|
||||
std::make_move_iterator(x.end())
|
||||
)), std::move(fmt)
|
||||
)), region_(std::move(reg)), comments_(std::move(com))
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
template<typename T, enable_if_table_like_t<T> = nullptr>
|
||||
basic_value& operator=(T x)
|
||||
@@ -1096,7 +1232,9 @@ class basic_value
|
||||
this->cleanup();
|
||||
this->type_ = value_t::table;
|
||||
this->region_ = region_type{};
|
||||
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
table_type t(std::make_move_iterator(x.begin()),
|
||||
std::make_move_iterator(x.end()));
|
||||
assigner(this->table_, table_storage(
|
||||
@@ -1126,6 +1264,9 @@ class basic_value
|
||||
basic_value& operator=(const T& ud)
|
||||
{
|
||||
*this = into<cxx::remove_cvref_t<T>>::template into_toml<config_type>(ud);
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1149,6 +1290,9 @@ class basic_value
|
||||
basic_value& operator=(const T& ud)
|
||||
{
|
||||
*this = ud.into_toml();
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1172,6 +1316,9 @@ class basic_value
|
||||
basic_value& operator=(const T& ud)
|
||||
{
|
||||
*this = ud.template into_toml<TypeConfig>();
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
// }}}
|
||||
@@ -1181,6 +1328,9 @@ class basic_value
|
||||
// mainly for `null` extension
|
||||
basic_value(detail::none_t, region_type reg) noexcept
|
||||
: type_(value_t::empty), empty_('\0'), region_(std::move(reg)), comments_{}
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
, accessed_{false}
|
||||
#endif
|
||||
{}
|
||||
|
||||
// }}}
|
||||
@@ -1239,36 +1389,38 @@ class basic_value
|
||||
detail::enum_to_type_t<T, basic_value<config_type>> const&
|
||||
as(const std::nothrow_t&) const noexcept
|
||||
{
|
||||
this->set_accessed();
|
||||
return detail::getter<config_type, T>::get_nothrow(*this);
|
||||
}
|
||||
template<value_t T>
|
||||
detail::enum_to_type_t<T, basic_value<config_type>>&
|
||||
as(const std::nothrow_t&) noexcept
|
||||
{
|
||||
this->set_accessed();
|
||||
return detail::getter<config_type, T>::get_nothrow(*this);
|
||||
}
|
||||
|
||||
boolean_type const& as_boolean (const std::nothrow_t&) const noexcept {return this->boolean_.value;}
|
||||
integer_type const& as_integer (const std::nothrow_t&) const noexcept {return this->integer_.value;}
|
||||
floating_type const& as_floating (const std::nothrow_t&) const noexcept {return this->floating_.value;}
|
||||
string_type const& as_string (const std::nothrow_t&) const noexcept {return this->string_.value;}
|
||||
offset_datetime_type const& as_offset_datetime(const std::nothrow_t&) const noexcept {return this->offset_datetime_.value;}
|
||||
local_datetime_type const& as_local_datetime (const std::nothrow_t&) const noexcept {return this->local_datetime_.value;}
|
||||
local_date_type const& as_local_date (const std::nothrow_t&) const noexcept {return this->local_date_.value;}
|
||||
local_time_type const& as_local_time (const std::nothrow_t&) const noexcept {return this->local_time_.value;}
|
||||
array_type const& as_array (const std::nothrow_t&) const noexcept {return this->array_.value.get();}
|
||||
table_type const& as_table (const std::nothrow_t&) const noexcept {return this->table_.value.get();}
|
||||
boolean_type const& as_boolean (const std::nothrow_t&) const noexcept {this->set_accessed(); return this->boolean_.value;}
|
||||
integer_type const& as_integer (const std::nothrow_t&) const noexcept {this->set_accessed(); return this->integer_.value;}
|
||||
floating_type const& as_floating (const std::nothrow_t&) const noexcept {this->set_accessed(); return this->floating_.value;}
|
||||
string_type const& as_string (const std::nothrow_t&) const noexcept {this->set_accessed(); return this->string_.value;}
|
||||
offset_datetime_type const& as_offset_datetime(const std::nothrow_t&) const noexcept {this->set_accessed(); return this->offset_datetime_.value;}
|
||||
local_datetime_type const& as_local_datetime (const std::nothrow_t&) const noexcept {this->set_accessed(); return this->local_datetime_.value;}
|
||||
local_date_type const& as_local_date (const std::nothrow_t&) const noexcept {this->set_accessed(); return this->local_date_.value;}
|
||||
local_time_type const& as_local_time (const std::nothrow_t&) const noexcept {this->set_accessed(); return this->local_time_.value;}
|
||||
array_type const& as_array (const std::nothrow_t&) const noexcept {this->set_accessed(); return this->array_.value.get();}
|
||||
table_type const& as_table (const std::nothrow_t&) const noexcept {this->set_accessed(); return this->table_.value.get();}
|
||||
|
||||
boolean_type & as_boolean (const std::nothrow_t&) noexcept {return this->boolean_.value;}
|
||||
integer_type & as_integer (const std::nothrow_t&) noexcept {return this->integer_.value;}
|
||||
floating_type & as_floating (const std::nothrow_t&) noexcept {return this->floating_.value;}
|
||||
string_type & as_string (const std::nothrow_t&) noexcept {return this->string_.value;}
|
||||
offset_datetime_type& as_offset_datetime(const std::nothrow_t&) noexcept {return this->offset_datetime_.value;}
|
||||
local_datetime_type & as_local_datetime (const std::nothrow_t&) noexcept {return this->local_datetime_.value;}
|
||||
local_date_type & as_local_date (const std::nothrow_t&) noexcept {return this->local_date_.value;}
|
||||
local_time_type & as_local_time (const std::nothrow_t&) noexcept {return this->local_time_.value;}
|
||||
array_type & as_array (const std::nothrow_t&) noexcept {return this->array_.value.get();}
|
||||
table_type & as_table (const std::nothrow_t&) noexcept {return this->table_.value.get();}
|
||||
boolean_type & as_boolean (const std::nothrow_t&) noexcept {this->set_accessed(); return this->boolean_.value;}
|
||||
integer_type & as_integer (const std::nothrow_t&) noexcept {this->set_accessed(); return this->integer_.value;}
|
||||
floating_type & as_floating (const std::nothrow_t&) noexcept {this->set_accessed(); return this->floating_.value;}
|
||||
string_type & as_string (const std::nothrow_t&) noexcept {this->set_accessed(); return this->string_.value;}
|
||||
offset_datetime_type& as_offset_datetime(const std::nothrow_t&) noexcept {this->set_accessed(); return this->offset_datetime_.value;}
|
||||
local_datetime_type & as_local_datetime (const std::nothrow_t&) noexcept {this->set_accessed(); return this->local_datetime_.value;}
|
||||
local_date_type & as_local_date (const std::nothrow_t&) noexcept {this->set_accessed(); return this->local_date_.value;}
|
||||
local_time_type & as_local_time (const std::nothrow_t&) noexcept {this->set_accessed(); return this->local_time_.value;}
|
||||
array_type & as_array (const std::nothrow_t&) noexcept {this->set_accessed(); return this->array_.value.get();}
|
||||
table_type & as_table (const std::nothrow_t&) noexcept {this->set_accessed(); return this->table_.value.get();}
|
||||
|
||||
// }}}
|
||||
|
||||
@@ -1291,6 +1443,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_boolean()", value_t::boolean);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->boolean_.value;
|
||||
}
|
||||
integer_type const& as_integer() const
|
||||
@@ -1299,6 +1452,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_integer()", value_t::integer);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->integer_.value;
|
||||
}
|
||||
floating_type const& as_floating() const
|
||||
@@ -1307,6 +1461,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_floating()", value_t::floating);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->floating_.value;
|
||||
}
|
||||
string_type const& as_string() const
|
||||
@@ -1315,6 +1470,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_string()", value_t::string);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->string_.value;
|
||||
}
|
||||
offset_datetime_type const& as_offset_datetime() const
|
||||
@@ -1323,6 +1479,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_offset_datetime()", value_t::offset_datetime);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->offset_datetime_.value;
|
||||
}
|
||||
local_datetime_type const& as_local_datetime() const
|
||||
@@ -1331,6 +1488,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_local_datetime()", value_t::local_datetime);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->local_datetime_.value;
|
||||
}
|
||||
local_date_type const& as_local_date() const
|
||||
@@ -1339,6 +1497,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_local_date()", value_t::local_date);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->local_date_.value;
|
||||
}
|
||||
local_time_type const& as_local_time() const
|
||||
@@ -1347,6 +1506,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_local_time()", value_t::local_time);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->local_time_.value;
|
||||
}
|
||||
array_type const& as_array() const
|
||||
@@ -1355,6 +1515,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_array()", value_t::array);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->array_.value.get();
|
||||
}
|
||||
table_type const& as_table() const
|
||||
@@ -1363,6 +1524,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_table()", value_t::table);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->table_.value.get();
|
||||
}
|
||||
|
||||
@@ -1375,6 +1537,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_boolean()", value_t::boolean);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->boolean_.value;
|
||||
}
|
||||
integer_type& as_integer()
|
||||
@@ -1383,6 +1546,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_integer()", value_t::integer);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->integer_.value;
|
||||
}
|
||||
floating_type& as_floating()
|
||||
@@ -1391,6 +1555,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_floating()", value_t::floating);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->floating_.value;
|
||||
}
|
||||
string_type& as_string()
|
||||
@@ -1399,6 +1564,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_string()", value_t::string);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->string_.value;
|
||||
}
|
||||
offset_datetime_type& as_offset_datetime()
|
||||
@@ -1407,6 +1573,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_offset_datetime()", value_t::offset_datetime);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->offset_datetime_.value;
|
||||
}
|
||||
local_datetime_type& as_local_datetime()
|
||||
@@ -1415,6 +1582,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_local_datetime()", value_t::local_datetime);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->local_datetime_.value;
|
||||
}
|
||||
local_date_type& as_local_date()
|
||||
@@ -1423,6 +1591,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_local_date()", value_t::local_date);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->local_date_.value;
|
||||
}
|
||||
local_time_type& as_local_time()
|
||||
@@ -1431,6 +1600,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_local_time()", value_t::local_time);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->local_time_.value;
|
||||
}
|
||||
array_type& as_array()
|
||||
@@ -1439,6 +1609,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_array()", value_t::array);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->array_.value.get();
|
||||
}
|
||||
table_type& as_table()
|
||||
@@ -1447,6 +1618,7 @@ class basic_value
|
||||
{
|
||||
this->throw_bad_cast("toml::value::as_table()", value_t::table);
|
||||
}
|
||||
this->set_accessed();
|
||||
return this->table_.value.get();
|
||||
}
|
||||
|
||||
@@ -1856,10 +2028,20 @@ class basic_value
|
||||
comment_type const& comments() const noexcept {return this->comments_;}
|
||||
comment_type& comments() noexcept {return this->comments_;}
|
||||
|
||||
bool accessed() const {return this->accessed_.load();}
|
||||
|
||||
private:
|
||||
|
||||
// private helper functions =========================================== {{{
|
||||
|
||||
void set_accessed() const noexcept
|
||||
{
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_.store(true);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
void cleanup() noexcept
|
||||
{
|
||||
switch(this->type_)
|
||||
@@ -1876,6 +2058,9 @@ class basic_value
|
||||
case value_t::table : { table_ .~table_storage (); break; }
|
||||
default : { break; }
|
||||
}
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
this->accessed_ = false;
|
||||
#endif
|
||||
this->type_ = value_t::empty;
|
||||
return;
|
||||
}
|
||||
@@ -1942,6 +2127,10 @@ class basic_value
|
||||
};
|
||||
region_type region_;
|
||||
comment_type comments_;
|
||||
|
||||
#ifdef TOML11_ENABLE_ACCESS_CHECK
|
||||
mutable std::atomic<bool> accessed_;
|
||||
#endif
|
||||
};
|
||||
|
||||
template<typename TC>
|
||||
|
Reference in New Issue
Block a user