本文整理汇总了C++中folly::dynamic类的典型用法代码示例。如果您正苦于以下问题:C++ dynamic类的具体用法?C++ dynamic怎么用?C++ dynamic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了dynamic类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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"]);
}
}
开发者ID:apinski-cavium,项目名称:mcrouter,代码行数:29,代码来源:FailoverWithExptimeRoute.cpp
示例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));
}
开发者ID:tempbottle,项目名称:mcrouter,代码行数:25,代码来源:FailoverWithExptimeRoute.cpp
示例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);
}
}
}
开发者ID:ConfusedReality,项目名称:mcrouter,代码行数:25,代码来源:ShardSplitter.cpp
示例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);
}
开发者ID:ConfusedReality,项目名称:mcrouter,代码行数:34,代码来源:HashRoute.cpp
示例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);
}
开发者ID:riseofthetigers,项目名称:mcrouter,代码行数:60,代码来源:ProxyConfig.cpp
示例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
}
开发者ID:jasontproject,项目名称:react-native,代码行数:28,代码来源:Scheduler.cpp
示例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;
}
}
}
开发者ID:easyfmxu,项目名称:mcrouter,代码行数:29,代码来源:PoolFactory.cpp
示例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;
}
开发者ID:facebook,项目名称:mcrouter,代码行数:26,代码来源:WeightedChHashFuncBase.cpp
示例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;
}
开发者ID:abacaxinho,项目名称:hhvm,代码行数:9,代码来源:idl.cpp
示例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();
}
开发者ID:4Catalyzer,项目名称:react-native,代码行数:9,代码来源:yogaValuesConversions.cpp
示例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();
}
开发者ID:4Catalyzer,项目名称:react-native,代码行数:9,代码来源:yogaValuesConversions.cpp
示例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);
}
开发者ID:jq,项目名称:mcrouter,代码行数:56,代码来源:FailoverWithExptimeRoute.cpp
示例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();
}
开发者ID:4Catalyzer,项目名称:react-native,代码行数:10,代码来源:yogaValuesConversions.cpp
示例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();
}
开发者ID:4Catalyzer,项目名称:react-native,代码行数:10,代码来源:yogaValuesConversions.cpp
示例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();
}
开发者ID:4Catalyzer,项目名称:react-native,代码行数:10,代码来源:yogaValuesConversions.cpp
示例16: makeRateLimitRoute
McrouterRouteHandlePtr makeRateLimitRoute(
RouteHandleFactory<McrouterRouteHandleIf>& factory,
const folly::dynamic& json) {
checkLogic(json.isObject(), "RateLimitRoute is not an object");
auto jtarget = json.get_ptr("target");
checkLogic(jtarget, "RateLimitRoute: target not found");
auto target = factory.create(*jtarget);
auto jrates = json.get_ptr("rates");
checkLogic(jrates, "RateLimitRoute: rates not found");
return makeRateLimitRoute(std::move(target), RateLimiter(*jrates));
}
开发者ID:ConfusedReality,项目名称:mcrouter,代码行数:11,代码来源:RateLimitRoute.cpp
示例17: yogaStyleFlexDirectionFromDynamic
YGFlexDirection yogaStyleFlexDirectionFromDynamic(const folly::dynamic &value) {
assert(value.isString());
auto stringValue = value.asString();
if (stringValue == "column") { return YGFlexDirectionColumn; }
if (stringValue == "column-reverse") { return YGFlexDirectionColumnReverse; }
if (stringValue == "row") { return YGFlexDirectionRow; }
if (stringValue == "row-reverse") { return YGFlexDirectionRowReverse; }
abort();
}
开发者ID:4Catalyzer,项目名称:react-native,代码行数:11,代码来源:yogaValuesConversions.cpp
示例18: parsePool
PoolFactory::PoolJson PoolFactory::parsePool(const folly::dynamic& json) {
checkLogic(json.isString() || json.isObject(),
"Pool should be a string (name of pool) or an object");
if (json.isString()) {
return parseNamedPool(json.stringPiece());
}
auto jname = json.get_ptr("name");
checkLogic(jname && jname->isString(), "Pool should have string 'name'");
pools_.emplace(jname->stringPiece(), std::make_pair(json, PoolState::NEW));
return parseNamedPool(jname->stringPiece());
}
开发者ID:Fierralin,项目名称:mcrouter,代码行数:11,代码来源:PoolFactory.cpp
示例19: parsePool
std::shared_ptr<ClientPool>
PoolFactory::parsePool(const folly::dynamic& json) {
checkLogic(json.isString() || json.isObject(),
"Pool should be a string (name of pool) or an object");
if (json.isString()) {
return parsePool(json.stringPiece().str(), json);
} else {
auto name = json.get_ptr("name");
checkLogic(name && name->isString(), "Pool should have string 'name'");
return parsePool(name->stringPiece().str(), json);
}
}
开发者ID:easyfmxu,项目名称:mcrouter,代码行数:12,代码来源:PoolFactory.cpp
示例20: yogaStyleOptionalFloatFromDynamic
YGFloatOptional yogaStyleOptionalFloatFromDynamic(const folly::dynamic &value) {
if (value.isNumber()) {
return YGFloatOptional(value.asDouble());
} else if (value.isString()) {
const auto stringValue = value.asString();
if (stringValue == "auto") {
return YGFloatOptional();
}
}
abort();
}
开发者ID:4Catalyzer,项目名称:react-native,代码行数:12,代码来源:yogaValuesConversions.cpp
注:本文中的folly::dynamic类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论