[Core] Implement ability to find ConfigVar based on a reference to its wrapped value
This commit is contained in:
parent
838870caa4
commit
e990505609
|
@ -185,7 +185,7 @@ void Config::LoadGameConfig(const std::string_view title_id) {
|
|||
}
|
||||
}
|
||||
|
||||
cvar::IConfigVar* Config::FindConfigVar(const std::string& name) {
|
||||
cvar::IConfigVar* Config::FindConfigVarByName(const std::string& name) {
|
||||
const auto it = config_vars_.find(name);
|
||||
if (it != config_vars_.end()) {
|
||||
return it->second.get();
|
||||
|
|
|
@ -59,7 +59,13 @@ class Config {
|
|||
/**
|
||||
* Find a config variable for a given config field
|
||||
*/
|
||||
cvar::IConfigVar* FindConfigVar(const std::string& name);
|
||||
cvar::IConfigVar* FindConfigVarByName(const std::string& name);
|
||||
|
||||
/**
|
||||
* Find a config variable that contains a pointer to a provided reference
|
||||
*/
|
||||
template <typename T>
|
||||
cvar::ConfigVar<T>* FindConfigVar(const T& value);
|
||||
|
||||
/**
|
||||
* Find a command variable for a given name
|
||||
|
@ -104,6 +110,19 @@ class Config {
|
|||
cxxopts::Options options_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
cvar::ConfigVar<T>* Config::FindConfigVar(const T& value) {
|
||||
for (const auto& [name, var] : config_vars_) {
|
||||
auto typed_var = dynamic_cast<cvar::ConfigVar<T>*>(var.get());
|
||||
if (typed_var) {
|
||||
if (std::addressof(value) == typed_var->current_value()) {
|
||||
return typed_var;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
cvar::ConfigVar<T>* Config::RegisterConfigVar(cvar::ConfigVar<T>* var) {
|
||||
const std::string& name = var->name();
|
||||
|
|
Loading…
Reference in New Issue