本文整理汇总了C++中folly::dynamic::items方法的典型用法代码示例。如果您正苦于以下问题:C++ dynamic::items方法的具体用法?C++ dynamic::items怎么用?C++ dynamic::items使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类folly::dynamic
的用法示例。
在下文中一共展示了dynamic::items方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fromDynamicInner
JSValueRef Value::fromDynamicInner(JSContextRef ctx, const folly::dynamic& obj) {
switch (obj.type()) {
// For primitive types (and strings), just create and return an equivalent JSValue
case folly::dynamic::Type::NULLT:
return JSC_JSValueMakeNull(ctx);
case folly::dynamic::Type::BOOL:
return JSC_JSValueMakeBoolean(ctx, obj.getBool());
case folly::dynamic::Type::DOUBLE:
return JSC_JSValueMakeNumber(ctx, obj.getDouble());
case folly::dynamic::Type::INT64:
return JSC_JSValueMakeNumber(ctx, obj.asDouble());
case folly::dynamic::Type::STRING:
return JSC_JSValueMakeString(ctx, String(ctx, obj.getString().c_str()));
case folly::dynamic::Type::ARRAY: {
// Collect JSValue for every element in the array
JSValueRef vals[obj.size()];
for (size_t i = 0; i < obj.size(); ++i) {
vals[i] = fromDynamicInner(ctx, obj[i]);
}
// Create a JSArray with the values
JSValueRef arr = JSC_JSObjectMakeArray(ctx, obj.size(), vals, nullptr);
return arr;
}
case folly::dynamic::Type::OBJECT: {
// Create an empty object
JSObjectRef jsObj = JSC_JSObjectMake(ctx, nullptr, nullptr);
// Create a JSValue for each of the object's children and set them in the object
for (auto it = obj.items().begin(); it != obj.items().end(); ++it) {
JSC_JSObjectSetProperty(
ctx,
jsObj,
String(ctx, it->first.asString().c_str()),
fromDynamicInner(ctx, it->second),
kJSPropertyAttributeNone,
nullptr);
}
return jsObj;
}
default:
// Assert not reached
LOG(FATAL) << "Trying to convert a folly object of unsupported type.";
return JSC_JSValueMakeNull(ctx);
}
}
示例2: 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);
}
}
}
示例3: UpdateProperties
void HyperlinkViewManager::UpdateProperties(ShadowNodeBase* nodeToUpdate, const folly::dynamic& reactDiffMap)
{
auto button = nodeToUpdate->GetView().as<winrt::HyperlinkButton>();
if (button == nullptr)
return;
for (const auto& pair : reactDiffMap.items())
{
const std::string& propertyName = pair.first.getString();
const folly::dynamic& propertyValue = pair.second;
if (propertyName == "disabled")
{
if (propertyValue.isBool())
button.IsEnabled(!propertyValue.asBool());
}
else if (propertyName == "tooltip")
{
if (propertyValue.isString())
{
winrt::TextBlock tooltip = winrt::TextBlock();
tooltip.Text(asHstring(propertyValue));
winrt::ToolTipService::SetToolTip(button, tooltip);
}
}
else if (propertyName == "url")
{
winrt::Uri myUri(asHstring(propertyValue));
button.NavigateUri(myUri);
}
}
Super::UpdateProperties(nodeToUpdate, reactDiffMap);
}
示例4: startSurface
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
}
示例5: UpdateProperties
void SwitchViewManager::UpdateProperties(ShadowNodeBase* nodeToUpdate, const folly::dynamic& reactDiffMap)
{
auto toggleSwitch = nodeToUpdate->GetView().as<winrt::ToggleSwitch>();
if (toggleSwitch == nullptr)
return;
for (const auto& pair : reactDiffMap.items())
{
const std::string& propertyName = pair.first.getString();
const folly::dynamic& propertyValue = pair.second;
if (propertyName == "disabled")
{
if (propertyValue.isBool())
toggleSwitch.IsEnabled(!propertyValue.asBool());
else if (pair.second.isNull())
toggleSwitch.ClearValue(winrt::Control::IsEnabledProperty());
}
else if (propertyName == "value")
{
if (propertyValue.isBool())
toggleSwitch.IsOn(propertyValue.asBool());
else if (pair.second.isNull())
toggleSwitch.ClearValue(winrt::ToggleSwitch::IsOnProperty());
}
}
Super::UpdateProperties(nodeToUpdate, reactDiffMap);
}
示例6: UpdateProperties
void CheckBoxViewManager::UpdateProperties(ShadowNodeBase* nodeToUpdate, const folly::dynamic& reactDiffMap)
{
auto checkbox = nodeToUpdate->GetView().as<winrt::CheckBox>();
if (checkbox == nullptr)
return;
for (const auto& pair : reactDiffMap.items())
{
const std::string& propertyName = pair.first.getString();
const folly::dynamic& propertyValue = pair.second;
if (propertyName == "disabled")
{
if (propertyValue.isBool())
checkbox.IsEnabled(!propertyValue.asBool());
else if (pair.second.isNull())
checkbox.ClearValue(winrt::Control::IsEnabledProperty());
}
else if (propertyName == "checked")
{
if (propertyValue.isBool())
checkbox.IsChecked(propertyValue.asBool());
else if (pair.second.isNull())
checkbox.ClearValue(winrt::Primitives::ToggleButton::IsCheckedProperty());
}
}
Super::UpdateProperties(nodeToUpdate, reactDiffMap);
}
示例7: dynamic_to_variant
static Variant dynamic_to_variant(const folly::dynamic& v) {
switch (v.type()) {
case folly::dynamic::Type::NULLT:
return init_null();
case folly::dynamic::Type::BOOL:
return v.asBool();
case folly::dynamic::Type::DOUBLE:
return v.asDouble();
case folly::dynamic::Type::INT64:
return v.asInt();
case folly::dynamic::Type::STRING:
return v.data();
case folly::dynamic::Type::ARRAY:
case folly::dynamic::Type::OBJECT:
ArrayInit arr_init(v.size(), ArrayInit::Mixed{});
for (auto& item : v.items()) {
arr_init.add(dynamic_to_variant(item.first),
dynamic_to_variant(item.second));
}
Array ret = arr_init.toArray();
// Sort the array since folly::dynamic has a tendency to iterate from
// back to front. This way a var_dump of the array, for example, looks
// ordered.
ret.sort(Array::SortNaturalAscending, true, false);
return ret;
}
not_reached();
}
示例8: ini_on_update
bool ini_on_update(const folly::dynamic& value,
std::map<std::string, std::string>& p) {
INI_ASSERT_ARR(value);
for (auto& pair : value.items()) {
p[pair.first.data()] = pair.second.data();
}
return true;
}
示例9:
RouteNextHopsMulti
RouteNextHopsMulti::fromFollyDynamic(const folly::dynamic& json) {
RouteNextHopsMulti nh;
for (const auto& pair : json.items()) {
nh.update(ClientID(pair.first.asInt()),
RouteNextHopEntry::fromFollyDynamic(pair.second));
}
return nh;
}
示例10: 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;
}
示例11: logic_error
PhpClass::PhpClass(const folly::dynamic &c) :
m_class(c),
m_idlName(c["name"].asString()),
m_phpName(toPhpName(m_idlName)),
m_cppName(toCppName(m_idlName)),
m_flags(parseFlags(m_class["flags"])),
m_desc(getFollyDynamicDefaultString(c, "desc", "")) {
auto ifacesIt = m_class.find("ifaces");
if (ifacesIt != m_class.items().end()) {
auto ifaces = ifacesIt->second;
if (!ifaces.isArray()) {
throw std::logic_error(
folly::format("Class {0}.ifaces field must be an array",
m_idlName).str()
);
}
for (auto &interface : ifaces) {
m_ifaces.push_back(interface.asString());
}
}
for (auto const& f : c["funcs"]) {
PhpFunc func(f, getCppName());
m_methods.push_back(func);
}
if (c.find("consts") != c.items().end()) {
for (auto const& cns : c["consts"]) {
PhpConst cons(cns, getCppName());
m_constants.push_back(cons);
}
}
if (c.find("properties") != c.items().end()) {
for (auto const& prp : c["properties"]) {
PhpProp prop(prp, getCppName());
m_properties.push_back(prop);
}
}
}
示例12: inferType
bool PhpConst::inferType(const folly::dynamic& cns) {
auto it = cns.find("value");
if (it != cns.items().end()) {
m_kindOf = kindOfFromValue(it->second);
auto typeIt = g_typeMap.find((int)m_kindOf);
if (typeIt != g_typeMap.end()) {
m_cppType = typeIt->second;
return true;
}
}
return false;
}
示例13: getFollyDynamicDefaultString
static fbstring getFollyDynamicDefaultString(const folly::dynamic& d,
const fbstring& key,
const fbstring& def) {
auto it = d.find(key);
if (it == d.items().end()) {
return def;
}
auto val = it->second;
if (val.isNull()) {
return def;
}
return val.asString();
}
示例14: buildShadowTree
SharedShadowNode UITemplateProcessor::buildShadowTree(
const std::string &jsonStr,
Tag rootTag,
const folly::dynamic ¶ms,
const ComponentDescriptorRegistry &componentDescriptorRegistry,
const NativeModuleRegistry &nativeModuleRegistry,
const std::shared_ptr<const ReactNativeConfig> reactNativeConfig) {
LOG(INFO)
<< "(strt) UITemplateProcessor inject hardcoded 'server rendered' view tree";
std::string content = jsonStr;
for (const auto ¶m : params.items()) {
const auto &key = param.first.asString();
size_t start_pos = content.find(key);
if (start_pos != std::string::npos) {
content.replace(start_pos, key.length(), param.second.asString());
}
}
auto parsed = folly::parseJson(content);
auto commands = parsed["commands"];
std::vector<SharedShadowNode> nodes(commands.size() * 2);
std::vector<folly::dynamic> registers(32);
for (const auto &command : commands) {
try {
if (DEBUG_FLY) {
LOG(INFO) << "try to run command " << folly::toJson(command);
}
auto ret = runCommand(
command,
rootTag,
nodes,
registers,
componentDescriptorRegistry,
nativeModuleRegistry,
reactNativeConfig);
if (ret != nullptr) {
return ret;
}
} catch (const std::exception &e) {
LOG(ERROR) << " >>> Exception <<< running previous command '"
<< folly::toJson(command) << "': '" << e.what() << "'";
}
}
LOG(ERROR) << "react ui template missing returnRoot command :(";
throw std::runtime_error(
"Missing returnRoot command in template content:\n" + content);
return SharedShadowNode{};
}
示例15: if
LocationObserverOptions(const folly::dynamic& options)
{
if (!options.empty())
{
for (auto& opt : options.items())
{
if (opt.first == "timeout")
timeout = opt.second.asDouble();
else if (opt.first == "maximumAge")
maxAge = opt.second.asDouble();
else if (opt.first == "enableHighAccuracy")
highAccuracy = opt.second.asBool();
else if (opt.first == "distanceFilter")
distanceFilter = opt.second.asDouble();
}
}
}