本文整理汇总了C++中json::Value::asFloat方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::asFloat方法的具体用法?C++ Value::asFloat怎么用?C++ Value::asFloat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::Value
的用法示例。
在下文中一共展示了Value::asFloat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: jsonToValues
Values Factory::jsonToValues(const Json::Value& values)
{
Values outValues;
if (values.isInt())
outValues.emplace_back(values.asInt());
else if (values.isDouble())
outValues.emplace_back(values.asFloat());
else if (values.isArray())
for (const auto& v : values)
{
if (v.isInt())
outValues.emplace_back(v.asInt());
else if (v.isDouble())
outValues.emplace_back(v.asFloat());
else if (v.isArray())
outValues.emplace_back(jsonToValues(v));
else
outValues.emplace_back(v.asString());
}
else
outValues.emplace_back(values.asString());
return outValues;
}
示例2: GetVal
void GetVal(Json::Value &config, float* setting)
{
if (config.isNull())
return;
*setting = config.asFloat();
}
示例3: Deserialize
bool Deserialize ( const Json::Value& json_val, float & obj_val )
{
if ( json_val.isDouble () )
{
obj_val = json_val.asFloat ();
return true;
}
return false;
}
示例4: GetFloat32
bool GetFloat32(const Json::Value& value, float32_t* out) {
if (value.isNull()) {
return false;
}
if (!value.isDouble()) {
return false;
}
*out = value.asFloat();
return true;
}
示例5: asFloat
float JsonUtils::asFloat(const Json::Value &value, float defaultValue)
{
float returned = defaultValue;
if(value.isString())
returned = Ogre::StringConverter::parseReal(value.asString(), defaultValue);
if(value.isNumeric())
returned = value.asFloat();
return returned;
}
示例6:
std::vector<float> ParserActionParameters::parseVector(Json::Value temp_info){
std::vector<float> vector;
if(!temp_info.isNull() && temp_info.isArray()){
Json::Value value;
for(int i= 0; i< temp_info.size(); ++i){
value = temp_info.get(i,"UTF-8");
if(!value.isNull() && value.isNumeric()){
vector.push_back(value.asFloat());
}
}
}
return vector;
}
示例7: deserialize
bool deserialize(const Json::Value& node, float& f)
{
if (node.empty())
{
std::cout << "Node is empty." << std::endl;
return false;
}
if (!node.isNumeric())
{
std::cout << "Node data type is not numeric." << std::endl;
return false;
}
f = node.asFloat();
return true;
}
示例8: AddShape
void AddShape(const Json::Value& shape) {
Json::Value name = shape["name"];
Json::Value type = shape["type"];
std::string shapeType = type.asString();
btCollisionShape* bulletShape = NULL;
if (shapeType.compare("cube") == 0) {
Json::Value wx = shape["wx"];
Json::Value wy = shape["wy"];
Json::Value wz = shape["wz"];
btVector3 halfExtents = btVector3(wx.asFloat(), wy.asFloat(), wz.asFloat());
halfExtents *= btScalar(0.5);
bulletShape = new btBoxShape(halfExtents);
} else if (shapeType.compare("convex") == 0) {
Json::Value points = shape["points"];
int numPoints = points.size();
if (numPoints > 0) {
btVector3* convexHull = new btVector3[numPoints];
for (int i = 0; i < numPoints; i++) {
convexHull[i][0] = points[i][0].asFloat();
convexHull[i][1] = points[i][1].asFloat();
convexHull[i][2] = points[i][2].asFloat();
}
bulletShape = new btConvexHullShape(&convexHull[0][0], numPoints);
}
} else if (shapeType.compare("sphere") == 0) {
Json::Value radius = shape["radius"];
bulletShape = new btSphereShape(radius.asFloat());
} else if (shapeType.compare("cylinder") == 0) {
Json::Value radius = shape["radius"];
Json::Value height = shape["height"];
btVector3 halfExtents = btVector3(radius.asFloat(), height.asFloat()*0.5f, 0.0f);
bulletShape = new btCylinderShape(halfExtents);
} else {
NaClAMPrintf("Could not load shape type %s\n", shapeType.c_str());
return;
}
if (bulletShape == NULL) {
NaClAMPrintf("Could not build shape %s\n", name.asString().c_str());
return;
}
shapes[name.asString()] = bulletShape;
NaClAMPrintf("Added shape %s of %s\n", name.asString().c_str(), type.asString().c_str());
}
示例9: if
Ogre::Vector3 JsonUtils::asVector3(Json::Value const &value, const Ogre::Vector3 &defaultValue)
{
if(value.isString())
{
auto const &s = value.asString();
if(Ogre::StringConverter::isNumber(s))
{
float f = Ogre::StringConverter::parseReal(s);
return Ogre::Vector3(f, f, f);
}
else
{
return Ogre::StringConverter::parseVector3(s);
}
}
else if(value.isNumeric())
{
float f = value.asFloat();
return Ogre::Vector3(f, f, f);
}
return defaultValue;
}
示例10:
float jsonNodeAs<float>(const Json::Value& node) {
if (node.isNull()) {
return 0;
}
return node.asFloat();
}
示例11: parseFloat
float ParserActionParameters::parseFloat(Json::Value temp_info){
if(!temp_info.isNull() && temp_info.isNumeric()){
return temp_info.asFloat();
}
return 0;
}
示例12: 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.memory[0],
&response.memory[(long) response.size - 1], root);
// Usage
Json::Value total = root["userStorage"]["total"];
Json::Value used = root["userStorage"]["recorded"];
storageTotal = (long long int) (total.asFloat() * FILMON_ONE_HOUR_RECORDING_SIZE); // bytes
storageUsed = (long long int) (used.asFloat() * FILMON_ONE_HOUR_RECORDING_SIZE); // bytes
std::cerr << "FilmonAPI: recordings total is " << storageTotal
<< std::endl;
std::cerr << "FilmonAPI: recordings used is " << storageUsed
<< std::endl;
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);
std::cerr << "FilmonAPI: found completed recording "
<< recording.strTitle << std::endl;
} 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) {
std::cerr << "FilmonAPI: found active timer "
<< timer.strTitle << std::endl;
timer.state = FILMON_TIMER_STATE_RECORDING;
} else if (t < timer.startTime) {
std::cerr << "FilmonAPI: found scheduled timer "
<< timer.strTitle << std::endl;
timer.state = FILMON_TIMER_STATE_SCHEDULED;
} else if (t > timer.endTime) {
std::cerr << "FilmonAPI: found completed timer "
<< timer.strTitle << std::endl;
timer.state = FILMON_TIMER_STATE_COMPLETED;
}
timers.push_back(timer);
}
}
clearResponse();
}
return res;
}
示例13: throw
void cmnDataJSON<float>::DeSerializeText(DataType & data, const Json::Value & jsonValue) throw (std::runtime_error) {
data = jsonValue.asFloat();
}
示例14: runtime_error
Texture *ResourceManager::loadTexture(const Json::Value& json,
const std::unordered_map<std::string, ResPtr<Resource> >& externalResources)
{
std::string textureType = getMember(json, "type").asString();
Texture::Type type;
if (textureType == "1d")
{
type = Texture::Texture1D;
} else if (textureType == "2d")
{
type = Texture::Texture2D;
} else if (textureType == "3d")
{
type = Texture::Texture3D;
} else if (textureType == "cubemap")
{
type = Texture::TextureCubeMap;
} else
{
throw std::runtime_error("Unknown texture type.");
}
Texture *texture;
bool hasMipmaps = false;
bool linearMipmapping = false;
if (type == Texture::TextureCubeMap)
{
texture = mRenderer->createCubemap(getMember(json, "positive x").asCString(), getMember(json, "negative x").asCString(),
getMember(json, "positive y").asCString(), getMember(json, "negative y").asCString(),
getMember(json, "positive z").asCString(), getMember(json, "negative z").asCString());
} else
{
texture = mRenderer->createTexture(getMember(json, "filename").asCString());
}
if (json.isMember("generate mipmaps"))
{
if (json["generate mipmaps"].asBool())
{
texture->generateMipmaps();
hasMipmaps = true;
}
}
if (json.isMember("linear mipmapping"))
{
if (json["generate mipmaps"].asBool())
{
linearMipmapping = true;
}
}
if (json.isMember("anisotropy"))
{
Json::Value anisotropy = json["anisotropy"];
if (anisotropy.isString())
{
if (anisotropy.asString() == "max")
{
texture->setAnisotropy(mRenderer->getMaxAnisotropy());
} else
{
throw std::runtime_error("Unknown anisotropy.");
}
} else
{
texture->setAnisotropy(std::min(mRenderer->getMaxAnisotropy(), anisotropy.asFloat()));
}
}
if (json.isMember("min filter"))
{
std::string minFilter = json["min filter"].asString();
if (minFilter == "linear")
{
if (hasMipmaps)
{
if (linearMipmapping)
{
texture->setMinFilter(Texture::LinearWithLinearMipmapMinFilter);
} else
{
texture->setMinFilter(Texture::LinearWithNearestMipmapMinFilter);
}
} else
{
texture->setMinFilter(Texture::LinearMinFilter);
}
} else if (minFilter == "nearest")
{
if (hasMipmaps)
{
if (linearMipmapping)
{
texture->setMinFilter(Texture::NearestWithLinearMipmapMinFilter);
//.........这里部分代码省略.........
示例15: fromJSON
template<> ZEROBUF_INL float fromJSON( const Json::Value& json )
{ return json.asFloat(); }