本文整理汇总了C++中rapidjson::Value类的典型用法代码示例。如果您正苦于以下问题:C++ Value类的具体用法?C++ Value怎么用?C++ Value使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Value类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RapidjsonSerialize
QString Util::RapidjsonSerialize(const rapidjson::Value &val) {
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
val.Accept(writer);
return buffer.GetString();
}
示例2:
cocos2d::Value JsonUtils::json2Value(rapidjson::Value &json) {
JsonValueConverter converter;
json.Accept(converter);
return converter.getValue();
}
示例3: initialize
virtual bool initialize(const rapidjson::Value &config) {
daemonize();
if (!m_elliptics.initialize(config, logger()))
return false;
m_async.initialize(logger());
if (config.HasMember("noauth")) {
m_noauth_allowed = std::string(config["noauth"].GetString()) == "allowed";
}
if (config.HasMember("cache")) {
m_cache = std::make_shared<rift::cache>();
if (!m_cache->initialize(config["cache"], m_elliptics.node(), logger(),
&m_async, m_elliptics.metadata_groups()))
return false;
}
if (config.HasMember("bucket")) {
m_bucket = std::make_shared<rift::bucket>();
if (!m_bucket->initialize(config["bucket"], m_elliptics, &m_async))
return false;
} else {
m_noauth_allowed = true;
}
if (config.HasMember("redirect-port")) {
m_redirect_port = config["redirect-port"].GetInt();
} else {
m_redirect_port = -1;
}
if (config.HasMember("https")) {
m_secured_http = config["https"].GetBool();
} else {
m_secured_http = false;
}
on<rift::index::on_update<example_server>>(
options::exact_match("/update"),
options::methods("POST")
);
on<rift::index::on_find<example_server>>(
options::exact_match("/find"),
options::methods("GET")
);
on<rift::io::on_redirectable_get<example_server>>(
options::exact_match("/redirect"),
options::methods("GET")
);
on<rift::io::on_get<example_server>>(
options::exact_match("/get"),
options::methods("GET")
);
on<rift::io::on_buffered_get<example_server>>(
options::exact_match("/get-big"),
options::methods("GET")
);
on<rift::io::on_upload<example_server>>(
options::exact_match("/upload"),
options::methods("POST")
);
on<rift::io::on_buffered_upload<example_server>>(
options::exact_match("/upload-big"),
options::methods("POST")
);
on<rift::io::on_download_info<example_server>>(
options::exact_match("/download-info"),
options::methods("GET")
);
on<rift::common::on_ping<example_server>>(
options::exact_match("/ping"),
options::methods("GET")
);
on<rift::common::on_echo<example_server>>(
options::exact_match("/echo"),
options::methods("GET")
);
return true;
}
示例4: parse_response_data
int32_t fetch::parse_response_data(const rapidjson::Value& _data)
{
try
{
bool have_webrtc_event = false;
auto iter_events = _data.FindMember("events");
if (iter_events != _data.MemberEnd() && iter_events->value.IsArray())
{
for (auto iter_evt = iter_events->value.Begin(); iter_evt != iter_events->value.End(); iter_evt++)
{
auto iter_type = iter_evt->FindMember("type");
auto iter_event_data = iter_evt->FindMember("eventData");
if (iter_type != iter_evt->MemberEnd() && iter_event_data != iter_evt->MemberEnd() &&
iter_type->value.IsString())
{
std::string event_type = iter_type->value.GetString();
if (event_type == "buddylist")
push_event(std::make_shared<fetch_event_buddy_list>())->parse(iter_event_data->value);
else if (event_type == "presence")
push_event(std::make_shared<fetch_event_presence>())->parse(iter_event_data->value);
else if (event_type == "histDlgState")
push_event(std::make_shared<fetch_event_dlg_state>())->parse(iter_event_data->value);
else if (event_type == "webrtcMsg")
have_webrtc_event = true;
else if (event_type == "hiddenChat")
push_event(std::make_shared<fetch_event_hidden_chat>())->parse(iter_event_data->value);
else if (event_type == "diff")
push_event(std::make_shared<fetch_event_diff>())->parse(iter_event_data->value);
else if (event_type == "myInfo")
push_event(std::make_shared<fetch_event_my_info>())->parse(iter_event_data->value);
else if (event_type == "userAddedToBuddyList")
push_event(std::make_shared<fetch_event_user_added_to_buddy_list>())->parse(iter_event_data->value);
else if (event_type == "typing")
push_event(std::make_shared<fetch_event_typing>())->parse(iter_event_data->value);
else if (event_type == "sessionEnded")
session_ended_ = true;
else if (event_type == "permitDeny")
push_event(std::make_shared<fetch_event_permit>())->parse(iter_event_data->value);
/*
else if (event_type == L"mchat")
PushEvent(std::make_shared<fetch_event_mchat>())->Parse(wr);
*/
}
}
}
if (!session_ended_)
{
auto iter_next_fetch_url = _data.FindMember("fetchBaseURL");
if (iter_next_fetch_url == _data.MemberEnd() || !iter_next_fetch_url->value.IsString())
return wpie_http_parse_response;
next_fetch_url_ = iter_next_fetch_url->value.GetString();
next_fetch_time_ = std::chrono::system_clock::now();
auto iter_time_to_next_fetch = _data.FindMember("timeToNextFetch");
if (iter_time_to_next_fetch != _data.MemberEnd() && iter_time_to_next_fetch->value.IsUint())
{
time_t fetch_timeout = iter_time_to_next_fetch->value.GetUint();
next_fetch_time_ += std::chrono::milliseconds(fetch_timeout);
}
auto iter_ts = _data.FindMember("ts");
if (iter_ts == _data.MemberEnd() || !iter_ts->value.IsUint())
return wpie_http_parse_response;
ts_ = iter_ts->value.GetUint();
time_offset_ = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()) - ts_;
}
if (have_webrtc_event) {
auto we = std::make_shared<webrtc_event>();
if (!!we) {
// sorry... the simplest way
we->parse(response_str());
push_event(we);
} else {
assert(false);
}
}
}
catch (const std::exception&)
{
}
return 0;
}
示例5: unserialize
int32_t my_info::unserialize(const rapidjson::Value& _node)
{
auto iter_aimid = _node.FindMember("aimId");
if (iter_aimid != _node.MemberEnd() && iter_aimid->value.IsString())
aimId_ = iter_aimid->value.GetString();
auto iter_displayId = _node.FindMember("displayId");
if (iter_displayId != _node.MemberEnd() && iter_displayId->value.IsString())
displayId_ = iter_displayId->value.GetString();
auto iter_friendlyName = _node.FindMember("friendly");
if (iter_friendlyName != _node.MemberEnd() && iter_friendlyName->value.IsString())
friendlyName_ = iter_friendlyName->value.GetString();
auto iter_state = _node.FindMember("state");
if (iter_state != _node.MemberEnd() && iter_state->value.IsString())
state_ = iter_state->value.GetString();
auto iter_userType = _node.FindMember("userType");
if (iter_userType != _node.MemberEnd() && iter_userType->value.IsString())
userType_ = iter_userType->value.GetString();
auto iter_phoneNumber = _node.FindMember("attachedPhoneNumber");
if (iter_phoneNumber != _node.MemberEnd() && iter_phoneNumber->value.IsString())
phoneNumber_ = iter_phoneNumber->value.GetString();
auto iter_flags = _node.FindMember("globalFlags");
if (iter_flags != _node.MemberEnd() && iter_flags->value.IsUint())
flags_ = iter_flags->value.GetUint();
if (state_ == "occupied" || state_ == "na" || state_ == "busy")
state_ = "dnd";
else if (state_ != "offline" && state_ != "invisible")
state_ = "online";
return 0;
}
示例6: unserialize
bool gui_settings::unserialize(const rapidjson::Value& _node)
{
auto iter_show_in_taskbar = _node.FindMember(settings_show_in_taskbar);
if (iter_show_in_taskbar != _node.MemberEnd() && iter_show_in_taskbar->value.IsBool())
{
tools::binary_stream bs;
bs.write<bool>(iter_show_in_taskbar->value.GetBool());
set_value(settings_show_in_taskbar, bs);
}
auto iter_enable_sounds = _node.FindMember(settings_sounds_enabled);
if (iter_enable_sounds != _node.MemberEnd() && iter_enable_sounds->value.IsBool())
{
tools::binary_stream bs;
bs.write<bool>(iter_enable_sounds->value.GetBool());
set_value(settings_sounds_enabled, bs);
}
auto iter_autosave_files = _node.FindMember(settings_download_files_automatically);
if (iter_autosave_files != _node.MemberEnd() && iter_autosave_files->value.IsBool())
{
tools::binary_stream bs;
bs.write<bool>(iter_autosave_files->value.GetBool());
set_value(settings_download_files_automatically, bs);
}
auto iter_download_folder = _node.FindMember(settings_download_directory);
if (iter_download_folder != _node.MemberEnd() && iter_download_folder->value.IsString())
{
tools::binary_stream bs;
std::string folder = iter_download_folder->value.GetString();
bs.write(folder.c_str(), folder.length() + 1);
set_value(settings_download_directory, bs);
}
auto iter_send_hotkey = _node.FindMember(settings_key1_to_send_message);
if (iter_send_hotkey != _node.MemberEnd() && iter_send_hotkey->value.IsInt())
{
tools::binary_stream bs;
bs.write<int32_t>(iter_send_hotkey->value.GetInt());
set_value(settings_key1_to_send_message, bs);
}
auto iter_enable_preview = _node.FindMember(settings_show_video_and_images);
if (iter_enable_preview != _node.MemberEnd() && iter_enable_preview->value.IsBool())
{
tools::binary_stream bs;
bs.write<bool>(iter_enable_preview->value.GetBool());
set_value(settings_show_video_and_images, bs);
}
auto iter_language = _node.FindMember(settings_language);
if (iter_language != _node.MemberEnd() && iter_language->value.IsString())
{
tools::binary_stream bs;
std::string folder = iter_language->value.GetString();
bs.write(folder.c_str(), folder.length() + 1);
set_value(settings_language, bs);
}
auto iter_notify = _node.FindMember(settings_notify_new_messages);
if (iter_notify != _node.MemberEnd() && iter_notify->value.IsBool())
{
tools::binary_stream bs;
bs.write<bool>(iter_notify->value.GetBool());
set_value(settings_notify_new_messages, bs);
}
return true;
}
示例7: parseValue
static void parseValue(SettingValue &value, const rapidjson::Value &json_val)
{
if (json_val.IsInt())
value = json_val.GetInt();
else if (json_val.IsString())
value = std::string(json_val.GetString(), json_val.GetStringLength());
else if (json_val.IsBool())
value = json_val.GetBool();
else if (json_val.IsArray())
{
SettingList value_list;
for (auto it = json_val.Begin(); it != json_val.End(); ++it)
{
SettingValue child_val;
parseValue(child_val, *it);
value_list.push_back(child_val);
}
value = value_list;
}
else if (json_val.IsObject())
{
SettingMap value_map;
for (auto it = json_val.MemberBegin(); it != json_val.MemberEnd(); ++it)
{
SettingValue child_val;
parseValue(child_val, it->value);
value_map[it->name.GetString()] = child_val;
}
value = value_map;
}
else
throw std::runtime_error("Unexpected JSON value type.");
}
示例8: fromJson
bool fromJson(const rapidjson::Value &v, Mat4f &dst)
{
if (v.IsArray()) {
ASSERT(v.Size() == 16, "Cannot convert Json Array to 4x4 Matrix: Invalid size");
for (unsigned i = 0; i < 16; ++i)
dst[i] = as<float>(v[i]);
return true;
} else if (v.IsObject()) {
Vec3f x(1.0f, 0.0f, 0.0f);
Vec3f y(0.0f, 1.0f, 0.0f);
Vec3f z(0.0f, 0.0f, 1.0f);
Vec3f pos(0.0f);
fromJson(v, "position", pos);
bool explicitX = false, explicitY = false, explicitZ = false;
Vec3f lookAt;
if (fromJson(v, "look_at", lookAt)) {
z = lookAt - pos;
explicitZ = true;
}
explicitY = fromJson(v, "up", y);
explicitX = fromJson(v, "x_axis", x) || explicitX;
explicitY = fromJson(v, "y_axis", y) || explicitY;
explicitZ = fromJson(v, "z_axis", z) || explicitZ;
int id =
(explicitZ ? 4 : 0) +
(explicitY ? 2 : 0) +
(explicitX ? 1 : 0);
switch (id) {
case 0: gramSchmidt(z, y, x); break;
case 1: gramSchmidt(x, z, y); break;
case 2: gramSchmidt(y, z, x); break;
case 3: gramSchmidt(y, x, z); break;
case 4: gramSchmidt(z, y, x); break;
case 5: gramSchmidt(z, x, y); break;
case 6: gramSchmidt(z, y, x); break;
case 7: gramSchmidt(z, y, x); break;
}
if (x.cross(y).dot(z) < 0.0f) {
if (!explicitX)
x = -x;
else if (!explicitY)
y = -y;
else
z = -z;
}
Vec3f scale;
if (fromJson(v, "scale", scale)) {
x *= scale.x();
y *= scale.y();
z *= scale.z();
}
Vec3f rot;
if (fromJson(v, "rotation", rot)) {
Mat4f tform = Mat4f::rotYXZ(rot);
x = tform*x;
y = tform*y;
z = tform*z;
}
dst = Mat4f(
x[0], y[0], z[0], pos[0],
x[1], y[1], z[1], pos[1],
x[2], y[2], z[2], pos[2],
0.0f, 0.0f, 0.0f, 1.0f
);
return true;
}
return false;
}
示例9: LOG_DEBUG
// Create an ACR message from a JSON descriptor. Most AVPs are auto-created from the
// contents parameter which should be a JSON object with keys named after AVPs. For example
// this object could be the "event" part of the original HTTP request received by Ralf.
AccountingRequest::AccountingRequest(const Dictionary* dict,
Diameter::Stack* diameter_stack,
const std::string& session_id,
const std::string& dest_host,
const std::string& dest_realm,
const uint32_t& record_number,
const rapidjson::Value& contents) :
Diameter::Message(dict, dict->ACCOUNTING_REQUEST, diameter_stack)
{
LOG_DEBUG("Building an Accounting-Request");
// Fill in the default fields
if (session_id == "")
{
add_new_session_id();
}
else
{
add_session_id(session_id);
}
add_origin();
add_app_id(Dictionary::Application::ACCT, dict->RF);
// Fill in contributed fields
Diameter::Dictionary::AVP dest_host_dict("Destination-Host");
Diameter::AVP dest_host_avp(dest_host_dict);
add(dest_host_avp.val_str(dest_host));
Diameter::Dictionary::AVP dest_realm_dict("Destination-Realm");
Diameter::AVP dest_realm_avp(dest_realm_dict);
add(dest_realm_avp.val_str(dest_realm));
Diameter::Dictionary::AVP record_number_dict("Accounting-Record-Number");
Diameter::AVP record_number_avp(record_number_dict);
add(record_number_avp.val_i32(record_number));
if (contents.GetType() != rapidjson::kObjectType)
{
LOG_ERROR("Cannot build ACR from JSON type %d", contents.GetType());
return;
}
// Fill in the dynamic fields
for (rapidjson::Value::ConstMemberIterator it = contents.MemberBegin();
it != contents.MemberEnd();
++it)
{
try
{
switch (it->value.GetType())
{
case rapidjson::kFalseType:
case rapidjson::kTrueType:
case rapidjson::kNullType:
LOG_ERROR("Invalid format (true/false) in JSON block, ignoring");
continue;
case rapidjson::kStringType:
case rapidjson::kNumberType:
case rapidjson::kObjectType:
{
Diameter::Dictionary::AVP new_dict(VENDORS, it->name.GetString());
Diameter::AVP avp(new_dict);
add(avp.val_json(VENDORS, new_dict, it->value));
}
break;
case rapidjson::kArrayType:
for (rapidjson::Value::ConstValueIterator array_iter = it->value.Begin();
array_iter != it->value.End();
++array_iter)
{
Diameter::Dictionary::AVP new_dict(VENDORS, it->name.GetString());
Diameter::AVP avp(new_dict);
add(avp.val_json(VENDORS, new_dict, *array_iter));
}
break;
}
}
catch (Diameter::Stack::Exception e)
{
LOG_WARNING("AVP %s not recognised, ignoring", it->name.GetString());
}
}
}
示例10:
template<> inline unsigned
conf_getter<unsigned>(const rapidjson::Value & value)
{
return value.GetUint();
}
示例11: name
/*
* Irregularly spaced sequence
*/
MultiEchoFlexSequence::MultiEchoFlexSequence(const rapidjson::Value &json) {
if (json.IsNull())
QI::Fail("Could not read sequence: {}", name());
TR = GetMember(json, "TR").GetDouble();
TE = ArrayFromJSON(json, "TE");
}
示例12: serialize
void favorite::serialize(rapidjson::Value& _node, rapidjson_allocator& _a)
{
_node.AddMember("aimId", get_aimid(), _a);
_node.AddMember("time", time_, _a);
}
示例13: handlePlatformMessage
std::string PersonManager::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 == "performAction")
{
return this->handlePerformAction(content);
}
else if (operation == "expandPersonMenu")
{
return this->handleExpandPersonMenu(content);
}
else if (operation == "dressFigure")
{
return this->handleDressFigure(content);
}
else if (operation == "updateSpouseScene")
{
return this->handleUpdateSpouseScene(content);
}
else if (operation == "setSpouseMessage")
{
if (content.HasMember("MESSAGE") == false)
{
return "missing MESSAGE";
}
else
{
std::string message = content["MESSAGE"].GetString();
mSpouseMessage.setValue(message);
mSpouseMessage.notify();
return SUCC;
}
}
else if (operation == "setFigureResourceDir")
{
assert(content.HasMember("DIRECTORY"));
std::string resourceDir = content["DIRECTORY"].GetString();
FigureResourceManager::getInstance()->setResourceDir(resourceDir);
return SUCC;
}
else
{
return std::string("invalid OPERATION: ") + operation;
}
}
示例14: ConvertToJSON
void ConvertToJSON(const msgpack::object& object, rapidjson::Value& value, rapidjson::MemoryPoolAllocator<>& allocator)
{
switch (object.type)
{
case msgpack::type::BOOLEAN:
value.SetBool(object.as<bool>());
break;
case msgpack::type::POSITIVE_INTEGER:
case msgpack::type::NEGATIVE_INTEGER:
value.SetInt(object.as<int>());
break;
case msgpack::type::FLOAT:
value.SetDouble(object.as<double>());
break;
case msgpack::type::STR:
{
std::string string = object.as<std::string>();
value.SetString(string.c_str(), string.size(), allocator);
break;
}
case msgpack::type::ARRAY:
{
auto list = object.as<std::vector<msgpack::object>>();
value.SetArray();
for (auto& entry : list)
{
rapidjson::Value inValue;
ConvertToJSON(entry, inValue, allocator);
value.PushBack(inValue, allocator);
}
break;
}
case msgpack::type::MAP:
{
auto list = object.as<std::map<std::string, msgpack::object>>();
value.SetObject();
for (auto& entry : list)
{
rapidjson::Value inValue;
ConvertToJSON(entry.second, inValue, allocator);
rapidjson::Value name;
name.SetString(entry.first.c_str(), entry.first.size(), allocator);
value.AddMember(name, inValue, allocator);
}
break;
}
default:
value.SetNull();
break;
}
}
示例15: loadImages
UnitType::UnitType(const rapidjson::Value &json)
: name{},
plural{},
moves{1},
initiative{0},
hp{1},
minDmg{0},
maxDmg{0},
minDmgRanged{0},
maxDmgRanged{0},
growth{1},
traits{},
spell{nullptr},
baseImg{},
reverseImg{},
imgMove{},
reverseImgMove{},
sndMove{},
animAttack{},
reverseAnimAttack{},
attackFrames{},
animRanged{},
reverseAnimRanged{},
rangedFrames{},
projectile{},
sndAttack{},
sndRanged{},
imgDefend{},
reverseImgDefend{},
sndDefend{},
animDie{},
reverseAnimDie{},
dieFrames{},
sndDie{}
{
bool hasRangedAttack = false;
if (json.HasMember("name")) {
name = json["name"].GetString();
}
if (json.HasMember("plural")) {
plural = json["plural"].GetString();
}
if (json.HasMember("initiative")) {
initiative = json["initiative"].GetInt();
}
if (json.HasMember("hp")) {
hp = json["hp"].GetInt();
}
if (json.HasMember("img")) {
loadImages(json, "img", baseImg, reverseImg);
}
if (json.HasMember("img-move")) {
loadImages(json, "img-move", imgMove, reverseImgMove);
}
if (json.HasMember("img-defend")) {
loadImages(json, "img-defend", imgDefend, reverseImgDefend);
}
if (json.HasMember("anim-attack") && json.HasMember("attack-frames")) {
loadAnimation(json, "anim-attack", animAttack, reverseAnimAttack,
"attack-frames", attackFrames);
}
if (json.HasMember("anim-ranged") && json.HasMember("ranged-frames")) {
loadAnimation(json, "anim-ranged", animRanged, reverseAnimRanged,
"ranged-frames", rangedFrames);
}
if (json.HasMember("damage")) {
const auto &damageList = json["damage"];
minDmg = damageList[0u].GetInt();
maxDmg = damageList[1u].GetInt();
}
if (json.HasMember("damage-ranged")) {
hasRangedAttack = true;
const auto &damageList = json["damage-ranged"];
minDmgRanged = damageList[0u].GetInt();
maxDmgRanged = damageList[1u].GetInt();
}
if (json.HasMember("growth")) {
growth = json["growth"].GetInt();
}
if (json.HasMember("projectile")) {
projectile = sdlLoadImage(json["projectile"].GetString());
}
if (json.HasMember("sound-move")) {
sndMove = sdlLoadSound(json["sound-move"].GetString());
}
if (json.HasMember("sound-attack")) {
sndAttack = sdlLoadSound(json["sound-attack"].GetString());
}
if (json.HasMember("sound-ranged")) {
sndRanged = sdlLoadSound(json["sound-ranged"].GetString());
}
if (json.HasMember("sound-defend")) {
sndDefend = sdlLoadSound(json["sound-defend"].GetString());
}
if (json.HasMember("sound-die")) {
sndDie = sdlLoadSound(json["sound-die"].GetString());
}
if (json.HasMember("anim-die") && json.HasMember("die-frames")) {
//.........这里部分代码省略.........