本文整理汇总了C++中dynamic::typeName方法的典型用法代码示例。如果您正苦于以下问题:C++ dynamic::typeName方法的具体用法?C++ dynamic::typeName怎么用?C++ dynamic::typeName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dynamic
的用法示例。
在下文中一共展示了dynamic::typeName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
CrontabSelector::CrontabSelector(
const dynamic &d,
int64_t min_val,
int64_t max_val,
function<int64_t(const string& lc_str)> str_to_value
) : start_(min_val),
end_(max_val),
period_(1),
minVal_(min_val),
maxVal_(max_val) {
switch (d.type()) {
case dynamic::Type::INT64:
case dynamic::Type::STRING:
sortedValues_.emplace_back(parseValue(d, str_to_value));
break;
case dynamic::Type::ARRAY:
for (const auto& val : d) {
sortedValues_.emplace_back(parseValue(val, str_to_value));
}
// If somebody specifies [] for a selector, we have to silently
// accept it, since PHP's JSON library can morph {} into [], and {}
// must mean "default selector accepting all values."
break;
case dynamic::Type::OBJECT:
for (const auto& pair : d.items()) {
// Interval is first so that it doesn't accept strings like "jan"
if (pair.first == "period") {
period_ = pair.second.asInt();
if (period_ < 1 || period_ >= maxVal_ - minVal_) {
throw runtime_error(format(
"period not in [1, {}]: {}", maxVal_ - minVal_, period_
).str());
}
continue;
}
// For start & end, we are happy to accept string names
auto val = parseValue(pair.second, str_to_value);
if (pair.first == "start") {
start_ = val;
} else if (pair.first == "end") {
end_ = val;
} else {
throw runtime_error(format("Unknown key: {}", pair.first).str());
}
}
// If we got an empty object, no problem -- this selector will
// follow the default of "match everything".
break;
default:
throw runtime_error(format(
"Bad type for crontab selector: {}", d.typeName()
).str());
}
sort(sortedValues_.begin(), sortedValues_.end());
}