本文整理汇总了C++中dynamic::size方法的典型用法代码示例。如果您正苦于以下问题:C++ dynamic::size方法的具体用法?C++ dynamic::size怎么用?C++ dynamic::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dynamic
的用法示例。
在下文中一共展示了dynamic::size方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: del
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;
}
示例2: makeError
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;
}
示例3: GenStat
static void GenStat(Stat& stat, const dynamic& v) {
switch (v.type()) {
case dynamic::ARRAY:
{
for (auto &i : v)
GenStat(stat, i);
stat.arrayCount++;
stat.elementCount += v.size();
}
break;
case dynamic::OBJECT:
{
auto p = v.items();
for (auto& i : p) {
GenStat(stat, i.second);
stat.stringLength += i.first.size();
}
stat.objectCount++;
stat.memberCount += v.size();
stat.stringCount += v.size();
}
break;
case dynamic::STRING:
stat.stringCount++;
stat.stringLength += v.size();
break;
case dynamic::INT64:
case dynamic::DOUBLE:
stat.numberCount++;
break;
case dynamic::BOOL:
if (v.getBool())
stat.trueCount++;
else
stat.falseCount++;
break;
case dynamic::NULLT:
stat.nullCount++;
break;
}
}
示例4: 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);
}
}
示例5: 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()
);
}
}
示例6: get
int MCRouterTestClient::get(const dynamic &keys,
dynamic &results) {
std::vector<mcrouter_msg_t> msgs(keys.size());
int ret = 0;
dynamic raw_results = dynamic::object;
for (int i = 0; i < keys.size(); i ++) {
msgs[i] = make_get_request(keys[i].asString().toStdString());
}
bool res = issueRequests(msgs.data(), keys.size(), raw_results);
assert(res);
for ( auto & raw_reply : raw_results.items() ) {
if (raw_reply.second["result"] == (int) mc_res_found) {
results[raw_reply.first] = raw_reply.second["value"];
ret ++;
}
}
return ret;
}
示例7: set
int MCRouterTestClient::set(const dynamic &kv_pairs,
dynamic &results) {
std::vector<mcrouter_msg_t> msgs(kv_pairs.size());
int i = 0;
dynamic raw_results = dynamic::object;
for (auto &kv_pair : kv_pairs.items()) {
msgs[i] = make_set_request(kv_pair.first.asString().toStdString(),
kv_pair.second.asString().toStdString());
i ++;
}
int ret = 0;
bool res = issueRequests(msgs.data(), kv_pairs.size(), raw_results);
if (res) {
for ( auto& raw_reply : raw_results.items()) {
bool stored = (raw_reply.second["result"] == (int) mc_res_stored);
results[raw_reply.first] = stored;
ret += (int) stored;
}
}
return ret;
}
示例8: bserEncodeObject
static void bserEncodeObject(dynamic const& dyn,
QueueAppender& appender,
const serialization_opts& opts) {
appender.write((int8_t)BserType::Object);
bserEncodeInt(dyn.size(), appender);
if (opts.sort_keys) {
std::vector<std::pair<dynamic, dynamic>> sorted(dyn.items().begin(),
dyn.items().end());
std::sort(sorted.begin(), sorted.end());
for (const auto& item : sorted) {
bserEncode(item.first, appender, opts);
bserEncode(item.second, appender, opts);
}
} else {
for (const auto& item : dyn.items()) {
bserEncode(item.first, appender, opts);
bserEncode(item.second, appender, opts);
}
}
}
示例9: bserEncodeArray
static void bserEncodeArray(dynamic const& dyn,
QueueAppender& appender,
const serialization_opts& opts) {
auto templ = getTemplate(opts, dyn);
if (UNLIKELY(templ != nullptr)) {
appender.write((int8_t)BserType::Template);
// Emit the list of property names
bserEncodeArraySimple(*templ, appender, opts);
// The number of objects in the array
bserEncodeInt(dyn.size(), appender);
// For each object in the array
for (const auto& ele : dyn) {
// For each key in the template
for (const auto& name : *templ) {
if (auto found = ele.get_ptr(name)) {
if (found->isNull()) {
// Prefer to Skip rather than encode a null value for
// compatibility with the other bser implementations
appender.write((int8_t)BserType::Skip);
} else {
bserEncode(*found, appender, opts);
}
} else {
appender.write((int8_t)BserType::Skip);
}
}
}
return;
}
bserEncodeArraySimple(dyn, appender, opts);
}