本文整理汇总了C++中dynamic::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ dynamic::empty方法的具体用法?C++ dynamic::empty怎么用?C++ dynamic::empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dynamic
的用法示例。
在下文中一共展示了dynamic::empty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BistroException
JobBackoffSettings::JobBackoffSettings(const dynamic& d) : repeat_(false) {
if (!d.isArray()) {
throw BistroException("Expected array; got ", folly::toJson(d));
}
if (d.empty()) {
throw BistroException("Backoff setting is empty");
}
for (const auto& item : d) {
if (item.isInt()) {
int val = item.asInt();
if (val <= 0) {
throw BistroException("Backoff times must be positive: ", val);
}
if (!values_.empty()) {
if (values_.back() == val) {
throw BistroException("Duplicate backoff time: ", val);
}
if (values_.back() > val) {
throw BistroException("Backoff times must be in increasing order");
}
}
values_.push_back(val);
} else if (item.isString()) {
const auto& s = item.asString();
if (s == "repeat") {
if (values_.empty()) {
throw BistroException("No backoff interval given before 'repeat'");
}
repeat_ = true;
} else if (s != "fail") {
throw BistroException("Unknown string in backoff settings: ", s);
}
break;
} else {
throw BistroException("Invalid backoff value: ", folly::toJson(item));
}
}
}
示例2: loadSchema
void SchemaValidator::loadSchema(SchemaValidatorContext& context,
const dynamic& schema) {
if (!schema.isObject() || schema.empty()) {
return;
}
// Check for $ref, if we have one we won't apply anything else. Refs are
// pointers to other parts of the json, e.g. #/foo/bar points to the schema
// located at root["foo"]["bar"].
if (const auto* p = schema.get_ptr("$ref")) {
// We only support absolute refs, i.e. those starting with '#'
if (p->isString() && p->stringPiece()[0] == '#') {
auto it = context.refs.find(p->getString());
if (it != context.refs.end()) {
validators_.emplace_back(make_unique<RefValidator>(it->second));
return;
}
// This is a ref, but we haven't loaded it yet. Find where it is based on
// the root schema.
std::vector<std::string> parts;
split("/", p->stringPiece(), parts);
const auto* s = &context.schema; // First part is '#'
for (size_t i = 1; s && i < parts.size(); ++i) {
// Per the standard, we must replace ~1 with / and then ~0 with ~
boost::replace_all(parts[i], "~1", "/");
boost::replace_all(parts[i], "~0", "~");
if (s->isObject()) {
s = s->get_ptr(parts[i]);
continue;
}
if (s->isArray()) {
try {
const size_t pos = to<size_t>(parts[i]);
if (pos < s->size()) {
s = s->get_ptr(pos);
continue;
}
} catch (const std::range_error& e) {
// ignore
}
}
break;
}
// If you have a self-recursive reference, this avoids getting into an
// infinite recursion, where we try to load a schema that just references
// itself, and then we try to load it again, and so on.
// Instead we load a pointer to the schema into the refs, so that any
// future references to it will just see that pointer and won't try to
// keep parsing further.
if (s) {
auto v = make_unique<SchemaValidator>();
context.refs[p->getString()] = v.get();
v->loadSchema(context, *s);
validators_.emplace_back(std::move(v));
return;
}
}
}
// Numeric validators
if (const auto* p = schema.get_ptr("multipleOf")) {
validators_.emplace_back(make_unique<MultipleOfValidator>(*p));
}
if (const auto* p = schema.get_ptr("maximum")) {
validators_.emplace_back(
make_unique<ComparisonValidator>(*p,
schema.get_ptr("exclusiveMaximum"),
ComparisonValidator::Type::MAX));
}
if (const auto* p = schema.get_ptr("minimum")) {
validators_.emplace_back(
make_unique<ComparisonValidator>(*p,
schema.get_ptr("exclusiveMinimum"),
ComparisonValidator::Type::MIN));
}
// String validators
if (const auto* p = schema.get_ptr("maxLength")) {
validators_.emplace_back(
make_unique<SizeValidator<std::greater_equal<int64_t>>>(
*p, dynamic::Type::STRING));
}
if (const auto* p = schema.get_ptr("minLength")) {
validators_.emplace_back(
make_unique<SizeValidator<std::less_equal<int64_t>>>(
*p, dynamic::Type::STRING));
}
if (const auto* p = schema.get_ptr("pattern")) {
validators_.emplace_back(make_unique<StringPatternValidator>(*p));
}
// Array validators
const auto* items = schema.get_ptr("items");
const auto* additionalItems = schema.get_ptr("additionalItems");
if (items || additionalItems) {
validators_.emplace_back(
make_unique<ArrayItemsValidator>(context, items, additionalItems));
}
if (const auto* p = schema.get_ptr("maxItems")) {
//.........这里部分代码省略.........