本文整理汇总了C++中jsonbox::Value::isObject方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::isObject方法的具体用法?C++ Value::isObject怎么用?C++ Value::isObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonbox::Value
的用法示例。
在下文中一共展示了Value::isObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadNode
ZD_STATUS Language::LoadNode(JsonBox::Value &node, const std::string &prefix)
{
if (node.isObject())
{
JsonBox::Object obj = node.getObject();
for (auto &i : obj)
{
std::stringstream new_prefix;
if (prefix.length() > 0)
{
new_prefix << prefix << m_delimiter;
}
new_prefix << i.first;
LoadNode(i.second, new_prefix.str());
}
}
else if (node.isString())
{
m_words[prefix] = node.getString();
}
else if (node.isInteger())
{
m_words[prefix] = Helpers::String::To(node.getInt());
}
return ZD_NOERROR;
}
示例2: MCObjectIdToDickKey
/**
* 从数据包加载任务
*/
bool
MCTaskAccessor::loadTasks(const char *aFilePath)
{
bool result = false;
do {
JsonBox::Value in;
JsonBox::Object o;
JsonBox::Object tasksDict;
JsonBox::Object::iterator oIter;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
CCString* pstrFileContent = CCString::createWithContentsOfFile(aFilePath);
if (pstrFileContent) {
in.loadFromString(pstrFileContent->getCString());
}
#else
in.loadFromFile(CCFileUtils::sharedFileUtils()->fullPathForFilename(aFilePath).c_str());
#endif
CC_BREAK_IF(! in.isObject());
tasksDict = in.getObject();
for (oIter = tasksDict.begin(); oIter != tasksDict.end(); ++oIter) {
std::string t_id = oIter->first;
const char *s_t_id = t_id.c_str();
mc_object_id_t o_id = {
s_t_id[0],
s_t_id[1],
s_t_id[2],
s_t_id[3]
};
MCTask *task = new MCTask;
task->autorelease();
if (task) {
task->setID(o_id);
o = oIter->second.getObject();
task->loadTaskContent(o);
/* 默认为未完成状态,然后会在加载存档数据的时候更新为正确状态 */
task->setTaskStatus(MCTaskUncompleted);
task->proto_ = NULL;
tasks_->setObject(task, MCObjectIdToDickKey(o_id));
}
}
result = true;
} while (0);
return result;
}
示例3: parse
bool Camera::parse(const JsonBox::Value &cameraVal, Camera &camera)
{
JsonBox::Object cameraObj;
if (!cameraVal.isObject())
{
cerr << "Error: Camera must be an Object." << endl;
return false;
}
cameraObj = cameraVal.getObject();
if
(
!cameraObj["origin"].isArray() || !cameraObj["direction"].isArray() || !cameraObj["top"].isArray()
||
!cameraObj["origin"].getArray()[0].isNumber() || !cameraObj["origin"].getArray()[1].isNumber() || !cameraObj["origin"].getArray()[2].isNumber()
||
!cameraObj["direction"].getArray()[0].isNumber() || !cameraObj["direction"].getArray()[1].isNumber() || !cameraObj["direction"].getArray()[2].isNumber()
||
!cameraObj["top"].getArray()[0].isNumber() || !cameraObj["top"].getArray()[1].isNumber() || !cameraObj["top"].getArray()[2].isNumber()
)
{
cerr << "Error: invalid Camera vectors (origin, direction and top)." << endl;
return false;
}
if (!cameraObj["fovy"].isNumber() || !cameraObj["width"].isInteger() || !cameraObj["height"].isInteger() || !cameraObj["filename"].isString())
{
cerr << "Error: invalid Camera parameters (fovy, width, height and filename)." << endl;
return false;
}
Point origin = Point(cameraObj["origin"].getArray()[0].getNumber(), cameraObj["origin"].getArray()[1].getNumber(), cameraObj["origin"].getArray()[2].getNumber());
Vector direction = Point(cameraObj["direction"].getArray()[0].getNumber(), cameraObj["direction"].getArray()[1].getNumber(), cameraObj["direction"].getArray()[2].getNumber());
Vector top = Point(cameraObj["top"].getArray()[0].getNumber(), cameraObj["top"].getArray()[1].getNumber(), cameraObj["top"].getArray()[2].getNumber());
camera = Camera(origin, direction, top, cameraObj["fovy"].getNumber() * (2 * M_PI) / 360.0, cameraObj["width"].getInt(), cameraObj["height"].getInt(), cameraObj["filename"].getString());
return true;
}
示例4: parse
bool Material::parse(const JsonBox::Value &materialVal, Material &material)
{
JsonBox::Object materialObj;
double infinity = numeric_limits<double>::infinity();
if (!materialVal.isObject())
{
cerr << "Error: material is not an Object." << endl;
return false;
}
materialObj = materialVal.getObject();
if (!materialObj["name"].isString())
{
cerr << "Error: material's name is not a string." << endl;
return false;
}
material.name = materialObj["name"].getString();
if
(
!materialObj["color"].isArray()
||
(!materialObj["color"].getArray()[0].isInteger() && !materialObj["color"].getArray()[0].isDouble())
||
(!materialObj["color"].getArray()[1].isInteger() && !materialObj["color"].getArray()[1].isDouble())
||
(!materialObj["color"].getArray()[2].isInteger() && !materialObj["color"].getArray()[2].isDouble())
)
{
/* color is not an array or one of the components is neither an integer nor a double */
cerr << "Error: material's color is not an (valid) array." << endl;
return false;
}
material.color.r = (materialObj["color"].getArray()[0].isInteger() ? materialObj["color"].getArray()[0].getInt() : materialObj["color"].getArray()[0].getDouble());
material.color.g = (materialObj["color"].getArray()[1].isInteger() ? materialObj["color"].getArray()[1].getInt() : materialObj["color"].getArray()[1].getDouble());
material.color.b = (materialObj["color"].getArray()[2].isInteger() ? materialObj["color"].getArray()[2].getInt() : materialObj["color"].getArray()[2].getDouble());
if
(
(!materialObj["roughness"].isInteger() && !materialObj["roughness"].isDouble())
||
(!materialObj["absorvance"].isInteger() && !materialObj["absorvance"].isDouble())
||
(!materialObj["emittance"].isInteger() && !materialObj["emittance"].isDouble())
||
(!materialObj["n"].isInteger() && !materialObj["n"].isDouble() && (!materialObj["n"].isString() || materialObj["n"].getString().compare("infinity") != 0))
)
{
cerr << "Error: at least one of the material's parameters (roughness, absorvance, emittance or n) is invalid." << endl;
return false;
}
material.roughness = (materialObj["roughness"].isInteger() ? materialObj["roughness"].getInt() : materialObj["roughness"].getDouble());
material.absorvance = (materialObj["absorvance"].isInteger() ? materialObj["absorvance"].getInt() : materialObj["absorvance"].getDouble());
material.emittance = (materialObj["emittance"].isInteger() ? materialObj["emittance"].getInt() : materialObj["emittance"].getDouble());
material.n = (materialObj["n"].isInteger() ? materialObj["n"].getInt() : (materialObj["n"].isDouble() ? materialObj["n"].getDouble() : infinity));
return true;
}