New options setting/clearing helpers.
This commit is contained in:
parent
ff7b82885f
commit
88bfaca2b3
2 changed files with 53 additions and 2 deletions
|
@ -1770,6 +1770,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
|
||||
{
|
||||
OptionDescDict::const_iterator it = options.find(key);
|
||||
|
@ -2203,6 +2219,34 @@ int Options::addOption(const string &key, const string &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);
|
||||
|
|
|
@ -102,6 +102,13 @@ public:
|
|||
*/
|
||||
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