本文整理汇总了C++中rapidjson::Value::HasMember方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::HasMember方法的具体用法?C++ Value::HasMember怎么用?C++ Value::HasMember使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rapidjson::Value
的用法示例。
在下文中一共展示了Value::HasMember方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FromItemJson
void ItemLocation::FromItemJson(const rapidjson::Value &root) {
if (root.HasMember("_type")) {
type_ = static_cast<ItemLocationType>(root["_type"].GetInt());
if (type_ == ItemLocationType::STASH) {
tab_label_ = root["_tab_label"].GetString();
tab_id_ = root["_tab"].GetInt();
} else {
character_ = root["_character"].GetString();
}
socketed_ = false;
if (root.HasMember("_socketed"))
socketed_ = root["_socketed"].GetBool();
// socketed items have x/y pointing to parent
if (socketed_) {
x_ = root["_x"].GetInt();
y_ = root["_y"].GetInt();
}
}
if (root.HasMember("x") && root.HasMember("y")) {
x_ = root["x"].GetInt();
y_ = root["y"].GetInt();
}
w_ = root["w"].GetInt();
h_ = root["h"].GetInt();
if (root.HasMember("inventoryId"))
inventory_id_ = root["inventoryId"].GetString();
}
示例2: processRawPost
Post processRawPost(const rapidjson::Value& raw_post) {
const char* ITEM_ID = "id";
const char* ITEM_USER_ID = "userId";
const char* ITEM_TITLE = "title";
const char* ITEM_BODY = "body";
Post post;
if (raw_post.IsObject()) { // could also be an Array
assert("No item: id" && raw_post.HasMember(ITEM_ID));
assert("Not an integer: id" && raw_post[ITEM_ID].IsInt());
post.id = raw_post[ITEM_ID].GetInt();
assert("No item: user_id" && raw_post.HasMember(ITEM_USER_ID));
assert("Not an integer: user_id" && raw_post[ITEM_USER_ID].IsInt());
post.user_id = raw_post[ITEM_USER_ID].GetInt();
assert("No item: title" && raw_post.HasMember(ITEM_TITLE));
assert("Not a string: title" && raw_post[ITEM_TITLE].IsString());
post.title = std::string(raw_post[ITEM_TITLE].GetString());
assert("No item: body" && raw_post.HasMember(ITEM_BODY));
assert("Not a string: body" && raw_post[ITEM_BODY].IsString());
post.body = std::string(raw_post[ITEM_BODY].GetString());
} else {
ERR("Invalid json object");
}
return post;
}
示例3:
bool
Element::loadFromJsonValue(rapidjson::Value& json_value)
{
if (!json_value.IsObject()) {
return false;
}
// parse the data and set the Elements
if (json_value.HasMember("id")) {
const rapidjson::Value& idVal = json_value["id"];
id_.fromStr(idVal.GetString());
}
tag_ids_.clear();
if (json_value.HasMember("tag_ids")) {
const rapidjson::Value& tag_ids = json_value["tag_ids"];
if (!tag_ids.IsArray()) {
LOG_ERROR("tag_ids field is not an array, wrong format?");
return false;
}
for (unsigned int i = 0; i < tag_ids.Size(); ++i) {
if (!tag_ids[i].IsString()) {
LOG_ERROR("Wrong format, expected string but it is not");
return false;
}
tag_ids_.insert(core::UID(tag_ids[i].GetString()));
}
}
return true;
}
示例4: CalculateHash
void Item::CalculateHash(const rapidjson::Value &json) {
std::string unique_old(name_ + "~" + typeLine_ + "~");
std::string unique_new(std::string(json["name"].GetString()) + "~" + json["typeLine"].GetString() + "~");
std::string unique_common;
if (json.HasMember("explicitMods"))
for (auto &mod : json["explicitMods"])
unique_common += std::string(mod.GetString()) + "~";
if (json.HasMember("implicitMods"))
for (auto &mod : json["implicitMods"])
unique_common += std::string(mod.GetString()) + "~";
unique_common += item_unique_properties(json, "properties") + "~";
unique_common += item_unique_properties(json, "additionalProperties") + "~";
if (json.HasMember("sockets"))
for (auto &socket : json["sockets"])
unique_common += std::to_string(socket["group"].GetInt()) + "~" + socket["attr"].GetString() + "~";
unique_old += unique_common;
unique_new += unique_common;
old_hash_ = Util::Md5(unique_old);
unique_new += "~" + location_.GetUniqueHash();
hash_ = Util::Md5(unique_new);
}
示例5: _parseEventData
void JSONDataParser::_parseEventData(const rapidjson::Value& rawData, std::vector<EventData*>& events, BoneData * bone, SlotData * slot) const
{
if (rawData.HasMember(SOUND))
{
const auto eventData = BaseObject::borrowObject<EventData>();
eventData->type = EventType::Sound;
eventData->name = rawData[SOUND].GetString();
eventData->bone = bone;
eventData->slot = slot;
events.push_back(eventData);
}
if (rawData.HasMember(EVENT))
{
const auto eventData = BaseObject::borrowObject<EventData>();
eventData->type = EventType::Frame;
eventData->name = rawData[EVENT].GetString();
eventData->bone = bone;
eventData->slot = slot;
if (rawData.HasMember(DATA))
{
// eventData->data = rawData[DATA]; // TODO
}
events.push_back(eventData);
}
}
示例6: fromJson
void Screen::fromJson(rapidjson::Value& value) {
auto visibleSize = cocos2d::Director::getInstance()->getVisibleSize();
if (value.HasMember("positioning")) {
std::string _positioning = toLowerCase(value["positioning"].GetString());
if (_positioning == "block") {
this->positioning = Screen::PositionTypes::BLOCK;
}
else if (_positioning == "overlay") {
this->positioning = Screen::PositionTypes::OVERLAY;
}
else if (_positioning == "fixed") {
this->positioning = Screen::PositionTypes::FIXED;
}
}
if (value.HasMember("position")) {
assert(value["position"].IsArray());
this->position.x = visibleSize.width * value["position"][0].GetInt();
this->position.y = visibleSize.height - visibleSize.height * value["position"][1].GetInt();
}
if (value.HasMember("size")) {
assert(value["size"].IsArray());
//Optimize This: Not really needed but this is gross
this->size.width = visibleSize.width * value["size"][0].GetDouble();
this->size.height = visibleSize.height * value["size"][1].GetDouble();
}
}
示例7: handleDressFigure
std::string PersonManager::handleDressFigure(const rapidjson::Value& json)
{
std::string operation = json["OPERATION"].GetString();
if (json.HasMember("WHO") == false || json.HasMember("FIGURES") == false)
{
return "missing WHO or FIGURES";
}
std::string who = json["WHO"].GetString();
const rapidjson::Value& figures = json["FIGURES"];
assert(figures.IsArray());
if (who != "me" && who != "spouse")
{
return "invalid value of WHO";
}
Person* person = (who == "me" ? mMe : mSpouse);
for (rapidjson::SizeType i = 0; i < figures.Size(); ++i)
{
const rapidjson::Value& item = figures[i];
assert(item.HasMember("TYPE"));
assert(item.HasMember("NAME"));
std::string type = item["TYPE"].GetString();
std::string id = item["NAME"].GetString();
FigureKey figureKey(person->isMale(), type, id);
FigureManager::getInstance()->dressItem(figureKey);
}
return SUCC;
}
示例8: parseAsset
Manifest::Asset Manifest::parseAsset(const std::string &path, const rapidjson::Value &json)
{
Asset asset;
asset.path = path;
if ( json.HasMember(KEY_MD5) && json[KEY_MD5].IsString() )
{
asset.md5 = json[KEY_MD5].GetString();
}
else asset.md5 = "";
if ( json.HasMember(KEY_PATH) && json[KEY_PATH].IsString() )
{
asset.path = json[KEY_PATH].GetString();
}
if ( json.HasMember(KEY_COMPRESSED) && json[KEY_COMPRESSED].IsBool() )
{
asset.compressed = json[KEY_COMPRESSED].GetBool();
}
else asset.compressed = false;
if ( json.HasMember(KEY_DOWNLOAD_STATE) && json[KEY_DOWNLOAD_STATE].IsInt() )
{
asset.downloadState = (DownloadState)(json[KEY_DOWNLOAD_STATE].GetInt());
}
else asset.downloadState = DownloadState::UNSTARTED;
return asset;
}
示例9: Load
RenderOptions RenderOptions::Load(const rapidjson::Value& value) {
RenderOptions options;
if (value.HasMember("maxThreadsCount")) {
options.maxThreadsCount = value["maxThreadsCount"].GetInt();
}
if (value.HasMember("antialiasingSampling")) {
options.antialiasingSampling = SamplingConfig::Load(value["antialiasingSampling"]);
}
if (value.HasMember("maxRayDepth")) {
options.maxRayDepth = value["maxRayDepth"].GetInt();
}
if (value.HasMember("surfaceIntegrator")) {
options.surfaceIntegrator = SurfaceIntegrator::Load(value["surfaceIntegrator"]);
if (!options.surfaceIntegrator) {
std::cerr << "RenderOptions error: error while loading surface integrator" << std::endl;
}
} else {
std::cerr << "RenderOptions error: no surface integrator given" << std::endl;
}
if (value.HasMember("volumeIntegrator")) {
options.volumeIntegrator = VolumeIntegrator::Load(value["volumeIntegrator"]);
if (!options.volumeIntegrator) {
std::cerr << "RenderOptions error: error while loading volume integrator" << std::endl;
}
} else {
std::cerr << "RenderOptions error: no volume integrator given" << std::endl;
}
return options;
}
示例10: sdlLoadImage
EffectData::EffectData(EffectType t, const rapidjson::Value &json)
: type{t},
anim{},
animFrames{},
sound{},
dur{Duration::INSTANT},
text{}
{
if (json.HasMember("anim")) {
anim = sdlLoadImage(json["anim"].GetString());
}
if (json.HasMember("anim-frames")) {
animFrames = jsonListUnsigned(json["anim-frames"]);
}
if (json.HasMember("sound")) {
sound = sdlLoadSound(json["sound"].GetString());
}
if (json.HasMember("duration")) {
const auto &durType = json["duration"].GetString();
auto iter = allDurations.find(to_upper(durType));
if (iter != std::end(allDurations)) {
dur = iter->second;
}
else {
std::cerr << "Warning: unrecognized duration type for effect " <<
" type " << static_cast<int>(type) << '\n';
}
}
if (json.HasMember("text")) {
text = json["text"].GetString();
}
}
示例11:
void BQ::RigidBodyPattern::parse(const rapidjson::Value & json)
{
mass = json.HasMember("mass") ? json["mass"].GetFloat() : 1;
restitution = json.HasMember("restitution") ? json["restitution"].GetFloat() : 1;
friction = json.HasMember("friction") ? json["friction"].GetFloat() : 0;
momentum.x = json.HasMember("momentum_x") ? json["momentum_x"].GetFloat() : 0;
momentum.y = json.HasMember("momentum_y") ? json["momentum_y"].GetFloat() : 0;
}
示例12: is_as_msg
bool is_as_msg(const rapidjson::Value & val)
{
RAPIDJSON_ASSERT(val.HasMember("category"));
RAPIDJSON_ASSERT(val.HasMember("msgid"));
RAPIDJSON_ASSERT(val.FindMember("msgid")->value.IsArray());
if (val.FindMember("msgid")->value.Size() > 0) {
return true;
}
return false;
}
示例13: handlePlatformMessage
std::string ChatOnBedRoom::handlePlatformMessage(const rapidjson::Value& content)
{
std::string operation = content[minius::Protocol::OPERATION.c_str()].GetString();
if (operation == "loadModule")
{
std::string result = SUCC;
if (content.HasMember("INIT_DATA"))
{
const rapidjson::Value& initData = content["INIT_DATA"];
for (rapidjson::SizeType i = 0; i < initData.Size(); ++i)
{
std::string resultTemp = this->handlePlatformMessage(initData[i]);
//assert(resultTemp == SUCC);
/*
if (resultTemp != SUCC)
result = resultTemp;*/
}
}
return result;
}
else if (operation == "setComponentAttrs")
{
if (content.HasMember("COMPONENT") == false || content.HasMember("ATTRS") == false)
{
return "missing COMPONENT or ATTRS";
}
std::string componentName = content["COMPONENT"].GetString();
minius::Component* pComponent = dynamic_cast<minius::Component*>(this->getChildByName(componentName));
if (pComponent == nullptr)
{
return std::string("invalid COMPONENT: ") + componentName;
}
bool status = pComponent->setAttrs(content["ATTRS"]);
return SUCC;
}
else if (operation == "chatAction")
{
std::string type = content["TYPE"].GetString();
std::string sponsor = content["WHO"].GetString();
if (sponsor == "me") {
this->playActionWithIsMeSponsor(true, type);
}
else {
this->playActionWithIsMeSponsor(false, type);
}
return SUCC;
}
else
{
return std::string("invalid OPERATION: ") + operation;
}
}
示例14: parseJob
bool Client::parseJob(const rapidjson::Value ¶ms, int *code)
{
if (!params.IsObject()) {
*code = 2;
return false;
}
# ifdef XMRIG_PROXY_PROJECT
Job job(m_id, m_url.variant());
job.setClientId(m_rpcId);
job.setCoin(m_url.coin());
# else
Job job(m_id, m_nicehash, m_url.algo(), m_url.variant());
# endif
if (!job.setId(params["job_id"].GetString())) {
*code = 3;
return false;
}
if (!job.setBlob(params["blob"].GetString())) {
*code = 4;
return false;
}
if (!job.setTarget(params["target"].GetString())) {
*code = 5;
return false;
}
if (params.HasMember("coin")) {
job.setCoin(params["coin"].GetString());
}
if (params.HasMember("variant")) {
job.setVariant(params["variant"].GetInt());
}
if (m_job != job) {
m_jobs++;
m_job = std::move(job);
return true;
}
if (m_jobs == 0) { // https://github.com/xmrig/xmrig/issues/459
return false;
}
if (!m_quiet) {
LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port());
}
close();
return false;
}
示例15:
void
SkillInfo::from_json_value(const rapidjson::Value& d)
{
if (d.HasMember("kind") && d["kind"].IsString()) {
kind_ = d["kind"].GetString();
}
if (d.HasMember("apiVersion") && d["apiVersion"].IsString()) {
apiVersion_ = d["apiVersion"].GetString();
}
if (d.HasMember("name") && d["name"].IsString()) {
name_ = d["name"].GetString();
}
}