iterator operator--(int) { assert_exists(); node* result = target; if (result -> left == nullptr) { node* tmp = nullptr; while (result -> parent != nullptr && (tmp == nullptr || result->left == tmp)) { tmp = result; result = result -> parent; } if (tmp == nullptr || result -> parent == nullptr && result -> left == tmp) target = nullptr; else target = result; return *this; } else { result = result -> left; while (result -> right != nullptr) result = result -> right; target = result; return *this; } }
void OptionsFunctionalityNode::setDefault(const std::string &name, const GenericType &def_val) { assert_exists(name); defaults_[name] = def_val; }
std::vector<GenericType> OptionsFunctionalityNode::getOptionAllowed(const std::string &name) const { assert_exists(name); map<string, std::vector<GenericType> >::const_iterator it = allowed_vals_.find(name); if (it!=allowed_vals_.end()) return it->second; return std::vector<GenericType>(); }
GenericType OptionsFunctionalityNode::getOptionDefault(const std::string &name) const { assert_exists(name); Dictionary::const_iterator it = defaults_.find(name); if (it!=defaults_.end()) return it->second; return GenericType(); }
opt_type OptionsFunctionalityNode::getOptionType(const std::string &name) const { assert_exists(name); map<string, opt_type>::const_iterator it = allowed_options.find(name); if (it!=allowed_options.end()) return it->second; return OT_UNKNOWN; }
std::string OptionsFunctionalityNode::getOptionDescription(const std::string &name) const { assert_exists(name); map<string, string>::const_iterator it = description_.find(name); if (it!=description_.end()) return it->second; return "N/A"; }
void OptionsFunctionalityNode::setOption(const string &name, const GenericType &op){ assert_exists(name); // If we have an empty vector, than we are not strict about the type if (op.isEmptyVector()) { dictionary_[name] = GenericType::from_type(allowed_options[name]); return; } // Some typechecking if (!op.can_cast_to(allowed_options[name])) { stringstream ss; ss << "Option '" << name << "' expects a '" << GenericType::get_type_description(allowed_options[name]) << "' type." << endl; if (op.getType() == OT_BOOLEAN) { ss << "You supplied another type, possibly boolean." << endl; if (allowed_options[name]==OT_REAL || allowed_options[name]==OT_INTEGER) { ss << "(A common mistake is to use SXMatrix/MX instead of floats/DMatrix in this context)" << endl; } } else { ss << "You supplied a type '" << op.get_description() << "' instead." << endl; } if (!allowed_vals_[name].empty()) { ss << "(Allowed values are:"; for (std::vector<GenericType>::const_iterator it=allowed_vals_[name].begin();it!=allowed_vals_[name].end();it++) { ss << " '" << *it << "'"; } ss << ")" << endl; } casadi_error(ss.str()); } // If allowed values are listed, check them. if (!allowed_vals_[name].empty()) { bool found = false; GenericType problem = op; if (op.isStringVector()) { const std::vector<std::string> & opv = op.toStringVector(); for (std::vector<std::string>::const_iterator it=opv.begin();it!=opv.end();it++) { if (std::find(allowed_vals_[name].begin(), allowed_vals_[name].end(), (*it))==allowed_vals_[name].end()) { problem = (*it); break; } found = true; } } else { for (std::vector<GenericType>::const_iterator it=allowed_vals_[name].begin();it!=allowed_vals_[name].end();it++) { found = found || (*it) == op; } } // If supplied op is not in allowed values, raise an error. if (!found) { stringstream ss; ss << "Option '" << name << "' does not allow '" << problem << "'." << endl; ss << "(Allowed values options are:"; for (std::vector<GenericType>::const_iterator it=allowed_vals_[name].begin();it!=allowed_vals_[name].end();it++) { ss << " '" << *it << "'"; } ss << ")" << endl; casadi_error(ss.str()); } } // Save the option dictionary_[name] = op; }
int const& operator*() { assert_exists(); return target->__val; }
int const& value() { assert_exists(); return target->__val; }