1
0
Fork 0

New options setting/clearing helpers.

This commit is contained in:
James Turner 2016-03-24 15:05:03 +00:00
parent ff7b82885f
commit 88bfaca2b3
2 changed files with 53 additions and 2 deletions

View file

@ -1770,6 +1770,22 @@ public:
return it; // not found 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 OptionDesc* findOption(const string& key) const
{ {
OptionDescDict::const_iterator it = options.find(key); OptionDescDict::const_iterator it = options.find(key);
@ -2203,6 +2219,34 @@ int Options::addOption(const string &key, const string &value)
return FG_OPTIONS_OK; 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 bool Options::isOptionSet(const string &key) const
{ {
OptionValueVec::const_iterator it = p->findValue(key); OptionValueVec::const_iterator it = p->findValue(key);

View file

@ -102,6 +102,13 @@ public:
*/ */
int addOption(const std::string& key, const std::string& value); 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 * apply option values to the simulation state
* (set properties, etc). * (set properties, etc).