From 8ec9257f2647c1f9dcc1dee949d630888973ad08 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 30 Jan 2025 00:13:26 +0900 Subject: [PATCH] feat: enable to unset flag --- include/toml11/value.hpp | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/include/toml11/value.hpp b/include/toml11/value.hpp index 3c4729d..9d54648 100644 --- a/include/toml11/value.hpp +++ b/include/toml11/value.hpp @@ -59,6 +59,11 @@ void change_region_of_value(basic_value&, const basic_value&); template struct getter; + +#ifdef TOML11_ENABLE_ACCESS_CHECK +template +void unset_access_flag(basic_value&); +#endif } // detail template @@ -2102,6 +2107,12 @@ class basic_value template friend class basic_value; + +#ifdef TOML11_ENABLE_ACCESS_CHECK + template + friend void detail::unset_access_flag(basic_value&); +#endif + // }}} private: @@ -2450,6 +2461,48 @@ void change_region_of_value(basic_value& dst, const basic_value& src) return; } +#ifdef TOML11_ENABLE_ACCESS_CHECK +template +void unset_access_flag(basic_value& v) +{ + v.accessed_.store(false); +} + +template +void unset_access_flag_recursively(basic_value& v) +{ + switch(v.type()) + { + case value_t::empty : { return unset_access_flag(v); } + case value_t::boolean : { return unset_access_flag(v); } + case value_t::integer : { return unset_access_flag(v); } + case value_t::floating : { return unset_access_flag(v); } + case value_t::string : { return unset_access_flag(v); } + case value_t::offset_datetime : { return unset_access_flag(v); } + case value_t::local_datetime : { return unset_access_flag(v); } + case value_t::local_date : { return unset_access_flag(v); } + case value_t::local_time : { return unset_access_flag(v); } + case value_t::array: + { + for(auto& elem : v.as_array()) + { + unset_access_flag_recursively(elem); + } + return unset_access_flag(v); + } + case value_t::table: + { + for(auto& kv : v.as_table()) + { + unset_access_flag_recursively(kv.second); + } + return unset_access_flag(v); + } + default: { return unset_access_flag(v); } + } +} +#endif + } // namespace detail } // namespace toml #endif // TOML11_VALUE_HPP