本文整理汇总了C++中param_descrs::get_kind方法的典型用法代码示例。如果您正苦于以下问题:C++ param_descrs::get_kind方法的具体用法?C++ param_descrs::get_kind怎么用?C++ param_descrs::get_kind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类param_descrs
的用法示例。
在下文中一共展示了param_descrs::get_kind方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: validate_type
void validate_type(symbol const& name, char const* value, param_descrs const& d) {
param_kind k = d.get_kind(name);
std::stringstream strm;
char const* _value = value;
switch (k) {
case CPK_UINT:
for (; *value; ++value) {
if (!('0' <= *value && *value <= '9')) {
strm << "Expected values for parameter " << name
<< " is an unsigned integer. It was given argument '" << _value << "'";
throw default_exception(strm.str());
}
}
break;
case CPK_DOUBLE:
for (; *value; ++value) {
if (!('0' <= *value && *value <= '9') && *value != '.' && *value != '-' && *value != '/') {
strm << "Expected values for parameter " << name
<< " is a double. It was given argument '" << _value << "'";
throw default_exception(strm.str());
}
}
break;
case CPK_BOOL:
if (strcmp(value, "true") != 0 && strcmp(value, "false") != 0) {
strm << "Expected values for parameter " << name
<< " are 'true' or 'false'. It was given argument '" << value << "'";
throw default_exception(strm.str());
}
break;
default:
break;
}
}
示例2: set
void set(param_descrs const & d, symbol const & param_name, char const * value, symbol const & mod_name) {
param_kind k = d.get_kind(param_name);
params_ref & ps = get_params(mod_name);
if (k == CPK_INVALID) {
throw_unknown_parameter(param_name, d, mod_name);
}
else if (k == CPK_UINT) {
long val = strtol(value, nullptr, 10);
ps.set_uint(param_name, static_cast<unsigned>(val));
}
else if (k == CPK_DOUBLE) {
char * aux;
double val = strtod(value, &aux);
ps.set_double(param_name, val);
}
else if (k == CPK_BOOL) {
if (strcmp(value, "true") == 0) {
ps.set_bool(param_name, true);
}
else if (strcmp(value, "false") == 0) {
ps.set_bool(param_name, false);
}
else {
std::stringstream strm;
strm << "invalid value '" << value << "' for Boolean parameter '" << param_name << "'";
if (mod_name == symbol::null) {
strm << " at module '" << mod_name << "'";
}
throw default_exception(strm.str());
}
}
else if (k == CPK_SYMBOL) {
ps.set_sym(param_name, symbol(value));
}
else if (k == CPK_STRING) {
// There is no guarantee that (external) callers will not delete value after invoking gparams::set.
// I see two solutions:
// 1) Modify params_ref to create a copy of set_str parameters.
// This solution is not nice since we create copies and move the params_ref around.
// We would have to keep copying the strings.
// Moreover, when we use params_ref internally, the value is usually a static value.
// So, we would be paying this price for nothing.
// 2) "Copy" value by transforming it into a symbol.
// I'm using this solution for now.
ps.set_str(param_name, symbol(value).bare_str());
}
else {
std::stringstream strm;
strm << "unsupported parameter type '" << param_name << "'";
if (mod_name == symbol::null) {
strm << " at module '" << mod_name << "'";
}
throw exception(strm.str());
}
}
示例3: validate
void validate(param_descrs const & p) const {
svector<params::entry>::const_iterator it = m_entries.begin();
svector<params::entry>::const_iterator end = m_entries.end();
for (; it != end; ++it) {
param_kind expected = p.get_kind(it->first);
if (expected == CPK_INVALID)
throw default_exception("unknown parameter '%s'", it->first.str().c_str());
if (it->second.m_kind != expected)
throw default_exception("parameter kind mismatch '%s'", it->first.str().c_str());
}
}