本文整理汇总了C++中rapidjson::Document::FindMember方法的典型用法代码示例。如果您正苦于以下问题:C++ Document::FindMember方法的具体用法?C++ Document::FindMember怎么用?C++ Document::FindMember使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rapidjson::Document
的用法示例。
在下文中一共展示了Document::FindMember方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create
// Configure from preparsed json config.
// Config template:
// {
// remotes: ["localhost:1025:2"],
// groups: [2],
// logfile: "/dev/stderr",
// loglevel: 0
// }
static elliptics_client_state create(const rapidjson::Document &args) {
std::string logfile = "/dev/stderr";
uint loglevel = DNET_LOG_ERROR;
std::vector<std::string> remotes;
std::vector<int> groups;
try {
{
const auto *m = args.FindMember("logfile");
if (m && m->value.IsString()) {
logfile = m->value.GetString();
}
}
{
const auto *m = args.FindMember("loglevel");
if (m && m->value.IsInt()) {
loglevel = m->value.GetInt();
}
}
const rapidjson::Value &remotesArray = args["remotes"];
std::transform(remotesArray.Begin(), remotesArray.End(),
std::back_inserter(remotes),
std::bind(&rapidjson::Value::GetString, std::placeholders::_1)
);
const rapidjson::Value &groupsArray = args["groups"];
std::transform(groupsArray.Begin(), groupsArray.End(),
std::back_inserter(groups),
std::bind(&rapidjson::Value::GetInt, std::placeholders::_1)
);
} catch (const std::exception &e) {
throw configuration_error(e.what());
}
return create(remotes, groups, logfile, loglevel);
}
示例2:
Config::ChildrenMapType
getAllElementChildren(const rapidjson::Document& doc, const std::vector<SvgElement>& all_elements_,
const Config::ElementGroupType& element_groups_)
{
Config::ChildrenMapType all_element_children;
all_element_children.set_empty_key(std::string{""});
// load elements
const auto element_children_it = doc.FindMember("element_children");
assert(element_children_it != doc.MemberEnd());
assert(element_children_it->value.IsArray());
const auto raw_element_children_array = element_children_it->value.GetArray();
for (const auto& raw_element_children_obj : raw_element_children_array)
{
assert(raw_element_children_obj.IsObject());
//parent
const auto raw_parent_element = raw_element_children_obj.FindMember("parent");
assert(raw_parent_element != raw_element_children_obj.MemberEnd());
assert(raw_parent_element->value.IsString());
const auto& parent_element_name = raw_parent_element->value.GetString();
//children
std::vector<std::string> all_children;
const auto raw_children_array_it = raw_element_children_obj.FindMember("children");
assert(raw_children_array_it != raw_element_children_obj.MemberEnd());
assert(raw_children_array_it->value.IsArray());
const auto raw_children_array = (raw_children_array_it->value.GetArray());
for (const auto& raw_child : raw_children_array)
{
assert(raw_child.IsString());
auto child = std::string{raw_child.GetString(), raw_child.GetStringLength()};
if (element_groups_.count(child) > 0) // the name is a group name
{
const auto& group_with_current_name = const_cast<Config::ElementGroupType&>(element_groups_)[child];
all_children.insert(std::end(all_children), std::begin(group_with_current_name),
std::end(group_with_current_name));//we replace the group with it's elements
} else // otherwise it's a simple element
{
all_children.emplace_back(std::move(child));
}
std::sort(std::begin(all_children), std::end(all_children));
all_element_children[parent_element_name] = std::move(all_children);
}
}
return all_element_children;
}
示例3: json_simpars
void Parameters::json_simpars(rapidjson::Document& jpars) {
try {
rapidjson::Value::MemberIterator it;
it = jpars.FindMember("simulation");
if (it != jpars.MemberEnd()) {
if (! it->value.IsObject()) throw 201;
rapidjson::Value& d = it->value;
it = d.FindMember("maxTime");
if (! it->value.IsDouble()) throw 202;
sim_pars.maxTime = it->value.GetDouble();
}
} catch (int e) {
cerr << "Exception while reading SimPars: " << e << endl;
return;
}
}
示例4: from_json
void Parameters::from_json(rapidjson::Document& jpars) {
try {
rapidjson::Value::MemberIterator m1;
rapidjson::SizeType z;
m1 = jpars.FindMember("model_type");
if (m1 != jpars.MemberEnd()) {
if (! m1->value.IsString()) throw 101;
model_type = m1->value.GetString();
}
m1 = jpars.FindMember("nroot");
if (m1 != jpars.MemberEnd()) {
if (! m1->value.IsInt()) throw 102;
nroot = m1->value.GetInt();
}
m1 = jpars.FindMember("shifts");
if (m1 != jpars.MemberEnd()) {
if (! m1->value.IsArray()) throw 103;
shifts.resize(m1->value.Size());
for (rapidjson::SizeType i = 0; i < m1->value.Size(); ++i) {
shifts[i] = m1->value[i].GetDouble();
}
}
rapidjson::Value::MemberIterator _d = jpars.FindMember("pars");
if (_d == jpars.MemberEnd()) throw 1;
rapidjson::Value& d = _d->value;
pars.resize(d.Size());
for (rapidjson::SizeType i = 0; i < d.Size(); ++i) {
rapidjson::Value& a = d[i];
m1 = a.FindMember("name");
if (m1 != a.MemberEnd()) {
if (! m1->value.IsString()) throw 5;
pars[i].name = m1->value.GetString();
name_map.insert(make_pair(pars[i].name,i));
}
m1 = a.FindMember("limits");
if (m1 != a.MemberEnd()) {
if (! m1->value.IsArray()) throw 2;
if (m1->value.Size() != 2) throw 3;
z = 0;
pars[i].lo = m1->value[z].GetDouble();
z = 1;
pars[i].hi = m1->value[z].GetDouble();
}
m1 = a.FindMember("value");
if (m1 == a.MemberEnd()) m1 = a.FindMember("init");
if (m1 != a.MemberEnd()) {
if (m1->value.IsDouble()) {
pars[i].init.assign(1,m1->value.GetDouble());
} else if (m1->value.IsArray()) {
pars[i].init.assign(m1->value.Size(),0.0);
for (size_t j = 0; j < m1->value.Size(); ++j) {
pars[i].init[j] = m1->value[j].GetDouble();
}
} else {
throw 2;
}
}
m1 = a.FindMember("lock");
if (m1 != a.MemberEnd()) {
if (! m1->value.IsDouble()) throw 4;
pars[i].lock = 1;
pars[i].lo = m1->value.GetDouble();
pars[i].hi = pars[i].lo;
pars[i].init.assign(1,0.0);
pars[i].init[0] = pars[i].hi;
}
m1 = a.FindMember("scale");
if (m1 != a.MemberEnd()) {
if (! m1->value.IsString()) throw 5;
pars[i].scale = m1->value.GetString()[0];
}
}
} catch (int e) {
cerr << "Exception while reading pars: " << e << endl;
return;
}
json_simpars(jpars);
}