本文整理汇总了C++中folly::dynamic类的典型用法代码示例。如果您正苦于以下问题:C++ dynamic类的具体用法?C++ dynamic怎么用?C++ dynamic使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了dynamic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkLogic
FailoverWithExptimeRoute::FailoverWithExptimeRoute(
RouteHandleFactory<McrouterRouteHandleIf>& factory,
const folly::dynamic& json)
: failoverExptime_(60) {
checkLogic(json.isObject(), "FailoverWithExptimeRoute is not object");
std::vector<McrouterRouteHandlePtr> failoverTargets;
if (json.count("failover")) {
failoverTargets = factory.createList(json["failover"]);
}
failover_ = FailoverRoute<McrouterRouteHandleIf>(std::move(failoverTargets));
if (json.count("normal")) {
normal_ = factory.create(json["normal"]);
}
if (json.count("failover_exptime")) {
checkLogic(json["failover_exptime"].isInt(),
"failover_exptime is not integer");
failoverExptime_ = json["failover_exptime"].asInt();
}
if (json.count("settings")) {
settings_ = FailoverWithExptimeSettings(json["settings"]);
}
}
示例2: makeFailoverWithExptimeRoute
McrouterRouteHandlePtr makeFailoverWithExptimeRoute(
RouteHandleFactory<McrouterRouteHandleIf>& factory,
const folly::dynamic& json) {
checkLogic(json.isObject(), "FailoverWithExptimeRoute is not an object");
auto jnormal = json.get_ptr("normal");
checkLogic(jnormal, "FailoverWithExptimeRoute: normal not found");
auto normal = factory.create(*jnormal);
int32_t failoverExptime = 60;
if (auto jexptime = json.get_ptr("failover_exptime")) {
checkLogic(jexptime->isInt(), "FailoverWithExptimeRoute: "
"failover_exptime is not an integer");
failoverExptime = jexptime->getInt();
}
std::vector<McrouterRouteHandlePtr> failover;
if (auto jfailover = json.get_ptr("failover")) {
failover = factory.createList(*jfailover);
}
auto children = getFailoverChildren(std::move(normal),
std::move(failover),
failoverExptime);
return makeFailoverRoute(json, std::move(children));
}
示例3: LOG
ShardSplitter::ShardSplitter(const folly::dynamic& json) {
if (!json.isObject()) {
return;
}
for (const auto& it : json.items()) {
if (!it.second.isInt()) {
LOG(ERROR) << "ShardSplitter: shard_splits value is not an int for "
<< it.first.asString();
continue;
}
auto splitCnt = it.second.asInt();
if (splitCnt <= 0) {
LOG(ERROR) << "ShardSplitter: shard_splits value <= 0 '"
<< it.first.asString() << "': " << splitCnt;
} else if (static_cast<size_t>(splitCnt) > kMaxSplits) {
LOG(ERROR) << "ShardSplitter: shard_splits value > " << kMaxSplits
<< " '" << it.first.asString() << "': " << splitCnt;
shardSplits_.emplace(it.first.c_str(), kMaxSplits);
} else {
shardSplits_.emplace(it.first.c_str(), splitCnt);
}
}
}
示例4: makeHashRoute
McrouterRouteHandlePtr makeHashRoute(
const folly::dynamic& json,
std::vector<McrouterRouteHandlePtr> rh,
size_t threadId) {
std::string salt;
folly::StringPiece funcType = Ch3HashFunc::type();
if (json.isObject()) {
if (auto jsalt = json.get_ptr("salt")) {
checkLogic(jsalt->isString(), "HashRoute: salt is not a string");
salt = jsalt->getString();
}
if (auto jhashFunc = json.get_ptr("hash_func")) {
checkLogic(jhashFunc->isString(),
"HashRoute: hash_func is not a string");
funcType = jhashFunc->stringPiece();
}
}
if (funcType == Ch3HashFunc::type()) {
return makeHashRouteCh3(std::move(rh), std::move(salt));
} else if (funcType == Crc32HashFunc::type()) {
return makeHashRouteCrc32(std::move(rh), std::move(salt));
} else if (funcType == WeightedCh3HashFunc::type()) {
WeightedCh3HashFunc func{json, rh.size()};
return makeHashRouteWeightedCh3(std::move(rh), std::move(salt),
std::move(func));
} else if (funcType == ConstShardHashFunc::type()) {
return makeHashRouteConstShard(std::move(rh), std::move(salt));
} else if (funcType == "Latest") {
return makeLatestRoute(json, std::move(rh), threadId);
}
throwLogic("Unknown hash function: {}", funcType);
}
示例5: provider
ProxyConfig::ProxyConfig(proxy_t* proxy,
const folly::dynamic& json,
std::string configMd5Digest,
std::shared_ptr<PoolFactory> poolFactory)
: poolFactory_(std::move(poolFactory)),
configMd5Digest_(std::move(configMd5Digest)) {
McRouteHandleProvider provider(proxy, *proxy->destinationMap, *poolFactory_);
RouteHandleFactory<McrouterRouteHandleIf> factory(provider);
checkLogic(json.isObject(), "Config is not an object");
if (json.count("named_handles")) {
checkLogic(json["named_handles"].isArray(), "named_handles is not array");
for (const auto& it : json["named_handles"]) {
factory.create(it);
}
}
RouteSelectorMap routeSelectors;
auto jRoute = json.get_ptr("route");
auto jRoutes = json.get_ptr("routes");
checkLogic(!jRoute || !jRoutes,
"Invalid config: both 'route' and 'routes' are specified");
checkLogic(jRoute || jRoutes, "No route/routes in config");
if (jRoute) {
routeSelectors[proxy->getRouterOptions().default_route] =
std::make_shared<PrefixSelectorRoute>(factory, *jRoute);
} else { // jRoutes
checkLogic(jRoutes->isArray() || jRoutes->isObject(),
"Config: routes is not array/object");
if (jRoutes->isArray()) {
for (const auto& it : *jRoutes) {
checkLogic(it.isObject(), "RoutePolicy is not an object");
auto jCurRoute = it.get_ptr("route");
auto jAliases = it.get_ptr("aliases");
checkLogic(jCurRoute, "RoutePolicy: no route");
checkLogic(jAliases, "RoutePolicy: no aliases");
checkLogic(jAliases->isArray(), "RoutePolicy: aliases is not an array");
auto routeSelector =
std::make_shared<PrefixSelectorRoute>(factory, *jCurRoute);
for (const auto& alias : *jAliases) {
checkLogic(alias.isString(), "RoutePolicy: alias is not a string");
routeSelectors[alias.stringPiece()] = routeSelector;
}
}
} else { // object
for (const auto& it : jRoutes->items()) {
checkLogic(it.first.isString(), "RoutePolicy: alias is not a string");
routeSelectors[it.first.stringPiece()] =
std::make_shared<PrefixSelectorRoute>(factory, it.second);
}
}
}
asyncLogRoutes_ = provider.releaseAsyncLogRoutes();
proxyRoute_ = std::make_shared<ProxyRoute>(proxy, routeSelectors);
serviceInfo_ = std::make_shared<ServiceInfo>(proxy, *this);
}
示例6: lock
void Scheduler::startSurface(
SurfaceId surfaceId,
const std::string &moduleName,
const folly::dynamic &initialProps,
const LayoutConstraints &layoutConstraints,
const LayoutContext &layoutContext) {
std::lock_guard<std::mutex> lock(mutex_);
auto shadowTree =
std::make_unique<ShadowTree>(surfaceId, layoutConstraints, layoutContext);
shadowTree->setDelegate(this);
shadowTreeRegistry_.emplace(surfaceId, std::move(shadowTree));
#ifndef ANDROID
// TODO: Is this an ok place to do this?
auto serializedCommands = initialProps.find("serializedCommands");
if (serializedCommands != initialProps.items().end()) {
auto tree = TemplateRenderer::buildShadowTree(serializedCommands->second.asString(), surfaceId, folly::dynamic::object(), *componentDescriptorRegistry_);
uiManagerDidFinishTransactionWithoutLock(surfaceId, std::make_shared<SharedShadowNodeList>(SharedShadowNodeList {tree}));
// TODO: hydrate rather than replace
uiManager_->startSurface(surfaceId, moduleName, initialProps);
} else {
uiManager_->startSurface(surfaceId, moduleName, initialProps);
}
#endif
}
示例7: parseQos
void PoolFactory::parseQos(std::string parentName, const folly::dynamic& jQos,
uint64_t& qosClass, uint64_t& qosPath) {
if (!jQos.isObject()) {
MC_LOG_FAILURE(opts_, memcache::failure::Category::kInvalidConfig,
"{}: qos must be an object.", parentName);
return;
}
uint64_t prevClass = qosClass;
if (auto jClass = jQos.get_ptr("class")) {
if (jClass->isInt() && isQosClassValid(jClass->getInt())) {
qosClass = jClass->getInt();
} else {
MC_LOG_FAILURE(opts_, memcache::failure::Category::kInvalidConfig,
"{}: qos.class must be an integer in the range [0, 4]",
parentName);
}
}
if (auto jPath = jQos.get_ptr("path")) {
if (jPath->isInt() && isQosPathValid(jPath->getInt())) {
qosPath = jPath->getInt();
} else {
MC_LOG_FAILURE(opts_, memcache::failure::Category::kInvalidConfig,
"{}: qos.path must be an integer in the range [0, 3]",
parentName);
qosClass = prevClass;
}
}
}
示例8: checkLogic
std::vector<double> WeightedChHashFuncBase::parseWeights(
const folly::dynamic& json,
size_t n) {
std::vector<double> weights;
checkLogic(
json.isObject() && json.count("weights"),
"WeightedChHashFunc: not an object or no weights");
checkLogic(
json["weights"].isArray(), "WeightedChHashFunc: weights is not array");
const auto& jWeights = json["weights"];
LOG_IF(ERROR, jWeights.size() < n)
<< "WeightedChHashFunc: CONFIG IS BROKEN!!! number of weights ("
<< jWeights.size() << ") is smaller than number of servers (" << n
<< "). Missing weights are set to 0.5";
for (size_t i = 0; i < std::min(n, jWeights.size()); ++i) {
const auto& weight = jWeights[i];
checkLogic(weight.isNumber(), "WeightedChHashFunc: weight is not number");
const auto weightNum = weight.asDouble();
checkLogic(
0 <= weightNum && weightNum <= 1.0,
"WeightedChHashFunc: weight must be in range [0, 1.0]");
weights.push_back(weightNum);
}
weights.resize(n, 0.5);
return weights;
}
示例9: parseType
bool PhpConst::parseType(const folly::dynamic& cns) {
auto it = cns.find("type");
if (it != cns.items().end()) {
m_kindOf = kindOfFromDynamic(it->second);
m_cppType = typeString(it->second, false);
return true;
}
return false;
}
示例10: yogaStyleDisplayFromDynamic
YGDisplay yogaStyleDisplayFromDynamic(const folly::dynamic &value) {
assert(value.isString());
auto stringValue = value.asString();
if (stringValue == "flex") { return YGDisplayFlex; }
if (stringValue == "none") { return YGDisplayNone; }
abort();
}
示例11: yogaStylePositionTypeFromDynamic
YGPositionType yogaStylePositionTypeFromDynamic(const folly::dynamic &value) {
assert(value.isString());
auto stringValue = value.asString();
if (stringValue == "relative") { return YGPositionTypeRelative; }
if (stringValue == "absolute") { return YGPositionTypeAbsolute; }
abort();
}
示例12: makeFailoverWithExptimeRoute
McrouterRouteHandlePtr makeFailoverWithExptimeRoute(
RouteHandleFactory<McrouterRouteHandleIf>& factory,
const folly::dynamic& json) {
checkLogic(json.isObject(), "FailoverWithExptimeRoute is not an object");
McrouterRouteHandlePtr normal;
if (auto jnormal = json.get_ptr("normal")) {
normal = factory.create(*jnormal);
}
std::vector<McrouterRouteHandlePtr> failoverTargets;
if (auto jfailover = json.get_ptr("failover")) {
failoverTargets = factory.createList(*jfailover);
}
int32_t failoverExptime = 60;
if (auto jexptime = json.get_ptr("failover_exptime")) {
checkLogic(jexptime->isInt(), "FailoverWithExptimeRoute: "
"failover_exptime is not an integer");
failoverExptime = jexptime->getInt();
}
// Check if only one format is being used
checkLogic(!(json.count("settings") && // old
(json.count("failover_errors") || json.count("failover_tag"))), // new
"Use either 'settings' (old format) or 'failover_errors' / 'failover_tag'"
);
// new format
FailoverErrorsSettings failoverErrors;
bool failoverTagging = false;
if (auto jfailoverTag = json.get_ptr("failover_tag")) {
checkLogic(jfailoverTag->isBool(),
"FailoverWithExptime: failover_tag is not bool");
failoverTagging = jfailoverTag->getBool();
}
if (auto jfailoverErrors = json.get_ptr("failover_errors")) {
failoverErrors = FailoverErrorsSettings(*jfailoverErrors);
}
// old format
if (auto jsettings = json.get_ptr("settings")) {
VLOG(1) << "FailoverWithExptime: This config format is deprecated. "
"Use 'failover_errors' instead of 'settings'.";
auto oldSettings = FailoverWithExptimeSettings(*jsettings);
failoverTagging = oldSettings.failoverTagging;
failoverErrors = oldSettings.getFailoverErrors();
}
return makeFailoverWithExptimeRoute(
std::move(normal),
std::move(failoverTargets),
failoverExptime,
std::move(failoverErrors),
failoverTagging);
}
示例13: yogaStyleOverflowFromDynamic
YGOverflow yogaStyleOverflowFromDynamic(const folly::dynamic &value) {
assert(value.isString());
auto stringValue = value.asString();
if (stringValue == "visible") { return YGOverflowVisible; }
if (stringValue == "hidden") { return YGOverflowHidden; }
if (stringValue == "scroll") { return YGOverflowScroll; }
abort();
}
示例14: yogaStyleDirectionFromDynamic
YGDirection yogaStyleDirectionFromDynamic(const folly::dynamic &value) {
assert(value.isString());
auto stringValue = value.asString();
if (stringValue == "inherit") { return YGDirectionInherit; }
if (stringValue == "ltr") { return YGDirectionLTR; }
if (stringValue == "rtl") { return YGDirectionRTL; }
abort();
}
示例15: yogaStyleWrapFromDynamic
YGWrap yogaStyleWrapFromDynamic(const folly::dynamic &value) {
assert(value.isString());
auto stringValue = value.asString();
if (stringValue == "no-wrap") { return YGWrapNoWrap; }
if (stringValue == "wrap") { return YGWrapWrap; }
if (stringValue == "wrap-reverse") { return YGWrapWrapReverse; }
abort();
}