mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2025-01-12 21:21:05 +00:00
debugging: make debugging_option_c instances re-evaluate their result upon invalidation
This commit is contained in:
parent
5654172dfd
commit
605bae5bf5
@ -47,11 +47,15 @@ request_debugging(const std::string &options) {
|
||||
|
||||
for (auto &one_option : all_options) {
|
||||
std::vector<std::string> parts = split(one_option, "=", 2);
|
||||
if (!parts[0].size())
|
||||
continue;
|
||||
if (parts[0] == "!")
|
||||
s_debugging_options.clear();
|
||||
else
|
||||
s_debugging_options[parts[0]] = 1 == parts.size() ? std::string("") : parts[1];
|
||||
}
|
||||
|
||||
debugging_option_c::invalidate_cache();
|
||||
}
|
||||
|
||||
void
|
||||
@ -64,3 +68,22 @@ init_debugging() {
|
||||
request_debugging(value);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<debugging_option_c::option_c> debugging_option_c::ms_registered_options;
|
||||
|
||||
size_t
|
||||
debugging_option_c::register_option(std::string const &option) {
|
||||
auto itr = brng::find_if(ms_registered_options, [&option](option_c const &opt) { return opt.m_option == option; });
|
||||
if (itr != ms_registered_options.end())
|
||||
return std::distance(ms_registered_options.begin(), itr);
|
||||
|
||||
ms_registered_options.emplace_back(option);
|
||||
|
||||
return ms_registered_options.size() - 1;
|
||||
}
|
||||
|
||||
void
|
||||
debugging_option_c::invalidate_cache() {
|
||||
for (auto &opt : ms_registered_options)
|
||||
opt.m_requested = boost::logic::indeterminate;
|
||||
}
|
||||
|
@ -24,23 +24,48 @@ void init_debugging();
|
||||
int parse_debug_interval_arg(const std::string &option, int default_value = 1000, int invalid_value = -1);
|
||||
|
||||
class debugging_option_c {
|
||||
struct option_c {
|
||||
boost::tribool m_requested;
|
||||
std::string m_option;
|
||||
|
||||
option_c(std::string const &option)
|
||||
: m_requested{boost::logic::indeterminate}
|
||||
, m_option{option}
|
||||
{
|
||||
}
|
||||
|
||||
bool get() {
|
||||
if (boost::logic::indeterminate(m_requested))
|
||||
m_requested = debugging_requested(m_option);
|
||||
|
||||
return m_requested;
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
boost::tribool m_requested;
|
||||
size_t m_registered_idx;
|
||||
std::string m_option;
|
||||
|
||||
private:
|
||||
static std::vector<option_c> ms_registered_options;
|
||||
|
||||
public:
|
||||
debugging_option_c(std::string const &option)
|
||||
: m_requested{boost::logic::indeterminate}
|
||||
: m_registered_idx{std::numeric_limits<size_t>::max()}
|
||||
, m_option{option}
|
||||
{
|
||||
}
|
||||
|
||||
operator bool() {
|
||||
if (boost::logic::indeterminate(m_requested))
|
||||
m_requested = debugging_requested(m_option);
|
||||
if (m_registered_idx == std::numeric_limits<size_t>::max())
|
||||
m_registered_idx = register_option(m_option);
|
||||
|
||||
return m_requested;
|
||||
return ms_registered_options[m_registered_idx].get();
|
||||
}
|
||||
|
||||
public:
|
||||
static size_t register_option(std::string const &option);
|
||||
static void invalidate_cache();
|
||||
};
|
||||
|
||||
#endif // MTX_COMMON_DEBUGGING_H
|
||||
|
Loading…
Reference in New Issue
Block a user