本文整理汇总了C++中dynamic::isArray方法的典型用法代码示例。如果您正苦于以下问题:C++ dynamic::isArray方法的具体用法?C++ dynamic::isArray怎么用?C++ dynamic::isArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dynamic
的用法示例。
在下文中一共展示了dynamic::isArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AllOfValidator
AllOfValidator(SchemaValidatorContext& context, const dynamic& schema) {
if (schema.isArray()) {
for (const auto& item : schema) {
validators_.emplace_back(SchemaValidator::make(context, item));
}
}
}
示例2: makeError
Optional<SchemaError> validate(ValidationContext& vc,
const dynamic& value) const override {
if (!value.isArray()) {
return none;
}
if (itemsValidator_) {
for (const auto& v : value) {
if (auto se = vc.validate(itemsValidator_.get(), v)) {
return se;
}
}
return none;
}
size_t pos = 0;
for (; pos < value.size() && pos < itemsValidators_.size(); ++pos) {
if (auto se = vc.validate(itemsValidators_[pos].get(), value[pos])) {
return se;
}
}
if (!allowAdditionalItems_ && pos < value.size()) {
return makeError("no more additional items", value);
}
if (additionalItemsValidator_) {
for (; pos < value.size(); ++pos) {
if (auto se =
vc.validate(additionalItemsValidator_.get(), value[pos])) {
return se;
}
}
}
return none;
}
示例3: RequiredValidator
explicit RequiredValidator(const dynamic& schema) {
if (schema.isArray()) {
for (const auto& item : schema) {
if (item.isString()) {
properties_.emplace_back(item.getString());
}
}
}
}
示例4: TypeValidator
explicit TypeValidator(const dynamic& schema) {
if (schema.isString()) {
addType(schema.stringPiece());
} else if (schema.isArray()) {
for (const auto& item : schema) {
if (item.isString()) {
addType(item.stringPiece());
}
}
}
}
示例5: 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));
}
}
}
示例6: makeUnexpected
// static
Expected<json_patch, json_patch::parse_error> json_patch::try_parse(
dynamic const& obj) noexcept {
using err_code = parse_error_code;
json_patch patch;
if (!obj.isArray()) {
return makeUnexpected(parse_error{err_code::invalid_shape, &obj});
}
for (auto const& elem : obj) {
if (!elem.isObject()) {
return makeUnexpected(parse_error{err_code::invalid_shape, &elem});
}
auto const* op_ptr = elem.get_ptr(kOpTag);
if (!op_ptr) {
return makeUnexpected(parse_error{err_code::missing_op, &elem});
}
if (!op_ptr->isString()) {
return makeUnexpected(parse_error{err_code::malformed_op, &elem});
}
auto const op_str = op_ptr->asString();
patch_operation op;
// extract 'from' attribute
{
auto const* from_ptr = elem.get_ptr(kFromTag);
if (from_ptr) {
if (!from_ptr->isString()) {
return makeUnexpected(parse_error{err_code::invalid_shape, &elem});
}
auto json_ptr = json_pointer::try_parse(from_ptr->asString());
if (!json_ptr.hasValue()) {
return makeUnexpected(
parse_error{err_code::malformed_from_attr, &elem});
}
op.from = json_ptr.value();
}
}
// extract 'path' attribute
{
auto const* path_ptr = elem.get_ptr(kPathTag);
if (!path_ptr) {
return makeUnexpected(parse_error{err_code::missing_path_attr, &elem});
}
if (!path_ptr->isString()) {
return makeUnexpected(
parse_error{err_code::malformed_path_attr, &elem});
}
auto const json_ptr = json_pointer::try_parse(path_ptr->asString());
if (!json_ptr.hasValue()) {
return makeUnexpected(
parse_error{err_code::malformed_path_attr, &elem});
}
op.path = json_ptr.value();
}
// extract 'value' attribute
{
auto const* val_ptr = elem.get_ptr(kValueTag);
if (val_ptr) {
op.value = *val_ptr;
}
}
// check mandatory attributes - different per operation
// NOTE: per RFC, the surplus attributes (e.g. 'from' with 'add')
// should be simply ignored
using op_code = patch_operation_code;
if (op_str == kOperationTest) {
if (!op.value) {
return makeUnexpected(parse_error{err_code::missing_value_attr, &elem});
}
op.op_code = op_code::test;
} else if (op_str == kOperationRemove) {
op.op_code = op_code::remove;
} else if (op_str == kOperationAdd) {
if (!op.value) {
return makeUnexpected(parse_error{err_code::missing_value_attr, &elem});
}
op.op_code = op_code::add;
} else if (op_str == kOperationReplace) {
if (!op.value) {
return makeUnexpected(parse_error{err_code::missing_value_attr, &elem});
}
op.op_code = op_code::replace;
} else if (op_str == kOperationMove) {
if (!op.from) {
return makeUnexpected(parse_error{err_code::missing_from_attr, &elem});
}
// is from a proper prefix to path?
if (op.from->is_prefix_of(op.path)) {
return makeUnexpected(
parse_error{err_code::overlapping_pointers, &elem});
}
op.op_code = op_code::move;
} else if (op_str == kOperationCopy) {
if (!op.from) {
//.........这里部分代码省略.........