本文整理汇总了C++中dynamic::try_get_ptr方法的典型用法代码示例。如果您正苦于以下问题:C++ dynamic::try_get_ptr方法的具体用法?C++ dynamic::try_get_ptr怎么用?C++ dynamic::try_get_ptr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dynamic
的用法示例。
在下文中一共展示了dynamic::try_get_ptr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeUnexpected
// clang-format off
Expected<Unit, json_patch::patch_application_error>
// clang-format on
json_patch::apply(dynamic& obj) {
using op_code = patch_operation_code;
using error_code = patch_application_error_code;
using error = patch_application_error;
for (auto&& it : enumerate(ops_)) {
auto const index = it.index;
auto const& op = *it;
auto resolved_path = obj.try_get_ptr(op.path);
switch (op.op_code) {
case op_code::test:
if (!resolved_path.hasValue()) {
return folly::makeUnexpected(
error{error_code::path_not_found, index});
}
if (*resolved_path->value != *op.value) {
return folly::makeUnexpected(error{error_code::test_failed, index});
}
break;
case op_code::remove: {
auto ret = do_remove(resolved_path);
if (ret.hasError()) {
return makeUnexpected(error{ret.error(), index});
}
break;
}
case op_code::add: {
DCHECK(op.value.hasValue());
auto ret = do_add(resolved_path, *op.value, op.path.tokens().back());
if (ret.hasError()) {
return makeUnexpected(error{ret.error(), index});
}
break;
}
case op_code::replace: {
if (resolved_path.hasValue()) {
*resolved_path->value = *op.value;
} else {
return folly::makeUnexpected(
error{error_code::path_not_found, index});
}
break;
}
case op_code::move: {
DCHECK(op.from.hasValue());
auto resolved_from = obj.try_get_ptr(*op.from);
if (!resolved_from.hasValue()) {
return makeUnexpected(error{error_code::from_not_found, index});
}
{
auto ret = do_add(
resolved_path, *resolved_from->value, op.path.tokens().back());
if (ret.hasError()) {
return makeUnexpected(error{ret.error(), index});
}
}
{
auto ret = do_remove(resolved_from);
if (ret.hasError()) {
return makeUnexpected(error{ret.error(), index});
}
}
break;
}
case op_code::copy: {
DCHECK(op.from.hasValue());
auto const resolved_from = obj.try_get_ptr(*op.from);
if (!resolved_from.hasValue()) {
return makeUnexpected(error{error_code::from_not_found, index});
}
{
DCHECK(!op.path.tokens().empty());
auto ret = do_add(
resolved_path, *resolved_from->value, op.path.tokens().back());
if (ret.hasError()) {
return makeUnexpected(error{ret.error(), index});
}
}
break;
}
case op_code::invalid: {
DCHECK(false);
return makeUnexpected(error{error_code::other, index});
}
}
}
return unit;
}