void core_options::append_entry(core_options::entry &newentry) { m_entrylist.append(newentry); // if we have names, add them to the map for (int name = 0; name < ARRAY_LENGTH(newentry.m_name); name++) if (newentry.name(name) != nullptr) { m_entrymap.insert(std::make_pair(newentry.name(name), &newentry)); // for boolean options add a "no" variant as well if (newentry.type() == OPTION_BOOLEAN) m_entrymap.insert(std::make_pair(std::string("no").append(newentry.name(name)), &newentry)); } }
void core_options::append_entry(core_options::entry &newentry) { m_entrylist.append(newentry); // if we have names, add them to the map for (int name = 0; name < ARRAY_LENGTH(newentry.m_name); name++) if (newentry.name(name) != NULL) { m_entrymap.add(newentry.name(name), &newentry); // for boolean options add a "no" variant as well if (newentry.type() == OPTION_BOOLEAN) m_entrymap.add(astring("no").cat(newentry.name(name)).c_str(), &newentry); } }
void core_options::append_entry(core_options::entry &newentry) { // append to the list *m_entrylist_tailptr = &newentry; m_entrylist_tailptr = &newentry.m_next; // if we have names, add them to the map astring tempstr; for (int name = 0; name < ARRAY_LENGTH(newentry.m_name); name++) if (newentry.m_name[name]) { m_entrymap.add(newentry.m_name[name], &newentry); // for boolean options add a "no" variant as well if (newentry.type() == OPTION_BOOLEAN) m_entrymap.add(tempstr.cpy("no").cat(newentry.m_name[name]), &newentry); } }
bool core_options::validate_and_set_data(core_options::entry &curentry, const char *newdata, int priority, astring &error_string) { // trim any whitespace astring data(newdata); data.trimspace(); // trim quotes if (data.chr(0, '"') == 0 && data.rchr(0, '"') == data.len() - 1) { data.del(0, 1); data.del(data.len() - 1, 1); } // validate the type of data and optionally the range float fval; int ival; switch (curentry.type()) { // booleans must be 0 or 1 case OPTION_BOOLEAN: if (sscanf(data, "%d", &ival) != 1 || ival < 0 || ival > 1) { error_string.catprintf("Illegal boolean value for %s: \"%s\"; reverting to %s\n", curentry.name(), data.cstr(), curentry.value()); return false; } break; // integers must be integral case OPTION_INTEGER: if (sscanf(data, "%d", &ival) != 1) { error_string.catprintf("Illegal integer value for %s: \"%s\"; reverting to %s\n", curentry.name(), data.cstr(), curentry.value()); return false; } if (curentry.has_range() && (ival < atoi(curentry.minimum()) || ival > atoi(curentry.maximum()))) { error_string.catprintf("Out-of-range integer value for %s: \"%s\" (must be between %s and %s); reverting to %s\n", curentry.name(), data.cstr(), curentry.minimum(), curentry.maximum(), curentry.value()); return false; } break; // floating-point values must be numeric case OPTION_FLOAT: if (sscanf(data, "%f", &fval) != 1) { error_string.catprintf("Illegal float value for %s: \"%s\"; reverting to %s\n", curentry.name(), data.cstr(), curentry.value()); return false; } if (curentry.has_range() && (fval < atof(curentry.minimum()) || fval > atof(curentry.maximum()))) { error_string.catprintf("Out-of-range float value for %s: \"%s\" (must be between %s and %s); reverting to %s\n", curentry.name(), data.cstr(), curentry.minimum(), curentry.maximum(), curentry.value()); return false; } break; // strings can be anything case OPTION_STRING: break; // anything else is invalid case OPTION_INVALID: case OPTION_HEADER: default: error_string.catprintf("Attempted to set invalid option %s\n", curentry.name()); return false; } // set the data curentry.set_value(data, priority); return true; }