当前位置: 首页>>代码示例>>C++>>正文


C++ dynamic类代码示例

本文整理汇总了C++中dynamic的典型用法代码示例。如果您正苦于以下问题:C++ dynamic类的具体用法?C++ dynamic怎么用?C++ dynamic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了dynamic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: msgs

int MCRouterTestClient::del(const dynamic &keys, bool local,
                            dynamic &results) {

  std::vector<mcrouter_msg_t> msgs(keys.size());
  dynamic raw_results = dynamic::object;

  for (int i = 0; i < keys.size(); i ++) {
    auto key = keys[i].asString().toStdString();
    if (!local) {
      key = "/*/*/" + key;
    }
    msgs[i] = make_delete_request(key);
  }

  int ret = 0;
  bool res = issueRequests(msgs.data(), keys.size(), raw_results);
  if (res) {
    for ( auto& raw_reply : raw_results.items() ) {
      bool found = (raw_reply.second["result"] == (int) mc_res_deleted);
      results[raw_reply.first] = found;
      ret += (int) found;
    }
  }
  return ret;
}
开发者ID:0xd3adsh3ll,项目名称:mcrouter,代码行数:25,代码来源:mcrouter_test_client.cpp

示例2: bserEncode

static void bserEncode(dynamic const& dyn,
                       QueueAppender& appender,
                       const serialization_opts& opts) {
  switch (dyn.type()) {
    case dynamic::Type::NULLT:
      appender.write((int8_t)BserType::Null);
      return;
    case dynamic::Type::BOOL:
      appender.write(
          (int8_t)(dyn.getBool() ? BserType::True : BserType::False));
      return;
    case dynamic::Type::DOUBLE: {
      double dval = dyn.getDouble();
      appender.write((int8_t)BserType::Real);
      appender.write(dval);
      return;
    }
    case dynamic::Type::INT64:
      bserEncodeInt(dyn.getInt(), appender);
      return;
    case dynamic::Type::OBJECT:
      bserEncodeObject(dyn, appender, opts);
      return;
    case dynamic::Type::ARRAY:
      bserEncodeArray(dyn, appender, opts);
      return;
    case dynamic::Type::STRING:
      bserEncodeString(dyn.getString(), appender);
      return;
  }
}
开发者ID:1Hgm,项目名称:folly,代码行数:31,代码来源:Dump.cpp

示例3: validate

 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;
 }
开发者ID:AddictXQ,项目名称:folly,代码行数:32,代码来源:JSONSchema.cpp

示例4: BistroException

SettingsMap::SettingsMap(const dynamic& d) {
  if (!d.isObject()) {
    throw BistroException("Can only create settings map from an object");
  }
  for (const auto& pair : d.items()) {
    const string& name = pair.first.asString().toStdString();
    set(name, pair.second);
  }
}
开发者ID:conkeyn,项目名称:bistro,代码行数:9,代码来源:SettingsMap.cpp

示例5: start_

CrontabSelector::CrontabSelector(
  const dynamic &d,
  int64_t min_val,
  int64_t max_val,
  function<int64_t(const string& lc_str)> str_to_value
) : start_(min_val),
    end_(max_val),
    period_(1),
    minVal_(min_val),
    maxVal_(max_val) {

  switch (d.type()) {
    case dynamic::Type::INT64:
    case dynamic::Type::STRING:
      sortedValues_.emplace_back(parseValue(d, str_to_value));
      break;
    case dynamic::Type::ARRAY:
      for (const auto& val : d) {
        sortedValues_.emplace_back(parseValue(val, str_to_value));
      }
      // If somebody specifies [] for a selector, we have to silently
      // accept it, since PHP's JSON library can morph {} into [], and {}
      // must mean "default selector accepting all values."
      break;
    case dynamic::Type::OBJECT:
      for (const auto& pair : d.items()) {
        // Interval is first so that it doesn't accept strings like "jan"
        if (pair.first == "period") {
          period_ = pair.second.asInt();
          if (period_ < 1 || period_ >= maxVal_ - minVal_) {
            throw runtime_error(format(
              "period not in [1, {}]: {}", maxVal_ - minVal_, period_
            ).str());
          }
          continue;
        }
        // For start & end, we are happy to accept string names
        auto val = parseValue(pair.second, str_to_value);
        if (pair.first == "start") {
          start_ = val;
        } else if (pair.first == "end") {
          end_ = val;
        } else {
          throw runtime_error(format("Unknown key: {}", pair.first).str());
        }
      }
      // If we got an empty object, no problem -- this selector will
      // follow the default of "match everything".
      break;
    default:
      throw runtime_error(format(
        "Bad type for crontab selector: {}", d.typeName()
      ).str());
  }
  sort(sortedValues_.begin(), sortedValues_.end());
}
开发者ID:facebook,项目名称:bistro,代码行数:56,代码来源:CrontabSelector.cpp

示例6: merge_diff

dynamic dynamic::merge_diff(const dynamic& source, const dynamic& target) {
  if (!source.isObject() || source.type() != target.type()) {
    return target;
  }

  dynamic diff = object;

  // added/modified keys
  for (const auto& pair : target.items()) {
    auto it = source.find(pair.first);
    if (it == source.items().end()) {
      diff[pair.first] = pair.second;
    } else {
      diff[pair.first] = merge_diff(source[pair.first], target[pair.first]);
    }
  }

  // removed keys
  for (const auto& pair : source.items()) {
    auto it = target.find(pair.first);
    if (it == target.items().end()) {
      diff[pair.first] = nullptr;
    }
  }

  return diff;
}
开发者ID:BranchMetrics,项目名称:react-native-branch-deep-linking,代码行数:27,代码来源:dynamic.cpp

示例7: 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());
       }
     }
   }
 }
开发者ID:AddictXQ,项目名称:folly,代码行数:11,代码来源:JSONSchema.cpp

示例8: runtime_error

EpochCrontabItem::EpochCrontabItem(
  const dynamic& d, boost::local_time::time_zone_ptr tz
) : CrontabItem(tz),
    epoch_sel_(d.getDefault("epoch"), 0, std::numeric_limits<time_t>::max()) {

  if (d.size() != 1) {
    throw runtime_error(
      "Can only have the 'epoch' key: " + folly::toJson(d).toStdString()
    );
  }
}
开发者ID:conkeyn,项目名称:bistro,代码行数:11,代码来源:EpochCrontabItem.cpp

示例9: checkItemParseError

void checkItemParseError(
    // real_k can differ from err_k, which is typically coerced to string
    dynamic d, Fn fn, dynamic real_k, dynamic err_k, std::string re) {
  DynamicParser p(DynamicParser::OnError::RECORD, &d);
  fn(p);
  auto errors = p.releaseErrors();
  auto error = errors.at("nested").at(err_k);
  EXPECT_EQ(d.at(real_k), error.at("value"));
  EXPECT_PCRE_MATCH(re, error.at("error").getString());
  EXPECT_EQ(dynamic(dynamic::object("nested", dynamic::object(
    err_k, dynamic::object("value", d.at(real_k))("error", error.at("error"))
  ))), errors);
}
开发者ID:1Hgm,项目名称:folly,代码行数:13,代码来源:DynamicParserTest.cpp

示例10: isInt

bool dynamic::operator==(dynamic const& o) const {
  if (type() != o.type()) {
    if (isNumber() && o.isNumber()) {
      auto& integ = isInt() ? *this : o;
      auto& doubl = isInt() ? o     : *this;
      return integ.asInt() == doubl.asDouble();
    }
    return false;
  }

#define FB_X(T) return *getAddress<T>() == *o.getAddress<T>();
  FB_DYNAMIC_APPLY(type_, FB_X);
#undef FB_X
}
开发者ID:1Hgm,项目名称:folly,代码行数:14,代码来源:dynamic.cpp

示例11: TEST

TEST(Dynamic, At) {
  const dynamic cd = dynamic::object("key1", make_long_string());
  dynamic dd = dynamic::object("key1", make_long_string());
  dynamic md = dynamic::object("key1", make_long_string());

  dynamic ds(make_long_string());
  EXPECT_EQ(ds, cd.at("key1"));
  EXPECT_EQ(ds, cd.at("key1"));

  dd.at("key1").getString() += " hello";
  EXPECT_EQ(dynamic(make_long_string() + " hello"), dd.at("key1"));
  EXPECT_EQ(dynamic(make_long_string() + " hello"), dd.at("key1"));

  EXPECT_EQ(ds, std::move(md).at("key1"));
  EXPECT_NE(ds, md.at("key1"));
}
开发者ID:jianw851,项目名称:folly,代码行数:16,代码来源:DynamicTest.cpp

示例12: AllOfValidator

 AllOfValidator(SchemaValidatorContext& context, const dynamic& schema) {
   if (schema.isArray()) {
     for (const auto& item : schema) {
       validators_.emplace_back(SchemaValidator::make(context, item));
     }
   }
 }
开发者ID:AddictXQ,项目名称:folly,代码行数:7,代码来源:JSONSchema.cpp

示例13: RequiredValidator

 explicit RequiredValidator(const dynamic& schema) {
   if (schema.isArray()) {
     for (const auto& item : schema) {
       if (item.isString()) {
         properties_.emplace_back(item.getString());
       }
     }
   }
 }
开发者ID:AddictXQ,项目名称:folly,代码行数:9,代码来源:JSONSchema.cpp

示例14: bserEncodeArraySimple

static void bserEncodeArraySimple(dynamic const& dyn,
                                  QueueAppender& appender,
                                  const serialization_opts& opts) {
  appender.write((int8_t)BserType::Array);
  bserEncodeInt(dyn.size(), appender);
  for (const auto& ele : dyn) {
    bserEncode(ele, appender, opts);
  }
}
开发者ID:1Hgm,项目名称:folly,代码行数:9,代码来源:Dump.cpp

示例15: TEST

TEST(Dynamic, At) {
  const dynamic cd = dynamic::object("key1", make_long_string());
  dynamic dd = dynamic::object("key1", make_long_string());
  dynamic md = dynamic::object("key1", make_long_string());

  dynamic ds(make_long_string());
  EXPECT_EQ(ds, cd.at("key1"));
  EXPECT_EQ(ds, cd.at("key1"));

  dd.at("key1").getString() += " hello";
  EXPECT_EQ(dynamic(make_long_string() + " hello"), dd.at("key1"));
  EXPECT_EQ(dynamic(make_long_string() + " hello"), dd.at("key1"));

  EXPECT_EQ(ds, std::move(md).at("key1")); // move available, but not performed
  EXPECT_EQ(ds, md.at("key1"));
  dynamic moved = std::move(md).at("key1"); // move performed
  EXPECT_EQ(ds, moved);
  EXPECT_NE(ds, md.at("key1"));
}
开发者ID:charsyam,项目名称:folly,代码行数:19,代码来源:DynamicTest.cpp


注:本文中的dynamic类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。