本文整理汇总了C++中value::begin_object方法的典型用法代码示例。如果您正苦于以下问题:C++ value::begin_object方法的具体用法?C++ value::begin_object怎么用?C++ value::begin_object使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类value
的用法示例。
在下文中一共展示了value::begin_object方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GenStat
static void GenStat(Stat& stat, const value& v) {
switch (v.kind()) {
case kind::array:
{
for (value::const_array_iterator itr = v.begin_array(); itr != v.end_array(); ++itr)
GenStat(stat, *itr);
stat.arrayCount++;
stat.elementCount += v.size();
}
break;
case kind::object:
{
for (value::const_object_iterator itr = v.begin_object(); itr != v.end_object(); ++itr) {
GenStat(stat, itr->second);
stat.stringLength += itr->first.size();
}
stat.objectCount++;
stat.memberCount += v.size();
stat.stringCount += v.size();
}
break;
case kind::string:
stat.stringCount++;
stat.stringLength += v.size();
break;
case kind::integer:
case kind::decimal:
stat.numberCount++;
break;
case kind::boolean:
if (v.as_boolean())
stat.trueCount++;
else
stat.falseCount++;
break;
case kind::null:
stat.nullCount++;
break;
}
}
示例2: diff
diff_result diff(value left, value right)
{
diff_result result;
if (left == right)
{
result.same = std::move(left);
}
else if (left.kind() != right.kind())
{
result.left = std::move(left);
result.right = std::move(right);
}
else switch (left.kind())
{
case kind::boolean:
case kind::decimal:
case kind::integer:
case kind::null:
case kind::string:
result.left = std::move(left);
result.right = std::move(right);
break;
case kind::array:
result.same = array();
result.left = array();
result.right = array();
for (value::size_type idx = 0; idx < std::min(left.size(), right.size()); ++idx)
{
diff_result subresult = diff(std::move(left.at(idx)), std::move(right.at(idx)));
result.same.push_back(std::move(subresult.same));
result.left.push_back(std::move(subresult.left));
result.right.push_back(std::move(subresult.right));
}
if (left.size() > right.size())
result.left.insert(result.left.end_array(),
std::make_move_iterator(left.begin_array() + right.size()),
std::make_move_iterator(left.end_array())
);
else if (left.size() < right.size())
result.right.insert(result.right.end_array(),
std::make_move_iterator(right.begin_array() + left.size()),
std::make_move_iterator(right.end_array())
);
break;
case kind::object:
result.same = object();
result.left = object();
result.right = object();
for (value::object_iterator liter = left.begin_object();
liter != left.end_object();
liter = left.erase(liter)
)
{
auto riter = right.find(liter->first);
if (riter == right.end_object())
{
result.left.insert({ liter->first, std::move(liter->second) });
}
else if (liter->second == riter->second)
{
result.same[liter->first] = std::move(liter->second);
right.erase(riter);
}
else
{
diff_result subresult = diff(std::move(liter->second), std::move(riter->second));
result.left[liter->first] = std::move(subresult.left);
result.right[liter->first] = std::move(subresult.right);
right.erase(riter);
}
}
for (value::object_iterator riter = right.begin_object();
riter != right.end_object();
riter = right.erase(riter)
)
{
result.right.insert({ riter->first, std::move(riter->second) });
}
break;
}
return result;
}