本文整理汇总了C++中json::Value::asDouble方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::asDouble方法的具体用法?C++ Value::asDouble怎么用?C++ Value::asDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::Value
的用法示例。
在下文中一共展示了Value::asDouble方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetJsonlonglong
int64_t GetJsonlonglong(const Json::Value& _jsValue)
{
return (_jsValue.type() == Json::realValue||
_jsValue.type() == Json::intValue||
_jsValue.type() == Json::uintValue) ? static_cast<int64_t>(_jsValue.asDouble()):0;
}
示例2:
double jsonNodeAs<double>(const Json::Value& node) {
if (node.isNull()) {
return 0;
}
return node.asDouble();
}
示例3: GetJsonDouble
double GetJsonDouble(const Json::Value& _jsValue)
{
return (_jsValue.type() == Json::realValue||
_jsValue.type() == Json::intValue||
_jsValue.type() == Json::uintValue) ? _jsValue.asDouble():0;
}
示例4: VerifyOptionf
void VerifyOptionf(Json::Value &Option, const float &Default, const float &Lower, const float &Upper)
{
if(Option.asDouble() < Lower || Option.asDouble() > Upper)
Option = Default;
}
示例5: ToPbSingle
int ToPbSingle(const Json::Value &value, const FieldDescriptor *pFieldDescriptor, Message &message, map<string, string>& key_map)
{
if (!check_type(value.type(), pFieldDescriptor->cpp_type()))
{
return 1;
}
const Reflection *pReflection = message.GetReflection();
EnumDescriptor *pEnumDes = NULL;
EnumValueDescriptor *pEnumValueDes = NULL;
int ret = 0;
switch(pFieldDescriptor->cpp_type())
{
case FieldDescriptor::CPPTYPE_INT32:
{
pReflection->SetInt32(&message, pFieldDescriptor, value.asInt());
break;
}
case FieldDescriptor::CPPTYPE_UINT32:
{
pReflection->SetUInt32(&message, pFieldDescriptor, value.asUInt());
break;
}
case FieldDescriptor::CPPTYPE_INT64:
{
pReflection->SetInt64(&message, pFieldDescriptor, value.asInt64());
break;
}
case FieldDescriptor::CPPTYPE_UINT64:
{
pReflection->SetUInt64(&message, pFieldDescriptor, value.asUInt64());
break;
}
case FieldDescriptor::CPPTYPE_STRING:
{
pReflection->SetString(&message, pFieldDescriptor, value.asString());
break;
}
case FieldDescriptor::CPPTYPE_BOOL:
{
pReflection->SetBool(&message, pFieldDescriptor, value.asBool());
break;
}
case FieldDescriptor::CPPTYPE_DOUBLE:
{
pReflection->SetDouble(&message, pFieldDescriptor, value.asDouble());
break;
}
case FieldDescriptor::CPPTYPE_FLOAT:
{
pReflection->SetFloat(&message, pFieldDescriptor, value.asFloat());
break;
}
case FieldDescriptor::CPPTYPE_ENUM:
{
if ((pEnumDes = (EnumDescriptor *)pFieldDescriptor->enum_type()) == NULL)
{
return 1;
}
if ((pEnumValueDes = (EnumValueDescriptor *)pEnumDes->FindValueByNumber(value.asInt())) == NULL)
{
return 1;
}
pReflection->SetEnum(&message, pFieldDescriptor, pEnumValueDes);
break;
}
case FieldDescriptor::CPPTYPE_MESSAGE:
{
Message *pmessage = pReflection->MutableMessage(&message, pFieldDescriptor);
if (key_map.size() == 0)
{
ret = ToPb(*pmessage, value);
}
else
{
ret = ToPbMap(*pmessage, value, key_map);
}
break;
}
default:
{
ret = 1;
break;
}
}
return ret;
}
示例6: PushJson
void LuaContext::PushJson(const Json::Value& value)
{
if (value.isString())
{
const std::string s = value.asString();
lua_pushlstring(lua_, s.c_str(), s.size());
}
else if (value.isDouble())
{
lua_pushnumber(lua_, value.asDouble());
}
else if (value.isInt())
{
lua_pushinteger(lua_, value.asInt());
}
else if (value.isUInt())
{
lua_pushinteger(lua_, value.asUInt());
}
else if (value.isBool())
{
lua_pushboolean(lua_, value.asBool());
}
else if (value.isNull())
{
lua_pushnil(lua_);
}
else if (value.isArray())
{
lua_newtable(lua_);
// http://lua-users.org/wiki/SimpleLuaApiExample
for (Json::Value::ArrayIndex i = 0; i < value.size(); i++)
{
// Push the table index (note the "+1" because of Lua conventions)
lua_pushnumber(lua_, i + 1);
// Push the value of the cell
PushJson(value[i]);
// Stores the pair in the table
lua_rawset(lua_, -3);
}
}
else if (value.isObject())
{
lua_newtable(lua_);
Json::Value::Members members = value.getMemberNames();
for (Json::Value::Members::const_iterator
it = members.begin(); it != members.end(); ++it)
{
// Push the index of the cell
lua_pushlstring(lua_, it->c_str(), it->size());
// Push the value of the cell
PushJson(value[*it]);
// Stores the pair in the table
lua_rawset(lua_, -3);
}
}
else
{
throw OrthancException(ErrorCode_JsonToLuaTable);
}
}
示例7: Deserialize_Double
void Deserialize_Double( const Json::Value& srcValue, F8 &dstValue )
{
CHK_VRET_IF_NOT( srcValue.isDouble() );
dstValue = srcValue.asDouble();
}
示例8: numberToString
std::string GlobalizationNDK::numberToString(const std::string& args)
{
if (args.empty()) {
slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::numberToString: no arguments provided!");
return errorInJson(UNKNOWN_ERROR, "No arguments provided!");
}
Json::Reader reader;
Json::Value root;
bool parse = reader.parse(args, root);
if (!parse) {
slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::numberToString: invalid json data: %s",
args.c_str());
return errorInJson(PARSING_ERROR, "Invalid json data!");
}
Json::Value nv = root["number"];
if (nv.isNull()) {
slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::numberToString: no number provided!");
return errorInJson(FORMATTING_ERROR, "No number provided!");
}
if (!nv.isNumeric()) {
slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::numberToString: invalid number type: %d!",
nv.type());
return errorInJson(FORMATTING_ERROR, "Invalid number type!");
}
// This is the default value when no options provided.
ENumberType type = kNumberDecimal;
Json::Value options = root["options"];
std::string error;
if (!handleNumberOptions(options, type, error))
return errorInJson(PARSING_ERROR, error);
UErrorCode status = U_ZERO_ERROR;
NumberFormat* nf;
switch (type) {
case kNumberDecimal:
default:
nf = NumberFormat::createInstance(status);
break;
case kNumberCurrency:
nf = NumberFormat::createCurrencyInstance(status);
break;
case kNumberPercent:
nf = NumberFormat::createPercentInstance(status);
break;
}
if (!nf) {
slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::numberToString: failed to create NumberFormat instance for type %d: %d",
status, type);
return errorInJson(UNKNOWN_ERROR, "Failed to create NumberFormat instance!");
}
std::auto_ptr<NumberFormat> deleter(nf);
UnicodeString result;
nf->format(nv.asDouble(), result);
std::string utf8;
result.toUTF8String(utf8);
return resultInJson(utf8);
}
示例9: fprintf
static void
printValueTree(FILE* fout, Json::Value& value, const std::string& path = ".") {
if (value.hasComment(Json::commentBefore)) {
fprintf(fout, "%s\n", value.getComment(Json::commentBefore).c_str());
}
switch (value.type()) {
case Json::nullValue:
fprintf(fout, "%s=null\n", path.c_str());
break;
case Json::intValue:
fprintf(fout,
"%s=%s\n",
path.c_str(),
Json::valueToString(value.asLargestInt()).c_str());
break;
case Json::uintValue:
fprintf(fout,
"%s=%s\n",
path.c_str(),
Json::valueToString(value.asLargestUInt()).c_str());
break;
case Json::realValue:
fprintf(fout,
"%s=%s\n",
path.c_str(),
normalizeFloatingPointStr(value.asDouble()).c_str());
break;
case Json::stringValue:
fprintf(fout, "%s=\"%s\"\n", path.c_str(), value.asString().c_str());
break;
case Json::booleanValue:
fprintf(fout, "%s=%s\n", path.c_str(), value.asBool() ? "true" : "false");
break;
case Json::arrayValue: {
fprintf(fout, "%s=[]\n", path.c_str());
int size = value.size();
for (int index = 0; index < size; ++index) {
static char buffer[16];
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
sprintf_s(buffer, sizeof(buffer), "[%d]", index);
#else
snprintf(buffer, sizeof(buffer), "[%d]", index);
#endif
printValueTree(fout, value[index], path + buffer);
}
} break;
case Json::objectValue: {
fprintf(fout, "%s={}\n", path.c_str());
Json::Value::Members members(value.getMemberNames());
std::sort(members.begin(), members.end());
std::string suffix = *(path.end() - 1) == '.' ? "" : ".";
for (Json::Value::Members::iterator it = members.begin();
it != members.end();
++it) {
const std::string& name = *it;
printValueTree(fout, value[name], path + suffix + name);
}
} break;
default:
break;
}
if (value.hasComment(Json::commentAfter)) {
fprintf(fout, "%s\n", value.getComment(Json::commentAfter).c_str());
}
}
示例10: SetSingleValueForMessage
static bool SetSingleValueForMessage(const Reflection* reflection,
Message* pb,
const FieldDescriptor* field,
const Json::Value& node) {
switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
reflection->SetInt32(pb, field, node.asInt());
break;
case FieldDescriptor::CPPTYPE_INT64: {
int64_t number = 0;
if (!StringToInt64(node.asString(), &number)) {
LOG(WARNING) << "Fail to convert to interger:" << node.asString();
return false;
}
reflection->SetInt64(pb, field, number);
break;
}
case FieldDescriptor::CPPTYPE_UINT32:
reflection->SetUInt32(pb, field, node.asUInt());
break;
case FieldDescriptor::CPPTYPE_UINT64: {
uint64_t number = 0;
if (!StringToUint64(node.asString(), &number)) {
LOG(WARNING) << "Fail to convert to interger:" << node.asString();
return false;
}
reflection->SetUInt64(pb, field, number);
break;
}
case FieldDescriptor::CPPTYPE_DOUBLE:
reflection->SetDouble(pb, field, node.asDouble());
break;
case FieldDescriptor::CPPTYPE_FLOAT:
reflection->SetFloat(pb, field, node.asDouble());
break;
case FieldDescriptor::CPPTYPE_BOOL:
reflection->SetBool(pb, field, node.asBool());
break;
case FieldDescriptor::CPPTYPE_ENUM: {
const EnumValueDescriptor* enum_value = reflection->GetEnum(*pb, field);
const EnumDescriptor* enum_desc = enum_value->type();
const EnumValueDescriptor* real_enum_value = enum_desc->FindValueByNumber(node.asInt());
reflection->SetEnum(pb, field, real_enum_value);
break;
}
case FieldDescriptor::CPPTYPE_STRING:
reflection->SetString(pb, field, node.asString());
break;
case FieldDescriptor::CPPTYPE_MESSAGE: {
Message* sub_pb = reflection->MutableMessage(pb, field);
if (!ParseFromJsonValue(node, sub_pb)) {
return false;
}
break;
}
default:
CHECK(false) << "bad type:" << field->cpp_type();
break;
}
return true;
}
示例11: SetRepeatedValueForMessage
static bool SetRepeatedValueForMessage(const Reflection* reflection,
Message* pb,
const FieldDescriptor* field,
const Json::Value& sub_node) {
switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
reflection->AddInt32(pb, field, sub_node.asInt());
break;
case FieldDescriptor::CPPTYPE_INT64: {
int64_t number = 0;
if (!StringToInt64(sub_node.asString(), &number)) {
LOG(WARNING) << "Fail to convert to interger:" << sub_node.asString();
return false;
}
reflection->AddInt64(pb, field, number);
break;
}
case FieldDescriptor::CPPTYPE_UINT32:
reflection->AddUInt32(pb, field, sub_node.asUInt());
break;
case FieldDescriptor::CPPTYPE_UINT64: {
uint64_t number = 0;
if (!StringToUint64(sub_node.asString(), &number)) {
LOG(WARNING) << "Fail to convert to interger:" << sub_node.asString();
return false;
}
reflection->AddUInt64(pb, field, number);
break;
}
case FieldDescriptor::CPPTYPE_DOUBLE:
reflection->AddDouble(pb, field, sub_node.asDouble());
break;
case FieldDescriptor::CPPTYPE_FLOAT:
reflection->AddFloat(pb, field, sub_node.asDouble());
break;
case FieldDescriptor::CPPTYPE_BOOL:
reflection->AddBool(pb, field, sub_node.asBool());
break;
case FieldDescriptor::CPPTYPE_ENUM: {
const EnumValueDescriptor* enum_value = reflection->GetEnum(*pb, field);
const EnumDescriptor* enum_desc = enum_value->type();
const EnumValueDescriptor* real_enum_value = enum_desc->FindValueByNumber(sub_node.asInt());
reflection->AddEnum(pb, field, real_enum_value);
break;
}
case FieldDescriptor::CPPTYPE_STRING:
reflection->AddString(pb, field, sub_node.asString());
break;
case FieldDescriptor::CPPTYPE_MESSAGE:
{
MessageFactory* factory = MessageFactory::generated_factory();
Message* message = reflection->AddMessage(pb, field, factory);
util::ProtoJsonFormat::ParseFromValue(sub_node, message);
break;
}
default:
LOG(FATAL) << "Bad type:" << field->cpp_type();
break;
}
return true;
}
示例12: print_value_tree
static void print_value_tree( FILE *fout, Json::Value &value, const std::string &path = "." )
{
switch (value.type())
{
case Json::nullValue:
fprintf( fout, "%s=null\n", path.c_str() );
break;
case Json::intValue:
fprintf( fout, "%s=%d\n", path.c_str(), value.asInt() );
break;
case Json::uintValue:
fprintf( fout, "%s=%u\n", path.c_str(), value.asUInt() );
break;
case Json::realValue:
fprintf( fout, "%s=%.16g\n", path.c_str(), value.asDouble() );
break;
case Json::stringValue:
fprintf( fout, "%s=\"%s\"\n", path.c_str(), value.asString().c_str() );
break;
case Json::booleanValue:
fprintf( fout, "%s=%s\n", path.c_str(), value.asBool() ? "true" : "false" );
break;
case Json::arrayValue:
{
fprintf( fout, "%s=[] arrayValue \n", path.c_str() );
int size = value.size();
for ( int index =0; index < size; ++index )
{
static char buffer[16];
sprintf( buffer, "[%d]", index );
print_value_tree( fout, value[index], path + buffer);
}
}
break;
case Json::objectValue:
{
fprintf( fout, "%s={} objectValue \n", path.c_str() );
Json::Value::Members members( value.getMemberNames() );
std::sort( members.begin(), members.end() );
std::string suffix = *(path.end()-1) == '.' ? "" : ".";
for ( Json::Value::Members::iterator it = members.begin(); it != members.end();++it)
{
const std::string &name = *it;
print_value_tree( fout, value[name], path + suffix + name );
}
}
break;
default:
break;
}
}
示例13: set
void OptionNumber::set(Json::Value &value)
{
_value = value.asDouble();
}
示例14: parseDouble
double FileParser::parseDouble(const Json::Value& node, const string& nodeName) const {
if (node == Json::nullValue) {
throw RenderException("unable to parse double for \"" + nodeName + "\"");
}
return node.asDouble();
}
示例15: filmonAPIgetRecordingsTimers
// Gets all timers and recordings
bool filmonAPIgetRecordingsTimers(bool completed) {
bool res = filmonRequest("tv/api/dvr/list", sessionKeyParam);
if (res == true) {
Json::Value root;
Json::Reader reader;
reader.parse(response, root);
// Usage
Json::Value total = root["userStorage"]["total"];
Json::Value used = root["userStorage"]["recorded"];
storageTotal = (long long int) (total.asDouble() * FILMON_ONE_HOUR_RECORDING_SIZE); // bytes
storageUsed = (long long int) (used.asDouble() * FILMON_ONE_HOUR_RECORDING_SIZE); // bytes
XBMC->Log(LOG_DEBUG, "recordings total is %u", storageTotal);
XBMC->Log(LOG_DEBUG, "recordings used is %u", storageUsed);
bool timersCleared = false;
bool recordingsCleared = false;
Json::Value recordingsTimers = root["recordings"];
for (unsigned int recordingId = 0;
recordingId < recordingsTimers.size(); recordingId++) {
std::string recTimId =
recordingsTimers[recordingId]["id"].asString();
std::string recTimTitle =
recordingsTimers[recordingId]["title"].asString();
unsigned int recTimStart = stringToInt(
recordingsTimers[recordingId]["time_start"].asString());
unsigned int recDuration = stringToInt(
recordingsTimers[recordingId]["length"].asString());
Json::Value status = recordingsTimers[recordingId]["status"];
if (completed && status.asString().compare(std::string(RECORDED_STATUS)) == 0) {
if (recordingsCleared == false) {
recordings.clear();
recordingsCleared = true;
}
FILMON_RECORDING recording;
recording.strRecordingId = recTimId;
recording.strTitle = recTimTitle;
recording.strStreamURL =
recordingsTimers[recordingId]["download_link"].asString();
recording.strPlot =
recordingsTimers[recordingId]["description"].asString();
recording.recordingTime = recTimStart;
recording.iDuration = recDuration;
recording.strIconPath = recordingsTimers[recordingId]["images"]["channel_logo"].asString();
recording.strThumbnailPath = recordingsTimers[recordingId]["images"]["poster"].asString();
recordings.push_back(recording);
XBMC->Log(LOG_DEBUG, "found completed recording %s", recording.strTitle.c_str());
} else if (status.asString().compare(std::string(TIMER_STATUS))
== 0) {
if (timersCleared == false) {
timers.clear();
timersCleared = true;
}
FILMON_TIMER timer;
timer.iClientIndex = stringToInt(recTimId);
timer.iClientChannelUid = stringToInt(
recordingsTimers[recordingId]["channel_id"].asString());
timer.startTime = recTimStart;
timer.endTime = timer.startTime + recDuration;
timer.strTitle = recTimTitle;
timer.state = FILMON_TIMER_STATE_NEW;
timer.strSummary =
recordingsTimers[recordingId]["description"].asString();
setTimerDefaults(&timer);
time_t t = time(0);
if (t >= timer.startTime && t <= timer.endTime) {
XBMC->Log(LOG_DEBUG, "found active timer %s", timer.strTitle.c_str());
timer.state = FILMON_TIMER_STATE_RECORDING;
} else if (t < timer.startTime) {
XBMC->Log(LOG_DEBUG, "found scheduled timer %s", timer.strTitle.c_str());
timer.state = FILMON_TIMER_STATE_SCHEDULED;
} else if (t > timer.endTime) {
XBMC->Log(LOG_DEBUG, "found completed timer %s", timer.strTitle.c_str());
timer.state = FILMON_TIMER_STATE_COMPLETED;
}
timers.push_back(timer);
}
}
clearResponse();
}
return res;
}