本文整理汇总了C++中rapidjson::Value::IsObject方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::IsObject方法的具体用法?C++ Value::IsObject怎么用?C++ Value::IsObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rapidjson::Value
的用法示例。
在下文中一共展示了Value::IsObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse
bool dto_complex::parse( const rapidjson::Value& json )
{
if( json.IsObject() && json.HasMember( key() ) && json[key()].IsObject() )
{
for( auto& child : get_children() )
{
child->set_client( client() );
if( !child->parse( json[key()] ) && !optional() )
{
return false;
}
}
return true;
}
else if( json.IsObject() )
{
for( auto& child : get_children() )
{
child->set_client( client() );
if( !child->parse( json ) && !optional() )
{
return false;
}
}
return true;
}
set_present( false );
return optional();
}
示例2: parseResponse
void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error)
{
if (error.IsObject()) {
const char *message = error["message"].GetString();
auto it = m_results.find(id);
if (it != m_results.end()) {
it->second.done();
m_listener->onResultAccepted(this, it->second, message);
m_results.erase(it);
}
else if (!m_quiet) {
LOG_ERR("[%s:%u] error: \"%s\", code: %d", m_url.host(), m_url.port(), message, error["code"].GetInt());
}
if (id == 1 || isCriticalError(message)) {
close();
}
return;
}
if (!result.IsObject()) {
return;
}
if (id == 1) {
int code = -1;
if (!parseLogin(result, &code)) {
if (!m_quiet) {
LOG_ERR("[%s:%u] login error code: %d", m_url.host(), m_url.port(), code);
}
close();
return;
}
m_failures = 0;
m_listener->onLoginSuccess(this);
m_listener->onJobReceived(this, m_job);
return;
}
auto it = m_results.find(id);
if (it != m_results.end()) {
it->second.done();
m_listener->onResultAccepted(this, it->second, nullptr);
m_results.erase(it);
}
}
示例3: JSONObjectToDetailedWares
void JSONObjectToDetailedWares(const rapidjson::Value& Obj,
FluidHubAPIClient::WaresDetailsByID_t& WMap)
{
WMap.clear();
if (Obj.IsObject())
{
for (rapidjson::Value::ConstMemberIterator it = Obj.MemberBegin(); it != Obj.MemberEnd(); ++it)
{
if (it->value.IsObject())
{
std::string WareID = it->name.GetString();
WMap[WareID] = FluidHubAPIClient::WareDetailedDescription();
rapidjson::Value::ConstMemberIterator itMember = it->value.FindMember("shortdesc");
if (itMember != it->value.MemberEnd() && itMember->value.IsString())
{
WMap[WareID].ShortDescription = std::string(itMember->value.GetString());
}
itMember = it->value.FindMember("git-url");
if (itMember != it->value.MemberEnd() && itMember->value.IsString())
{
WMap[WareID].GitUrl = std::string(itMember->value.GetString());
}
itMember = it->value.FindMember("git-branches");
if (itMember != it->value.MemberEnd() && itMember->value.IsArray())
{
JSONArrayToStringVector(itMember->value,WMap[WareID].GitBranches);
}
itMember = it->value.FindMember("issues-counts");
if (itMember != it->value.MemberEnd() && itMember->value.IsObject())
{
for (rapidjson::Value::ConstMemberIterator itCounters = itMember->value.MemberBegin();
itCounters != itMember->value.MemberEnd();
++itCounters)
{
if (itCounters->value.IsInt())
WMap[WareID].IssuesCounters[itCounters->name.GetString()] = itCounters->value.GetInt();
}
}
itMember = it->value.FindMember("users-ro");
if (itMember != it->value.MemberEnd() && itMember->value.IsArray())
{
JSONArrayToStringSet(itMember->value,WMap[WareID].ROUsers);
}
itMember = it->value.FindMember("users-rw");
if (itMember != it->value.MemberEnd() && itMember->value.IsArray())
{
JSONArrayToStringSet(itMember->value,WMap[WareID].RWUsers);
}
}
}
}
}
示例4: parse_error
tws::geoarray::spatial_extent_t
tws::geoarray::read_spatial_extent(const rapidjson::Value& jspatial_extent)
{
if(!jspatial_extent.IsObject() || jspatial_extent.IsNull())
throw tws::parse_error() << tws::error_description("error parsing spatial extent in metadata.");
spatial_extent_t sp_extent;
const rapidjson::Value& jextent = jspatial_extent["extent"];
sp_extent.extent = read_extent(jextent);
const rapidjson::Value& jres = jspatial_extent["resolution"];
sp_extent.resolution = read_spatial_resolution(jres);
//const rapidjson::Value& jcrs = jspatial_extent["crs"];
//if(!jcrs.IsString() || jcrs.IsNull())
//throw tws::parse_error() << tws::error_description("error in CRS in metadata.");
//std::string crs = jcrs.GetString();
//std::pair<std::string,unsigned int> crs_id = te::srs::SpatialReferenceSystemManager::getInstance().getIdFromP4Txt(crs);
const rapidjson::Value& jsrid = jspatial_extent["srid"];
if(!jsrid.IsInt() || jsrid.IsNull())
throw tws::parse_error() << tws::error_description("error reading geoarray srid.");
sp_extent.crs_code = jsrid.GetUint();
return sp_extent;
}
示例5: 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;
}
示例6: if
std::shared_ptr<VolumeIntegrator> VolumeIntegrator::Load(const rapidjson::Value& value) {
std::shared_ptr<VolumeIntegrator> integrator;
std::string type;
if (value.IsString()) {
type = value.GetString();
} else if (value.IsObject() && value.HasMember("type")) {
type = value["type"].GetString();
} else {
std::cerr << "VolumeIntegrator error: no type given" << std::endl;
return integrator;
}
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
if (type == "singlescattering") {
integrator = SingleScatteringIntegrator::Load(value);
} else {
std::cerr << "VolumeIntegrator error: unknown type \"" << type << "\"" << std::endl;
return integrator;
}
return integrator;
}
示例7:
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;
}
示例8: configure
void counter::configure(const rapidjson::Value& config) {
if (!config.IsObject()) {
return;
}
this->values.configure(config);
}
示例9: Parse
bool JSASTNode::Parse(const rapidjson::Value& value)
{
assert(value.IsObject());
for (Value::ConstMemberIterator itr = value.MemberBegin();
itr != value.MemberEnd(); ++itr)
{
String name = itr->name.GetString();
if (name == "loc")
{
ParseLoc(itr->value);
}
else if (name == "type")
{
// TODO: Verify type
}
else if (name == "range")
{
ParseRange(itr->value);
}
}
return true;
}
示例10: configure
void configure(counter& obj, const rapidjson::Value& config) {
if (!config.IsObject()) {
return;
}
configure(obj.values, config);
}
示例11: loadBasedOnTextureOrUav
//-----------------------------------------------------------------------------------
void HlmsJsonCompute::loadBasedOnTextureOrUav( const rapidjson::Value &objValue,
const String &jobName, HlmsComputeJob *job,
int _threadGroupsBasedOn )
{
HlmsComputeJob::ThreadGroupsBasedOn threadGroupsBasedOn =
static_cast<HlmsComputeJob::ThreadGroupsBasedOn>( _threadGroupsBasedOn );
if( objValue.IsUint() )
{
job->setNumThreadGroupsBasedOn( threadGroupsBasedOn,
static_cast<uint8>( objValue.GetUint() ),
1u, 1u, 1u );
}
else if( objValue.IsObject() )
{
uint8 slot = 0;
uint8 divisors[3] = { 1u, 1u, 1u };
bool hasError = false;
const rapidjson::Value &subobj = objValue;
rapidjson::Value::ConstMemberIterator itor = subobj.FindMember( "slot" );
if( itor != subobj.MemberEnd() && itor->value.IsUint() )
slot = static_cast<uint8>( itor->value.GetUint() );
else
hasError = true;
itor = subobj.FindMember( "divisor" );
if( itor != subobj.MemberEnd() && itor->value.IsArray() )
{
const rapidjson::Value &divArray = itor->value;
const rapidjson::SizeType arraySize = std::min( 3u, divArray.Size() );
for( rapidjson::SizeType i=0; i<arraySize; ++i )
{
if( divArray[i].IsUint() )
{
divisors[i] = divArray[i].GetUint();
}
else
{
hasError = true;
LogManager::getSingleton().logMessage(
"Array with 3 integers expected in " + jobName + ". "
"Syntax is thread_groups_based_on_texture : { \"slot\" "
": 0, \"divisor\" : [1, 1, 1] } or the short form: "
"thread_groups_based_on_texture : 0 (with no divisors)" );
}
}
}
if( !hasError )
{
job->setNumThreadGroupsBasedOn( threadGroupsBasedOn,
slot, divisors[0], divisors[1], divisors[2] );
}
}
}
示例12: gameFromJson
bool Globals::gameFromJson(SGame &game, const rapidjson::Value &jsonData)
{
game = {0};
// Parse json and validate
if (!jsonData.IsObject())
{
return false;
}
const auto &jsonGame = jsonData["game"];
const auto &jsonUsers = jsonData["users"];
if (!jsonGame.IsObject())
{
return false;
}
if (!jsonUsers.IsArray())
{
return false;
}
// Parse game
const auto &jsonGameId = jsonGame["id"];
if (!jsonGameId.IsInt64())
{
return false;
}
game.id = jsonGameId.GetInt64();
const auto &jsonGameSeed = jsonGame["seed"];
if (!jsonGameSeed.IsUint())
{
return false;
}
game.seed = jsonGameSeed.GetUint();
const auto &jsonGameStatus = jsonGame["status"];
if (!jsonGameStatus.IsString())
{
return false;
}
game.status = jsonGameStatus.GetString();
// Parse users
for (decltype(jsonUsers.Size()) i = 0; i < jsonUsers.Size(); ++i)
{
const auto &jsonUser = jsonUsers[i];
SUser user;
if (!userFromJson(user, jsonUser))
{
return false;
}
game.users.push_back(user);
}
return true;
}
示例13: 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;
}
示例14: JsonMembers
void JsonToObject<>(const rapidjson::Value& json, VideoAttachment* video) {
if (!json.IsObject()) {
THROW_AT(json::NotAnObjectException);
}
bool res = vk_api::FirstFieldToObject(
json, {"photo_640", "photo_320", "photo_130"}, &video->preview_url);
if (!res) {
THROW_AT(json::NoFieldException, "photo_*");
}
JsonMembers(json)("title", &video->title)("description", &video->description);
}
示例15: configure
void metrics_dump::configure(const rapidjson::Value& config) {
if (!config.IsObject()) {
return;
}
if (config.HasMember("interval")) {
const rapidjson::Value& interval = config["interval"];
if (interval.IsUint64()) {
this->interval = chrono::duration(interval.GetUint64(), chrono::time_unit::MSEC);
}
}
}