本文整理汇总了C++中ndt::type::is_scalar方法的典型用法代码示例。如果您正苦于以下问题:C++ type::is_scalar方法的具体用法?C++ type::is_scalar怎么用?C++ type::is_scalar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ndt::type
的用法示例。
在下文中一共展示了type::is_scalar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_nonragged_dim_count
size_t pydynd::get_nonragged_dim_count(const ndt::type &tp, size_t max_count)
{
if (tp.is_symbolic()) {
if (tp.is_scalar()) {
return 0;
}
}
if (!tp.is_scalar()) {
if (max_count <= 1) {
return max_count;
}
else {
return min(max_count,
1 + get_nonragged_dim_count(
static_cast<const ndt::base_dim_type *>(tp.extended())
->get_element_type(),
max_count - 1));
}
}
switch (tp.get_id()) {
case struct_id:
case tuple_id:
if (max_count <= 1) {
return max_count;
}
else {
auto bsd = tp.extended<ndt::tuple_type>();
size_t field_count = bsd->get_field_count();
for (size_t i = 0; i != field_count; ++i) {
size_t candidate =
1 + get_nonragged_dim_count(bsd->get_field_type(i), max_count - 1);
if (candidate < max_count) {
max_count = candidate;
if (max_count <= 1) {
return max_count;
}
}
}
return max_count;
}
default:
return 0;
}
}
示例2: parse_option_json
static void parse_option_json(const ndt::type &tp, const char *arrmeta, char *out_data, const char *&begin,
const char *end, const eval::eval_context *ectx)
{
begin = skip_whitespace(begin, end);
const char *saved_begin = begin;
if (tp.is_scalar()) {
if (parse_token(begin, end, "null")) {
tp.extended<ndt::option_type>()->assign_na(arrmeta, out_data, ectx);
return;
} else {
const ndt::type &value_tp = tp.extended<ndt::option_type>()->get_value_type();
const char *strbegin, *strend;
bool escaped;
if (parse::parse_doublequote_string_no_ws(begin, end, strbegin, strend, escaped)) {
try
{
if (!escaped) {
tp.extended()->set_from_utf8_string(arrmeta, out_data, strbegin, strend, ectx);
} else {
std::string val;
parse::unescape_string(strbegin, strend, val);
tp.extended()->set_from_utf8_string(arrmeta, out_data, val, ectx);
}
return;
}
catch (const exception &e)
{
throw json_parse_error(saved_begin, e.what(), tp);
}
catch (const dynd::dynd_exception &e)
{
throw json_parse_error(saved_begin, e.what(), tp);
}
} else if (value_tp.get_kind() == bool_kind) {
if (parse_token(begin, end, "true")) {
*out_data = 1;
} else if (parse_token(begin, end, "false")) {
*out_data = 0;
} else if (parse::parse_json_number_no_ws(begin, end, strbegin, strend)) {
if (parse::compare_range_to_literal(strbegin, strend, "1")) {
*out_data = 1;
} else if (parse::compare_range_to_literal(strbegin, strend, "0")) {
*out_data = 0;
} else {
throw json_parse_error(begin, "expected a boolean", tp);
}
} else {
throw json_parse_error(begin, "expected a boolean", tp);
}
return;
} else if (value_tp.get_kind() == sint_kind || value_tp.get_kind() == uint_kind ||
value_tp.get_kind() == real_kind || value_tp.get_kind() == complex_kind) {
if (parse::parse_json_number_no_ws(begin, end, strbegin, strend)) {
parse::string_to_number(out_data, value_tp.get_type_id(), strbegin, strend, false, ectx->errmode);
} else {
throw json_parse_error(begin, "expected a number", tp);
}
return;
} else {
throw json_parse_error(begin, "expected a string", tp);
}
}
}
stringstream ss;
ss << "parse_json: unsupported dynd type \"" << tp << "\"";
throw runtime_error(ss.str());
}