New options setting/clearing helpers.
This commit is contained in:
parent
ff7b82885f
commit
88bfaca2b3
2 changed files with 53 additions and 2 deletions
|
@ -1769,6 +1769,22 @@ public:
|
|||
|
||||
return it; // not found
|
||||
}
|
||||
|
||||
OptionValueVec::iterator findValue(const string& key)
|
||||
{
|
||||
OptionValueVec::iterator it = values.begin();
|
||||
for (; it != values.end(); ++it) {
|
||||
if (!it->desc) {
|
||||
continue; // ignore markers
|
||||
}
|
||||
|
||||
if (it->desc->option == key) {
|
||||
return it;
|
||||
}
|
||||
} // of set values iteration
|
||||
|
||||
return it; // not found
|
||||
}
|
||||
|
||||
OptionDesc* findOption(const string& key) const
|
||||
{
|
||||
|
@ -2202,7 +2218,35 @@ int Options::addOption(const string &key, const string &value)
|
|||
p->values.push_back(OptionValue(desc, value));
|
||||
return FG_OPTIONS_OK;
|
||||
}
|
||||
|
||||
|
||||
int Options::setOption(const string &key, const string &value)
|
||||
{
|
||||
OptionDesc* desc = p->findOption(key);
|
||||
if (!desc) {
|
||||
flightgear::modalMessageBox("Unknown option", "Unknown command-line option: " + key);
|
||||
return FG_OPTIONS_ERROR;
|
||||
}
|
||||
|
||||
if (!(desc->type & OPTION_MULTI)) {
|
||||
OptionValueVec::const_iterator it = p->findValue(key);
|
||||
if (it != p->values.end()) {
|
||||
// remove existing valye
|
||||
p->values.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
p->values.push_back(OptionValue(desc, value));
|
||||
return FG_OPTIONS_OK;
|
||||
}
|
||||
|
||||
void Options::clearOption(const std::string& key)
|
||||
{
|
||||
OptionValueVec::iterator it = p->findValue(key);
|
||||
for (; it != p->values.end(); it = p->findValue(key)) {
|
||||
p->values.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
bool Options::isOptionSet(const string &key) const
|
||||
{
|
||||
OptionValueVec::const_iterator it = p->findValue(key);
|
||||
|
|
|
@ -101,7 +101,14 @@ public:
|
|||
* This can be used to inject option values, eg based upon environment variables
|
||||
*/
|
||||
int addOption(const std::string& key, const std::string& value);
|
||||
|
||||
|
||||
/**
|
||||
* set an option, overwriting any existing value which might be set
|
||||
*/
|
||||
int setOption(const std::string& key, const std::string& value);
|
||||
|
||||
void clearOption(const std::string& key);
|
||||
|
||||
/**
|
||||
* apply option values to the simulation state
|
||||
* (set properties, etc).
|
||||
|
|
Loading…
Reference in a new issue