本文整理汇总了C++中rapidjson::Value::FindMember方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::FindMember方法的具体用法?C++ Value::FindMember怎么用?C++ Value::FindMember使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rapidjson::Value
的用法示例。
在下文中一共展示了Value::FindMember方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fromJson
inline bool fromJson(const rapidjson::Value &v, const char *field, T &dst)
{
const rapidjson::Value::Member *member = v.FindMember(field);
if (!member)
return false;
return fromJson(member->value, dst);
}
示例2: assert
name_t::name_t(const rapidjson::Value &json_value) {
auto last_iter = json_value.FindMember("last");
if ( last_iter != json_value.MemberEnd() ) {
assert(last_iter->value.IsString());
last = last_iter->value.GetString();
}
auto first_iter = json_value.FindMember("first");
if ( first_iter != json_value.MemberEnd() ) {
assert(first_iter->value.IsString());
first = first_iter->value.GetString();
}
}
示例3: Parse
bool JSASTLabeledStatement::Parse(const rapidjson::Value& value)
{
JSASTStatement::Parse(value);
const Value::Member* body = value.FindMember("body");
assert(body);
const Value::Member* label = value.FindMember("label");
assert(label);
body_ = ParseStatement(body->value);
label_ = (JSASTIdentifier*) ParseExpression(label->value, JSAST_IDENTIFIER);
return body_ && label_;
}
示例4: ensure_has_object_mem
void ensure_has_object_mem(rapidjson::Value & _val, rapidjson::Value::StringRefType _name, rapidjson::Document & _doc)
{
if (!_val.HasMember(_name)) {
rapidjson::Value v(rapidjson::kObjectType);
_val.AddMember(_name, v, _doc.GetAllocator());
}
RAPIDJSON_ASSERT(_val.FindMember(_name)->value.IsObject());
}
示例5: parse
int32_t fetch_event_imstate::parse(const rapidjson::Value& _node_event_data)
{
auto iter_imstates = _node_event_data.FindMember("imStates");
if (iter_imstates == _node_event_data.MemberEnd() || !iter_imstates->value.IsArray())
return wpie_error_parse_response;
for (auto iter_state = iter_imstates->value.Begin(); iter_state != iter_imstates->value.End(); ++iter_state)
{
imstate ustate;
auto iter_request_id = iter_state->FindMember("sendReqId");
if (iter_request_id == iter_state->MemberEnd() || !iter_request_id->value.IsString())
continue;
ustate.set_request_id(rapidjson_get_string(iter_request_id->value));
auto iter_msg_id = iter_state->FindMember("msgId");
if (iter_msg_id == iter_state->MemberEnd() || !iter_msg_id->value.IsString())
continue;
ustate.set_msg_id(rapidjson_get_string(iter_msg_id->value));
auto iter_state_state = iter_state->FindMember("state");
if (iter_state_state == iter_state->MemberEnd() || !iter_state_state->value.IsString())
continue;
const std::string state = rapidjson_get_string(iter_state_state->value);
if (state == "failed")
ustate.set_state(imstate_sent_state::failed);
else if (state == "sent")
ustate.set_state(imstate_sent_state::sent);
else if (state == "delivered")
ustate.set_state(imstate_sent_state::delivered);
auto iter_hist_msg_id = iter_state->FindMember("histMsgId");
if (iter_hist_msg_id != iter_state->MemberEnd() && iter_hist_msg_id->value.IsInt64())
{
ustate.set_hist_msg_id(iter_hist_msg_id->value.GetInt64());
}
auto iter_before_hist_msg_id = iter_state->FindMember("beforeHistMsgId");
if (iter_before_hist_msg_id != iter_state->MemberEnd() && iter_before_hist_msg_id->value.IsInt64())
{
ustate.set_before_hist_msg_id(iter_before_hist_msg_id->value.GetInt64());
}
auto iter_error_code = iter_state->FindMember("errorCode");
if (iter_error_code != iter_state->MemberEnd() && iter_error_code->value.IsInt())
{
ustate.set_error_code(iter_error_code->value.GetInt());
}
states_.push_back(ustate);
}
return 0;
}
示例6: set_geometry
/*!
Sets box geometry from given rapidjson object.
Given object must have "start" and "end" items
and both must be arrays of 3 numbers.
*/
void set_geometry(const rapidjson::Value& object)
{
const auto& obj_start_i = object.FindMember("start");
if (obj_start_i == object.MemberEnd()) {
throw std::invalid_argument(__FILE__ ": Given object doesn't have a start item.");
}
const auto& obj_start = obj_start_i->value;
if (not obj_start.IsArray()) {
throw std::invalid_argument(__FILE__ ": Start item isn't an array.");
}
if (obj_start.Size() != 3) {
throw std::invalid_argument(__FILE__ ": Start item doesn't have a length of 3.");
}
this->start_rw[0] = obj_start[0].GetDouble();
this->start_rw[1] = obj_start[1].GetDouble();
this->start_rw[2] = obj_start[2].GetDouble();
const auto& obj_end_i = object.FindMember("end");
if (obj_end_i == object.MemberEnd()) {
throw std::invalid_argument(__FILE__ ": Given object doesn't have an end item.");
}
const auto& obj_end = obj_end_i->value;
if (not obj_end.IsArray()) {
throw std::invalid_argument(__FILE__ ": End item isn't an array.");
}
if (obj_end.Size() != 3) {
throw std::invalid_argument(__FILE__ ": End item doesn't have a length of 3.");
}
this->end_rw[0] = obj_end[0].GetDouble();
this->end_rw[1] = obj_end[1].GetDouble();
this->end_rw[2] = obj_end[2].GetDouble();
for (size_t i = 0; i < 3; i++) {
if (this->end_rw[i] <= this->start_rw[i]) {
throw std::invalid_argument(__FILE__ ": Given object ends before it starts.");
}
}
}
示例7: convert_struct_by_name
static void convert_struct_by_name(rapidjson::Document & /*doc*/,
const rapidjson::Value & val,
const std::string & tname,
const std::size_t lvl)
{
const char * ename = tname.c_str();
//bool is_msg = is_as_msg(val);
//const char * fn_prefix = is_msg ? "" : "static inline ";
const rapidjson::Value & fields = val.FindMember("fields")->value;
filebuf & outf = s_outf_converter;
if (fields.MemberCount() > 0) {
outf.pf(lvl, "/// @%s\n", ename);
outf.pf(lvl, "static inline rapidjson::Value c2json(rapidjson::Document & jd, const %s & src)\n", ename);
outf.pf(lvl, "{\n");
outf.pf(lvl+1, "rapidjson::Value v(rapidjson::kObjectType);\n");
for (rapidjson::Value::ConstMemberIterator itr = fields.MemberBegin(); itr != fields.MemberEnd(); ++itr) {
const char * mname = itr->name.GetString();
auto & mval = itr->value;
if (mval.FindMember("maybenull")->value.GetBool()) {
outf.pf(lvl+1, "ENC_MEM_IF(jd, \"%s\", v, src.%s, src.has_%s);\n", mname, mname, mname);
}
else {
outf.pf(lvl+1, "ENC_MEM(jd, \"%s\", v, src.%s);\n", mname, mname);
}
}
outf.pf(0, "\n");
outf.pf(lvl+1, "return v;\n");
outf.pf(lvl, "}\n");
outf.pf(lvl, "static inline void json2c(%s & dst, const rapidjson::Value & src)\n", ename);
outf.pf(lvl, "{\n");
for (rapidjson::Value::ConstMemberIterator itr = fields.MemberBegin(); itr != fields.MemberEnd(); ++itr) {
const char * mname = itr->name.GetString();
auto & mval = itr->value;
if (mval.FindMember("maybenull")->value.GetBool()) {
outf.pf(lvl+1, "DEC_MEM_IF(\"%s\", src, dst.%s, dst.has_%s);\n", mname, mname, mname);
}
else {
outf.pf(lvl+1, "DEC_MEM(\"%s\", src, dst.%s);\n", mname, mname);
}
}
outf.pf(lvl, "}\n");
outf.pf(0, "\n");
}
else {
outf.pf(lvl, "static inline rapidjson::Value c2json(rapidjson::Document & /*jd*/, const %s & /*src*/) {\n", ename);
outf.pf(lvl+1, "return rapidjson::Value(rapidjson::kObjectType);\n");
outf.pf(lvl, "}\n");
outf.pf(lvl, "static inline void json2c(%s & /*dst*/, const rapidjson::Value & /*src*/) {}\n", ename);
outf.pf(0, "\n");
}
}
示例8: OnCommand
QueryError OnCommand(const rapidjson::Value &p_Args, std::string *p_Result)
{
// Get the "command" argument
auto s_CommandValue = p_Args.FindMember("command");
if (s_CommandValue == p_Args.MemberEnd() || !s_CommandValue->value.IsString())
{
*p_Result = "Bad query: A \"command\" argument is required and must be a string";
return QueryError_BadQuery;
}
// Get the "internal" argument (defaults to false)
auto s_InternalValue = p_Args.FindMember("internal");
auto s_IsInternal = (s_InternalValue != p_Args.MemberEnd() && s_InternalValue->value.IsBool() && s_InternalValue->value.GetBool());
// Run the command
if (!Modules::CommandMap::Instance().ExecuteCommandWithStatus(s_CommandValue->value.GetString(), !s_IsInternal, p_Result))
return QueryError_CommandFailed;
return QueryError_Ok;
}
示例9: parse_results
int32_t robusto_add_client::parse_results(const rapidjson::Value& _node_results)
{
auto iter_client_id = _node_results.FindMember("clientId");
if (iter_client_id == _node_results.MemberEnd())
return wpie_http_parse_response;
client_id_ = iter_client_id->value.GetUint();
return 0;
}
示例10: unserialize
int32_t favorite::unserialize(const rapidjson::Value& _node)
{
auto iter_aimid = _node.FindMember("aimId");
if (iter_aimid == _node.MemberEnd() || !iter_aimid->value.IsString())
return -1;
aimid_ = iter_aimid->value.GetString();
auto iter_time = _node.FindMember("time");
if (iter_time == _node.MemberEnd() || !iter_time->value.IsInt64())
{
time_ = 0;
return 0;
}
time_ = iter_time->value.GetInt64();
return 0;
}
示例11: GetIterator
inline auto GetIterator(const rapidjson::Value& value, const char* name)
{
auto it = value.FindMember(name);
if (it == value.MemberEnd())
{
SDR::Error::Make("Member Json value \"%s\" not found", name);
}
return it;
}
示例12: deserializePoint
MapPoint deserializePoint(rapidjson::Value& value)
{
MapPoint p;
rapidjson::Value& position = value.FindMember("position")->value;
if(position.IsArray())
{
p.point.x = position[0].GetDouble();
p.point.y = position[1].GetDouble();
}
rapidjson::Value& name = value.FindMember("name")->value;
if(name.IsString())
{
p.name = name.GetString();
}
rapidjson::Value& desc = value.FindMember("description")->value;
if(desc.IsString())
{
p.description = desc.GetString();
}
return p;
}
示例13: ParseLoc
bool JSASTNode::ParseLoc(const rapidjson::Value& value)
{
// SpiderMonkey can have this for loc :/
if (value.IsNull())
return true;
assert(value.IsObject());
const Value::Member* mstart = value.FindMember("start");
assert(mstart);
const Value::Member* mend = value.FindMember("end");
assert(mend);
loc_.startLine_ = mstart->value["line"].GetInt();
loc_.startColumn_ = mstart->value["column"].GetInt();
loc_.endLine_ = mend->value["line"].GetInt();
loc_.endColumn_ = mend->value["column"].GetInt();
return true;
}
示例14: unpack_int
void etcd_packer::unpack_int(rapidjson::Value &json_val, const char *key, uint64_t &out) {
rapidjson::Value::MemberIterator iter = json_val.FindMember(key);
if (iter == json_val.MemberEnd()) {
out = 0;
} else {
if (iter->value.IsUint64()) {
out = iter->value.GetUint64();
} else if (iter->value.IsString()) {
const char *val = iter->value.GetString();
::util::string::str2int(out, val);
}
}
}
示例15: unpack_string
bool etcd_packer::unpack_string(rapidjson::Value &json_val, const char *key, std::string &val) {
rapidjson::Value::MemberIterator iter = json_val.FindMember(key);
if (iter == json_val.MemberEnd()) {
return false;
}
switch (iter->value.GetType()) {
case rapidjson::kNullType: {
val.clear();
break;
}
case rapidjson::kFalseType: {
val = "false";
break;
}
case rapidjson::kTrueType: {
val = "true";
break;
}
case rapidjson::kObjectType: {
val = "[object object]";
break;
}
case rapidjson::kArrayType: {
val = "[object array]";
break;
}
case rapidjson::kStringType: {
val = iter->value.GetString();
break;
}
case rapidjson::kNumberType: {
std::stringstream ss;
if (iter->value.IsDouble()) {
ss << iter->value.GetDouble();
} else if (iter->value.IsInt()) {
ss << iter->value.GetInt();
} else if (iter->value.IsUint()) {
ss << iter->value.GetUint();
} else if (iter->value.IsInt64()) {
ss << iter->value.GetInt64();
} else {
ss << iter->value.GetUint64();
}
val = ss.str();
break;
}
}
return true;
}