本文整理汇总了C++中json::Value::end方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::end方法的具体用法?C++ Value::end怎么用?C++ Value::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::Value
的用法示例。
在下文中一共展示了Value::end方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseMaterials
void JsonParser::parseMaterials(Json::Value &root){
LOG_DEBUG("Parsing Materials.");
bool foundMaterials = false;
for( Json::ValueIterator itr = root.begin() ; itr != root.end() ; itr++ ) {
std::string key = itr.key().asString();
if (key == "materials") {
foundMaterials = true;
// loop through materials
Json::Value objRoot = *itr;
for( Json::ValueIterator objItr = objRoot.begin() ; objItr != objRoot.end() ; objItr++ ) {
std::string matName = objItr.key().asString();
LOG_DEBUG("Found material: " << matName);
// we first check if we're dealing with a light or mesh
std::string matType = getStringAttr("type", *objItr);
Material * mat = getMaterial(matType, matName, *objItr, renderEnv);
// add to shading engine
renderEnv->shadingEngine->registerMaterial(matName, mat);
}
LOG_DEBUG("Done parsing materials.\n");
break;
}
}
if (!foundMaterials) {
LOG_WARNING("No materials found in file " << filename << ".");
}
}
示例2: get_val
Terr::Terr(const Json::Value& loc,
const Json::Value locs,
map<string, shared_ptr<Terr>>& terrs)
: short_name{get_val("short_name", loc).asString()}
, display_name{get_val("display_name", loc).asString()}
, has_center{get_val("has_center", loc).asBool()}
, adjacent{}
, piece{}
{
terrs[short_name] = shared_ptr<Terr>(this); // sketchy...
assert(terrs.find(short_name) != terrs.end());
for(const auto& adj_val : get_val("adjacent", loc)) {
string adj_name = adj_val.asString();
if(terrs.find(adj_name) == terrs.end()) {
const auto it = find_if(locs.begin(), locs.end(),
[&adj_name](const Json::Value& t) {
return get_val("short_name", t) == adj_name;
});
assert(it != locs.end());
set_terrs(*it, locs, terrs);
assert(terrs.find(adj_name) != terrs.end()); // TODO NDEBUG
adjacent.push_back(terrs[adj_name]);
}
}
}
示例3: getTransformAttr
// TODO: Clean this one up.
inline Transform getTransformAttr(const std::string &name, Json::Value &root){
Json::Value errorVal = Json::Value(-99999); //TODO: Very temp
Json::Value value = root.get( name.c_str(), errorVal );
if (value == errorVal) {
LOG_ERROR("Can't json attribute: " << name);
}
Transform trans;
if (value.size() > 0) {
for( Json::ValueIterator trItr = value.begin() ; trItr != value.end() ; trItr++ ) {
Json::Value t = *trItr;
if (t.begin().key().asString() == "translate") {
double num[3];
int i = 0;
Json::Value xyz = *t.begin();
for( Json::ValueIterator xyzItr = xyz.begin() ; xyzItr != xyz.end() ; xyzItr++ ) {
Json::Value v = *xyzItr;
num[i] = v.asDouble();
i++;
}
LOG_DEBUG("Translating: " << num[0] << " " << num[1] << " " << num[2]);
trans.translate(Vector(num[0], num[1], num[2]));
}
else if (t.begin().key().asString() == "scale") {
double num[3];
int i = 0;
Json::Value xyz = *t.begin();
for( Json::ValueIterator xyzItr = xyz.begin() ; xyzItr != xyz.end() ; xyzItr++ ) {
Json::Value v = *xyzItr;
num[i] = v.asDouble();
i++;
}
LOG_DEBUG("Scaling: " << num[0] << " " << num[1] << " " << num[2]);
trans.scale(num[0], num[1], num[2]);
}
else if (t.begin().key().asString() == "rotateX") {
Json::Value v = *t.begin();
double num = v.asDouble();
LOG_DEBUG("Rotate X: " << num);
trans.rotateX(num);
}
else if (t.begin().key().asString() == "rotateY") {
Json::Value v = *t.begin();
double num = v.asDouble();
LOG_DEBUG("Rotate Y: " << num);
trans.rotateY(num);
}
else if (t.begin().key().asString() == "rotateZ") {
Json::Value v = *t.begin();
double num = v.asDouble();
LOG_DEBUG("Rotate Z: " << num);
trans.rotateZ(num);
}
}
}
return trans;
}
示例4: readFromFile
bool CannyReader::readFromFile()
{
Timer aTimer;
std::ifstream cannyFile(srcFile);
cannyFile.precision(20);
if (cannyFile.is_open()) {
std::stringstream buffer;
buffer << cannyFile.rdbuf();
std::string contents(buffer.str());
cout << "Time to Read: " << aTimer.elapsed() << endl;
aTimer.restart();
Json::Value root;
Json::Reader reader;
bool parsingSuccessful = reader.parse( contents, root );
cout << "Time to parse: " << aTimer.elapsed() << endl;
aTimer.restart();
if (parsingSuccessful)
{
for( Json::ValueIterator outer = root.begin() ; outer != root.end() ; outer++ ) {
int camNum = outer.key().asInt();
Json::Value oneCam = root[camNum];
for( Json::ValueIterator itr = oneCam.begin() ; itr != oneCam.end() ; itr++ ) {
vector<Line_Segment *>* lineSegments = new vector<Line_Segment *>();
int key = atoi(itr.key().asCString());
Json::Value jsonSegments = oneCam[itr.key().asCString()];
for( Json::ValueIterator itr2 = jsonSegments.begin() ; itr2 != jsonSegments.end() ; itr2++ ) {
Json::Value jsonSeg = jsonSegments[itr2.key().asInt()];
Line_Segment* seg = (Line_Segment *) malloc(sizeof(Line_Segment));
seg->row1 = jsonSeg["r1"].asInt();
seg->col1 = jsonSeg["c1"].asInt();
seg->row2 = jsonSeg["r2"].asInt();
seg->col2 = jsonSeg["c2"].asInt();
lineSegments->push_back(seg);
}
precomputedCannySegments[camNum][key] = lineSegments;
}
}
cannyFile.close();
cout << "Time to reconstruct: " << aTimer.elapsed() << endl;
return true;
}
else {
return false;
}
}
return false;
}
示例5: push_json_value_helper
// Recursive function to convert JSON --> Lua table
static bool push_json_value_helper(lua_State *L, const Json::Value &value,
int nullindex)
{
switch(value.type()) {
case Json::nullValue:
default:
lua_pushvalue(L, nullindex);
break;
case Json::intValue:
lua_pushinteger(L, value.asInt());
break;
case Json::uintValue:
lua_pushinteger(L, value.asUInt());
break;
case Json::realValue:
lua_pushnumber(L, value.asDouble());
break;
case Json::stringValue:
{
const char *str = value.asCString();
lua_pushstring(L, str ? str : "");
}
break;
case Json::booleanValue:
lua_pushboolean(L, value.asInt());
break;
case Json::arrayValue:
lua_newtable(L);
for (Json::Value::const_iterator it = value.begin();
it != value.end(); ++it) {
push_json_value_helper(L, *it, nullindex);
lua_rawseti(L, -2, it.index() + 1);
}
break;
case Json::objectValue:
lua_newtable(L);
for (Json::Value::const_iterator it = value.begin();
it != value.end(); ++it) {
#ifndef JSONCPP_STRING
const char *str = it.memberName();
lua_pushstring(L, str ? str : "");
#else
std::string str = it.name();
lua_pushstring(L, str.c_str());
#endif
push_json_value_helper(L, *it, nullindex);
lua_rawset(L, -3);
}
break;
}
return true;
}
示例6:
std::list<std::string> CJSONHandler::ParseResources(std::string strJSON)
{
Json::Value root; // will contains the root value after parsing.
Json::Reader reader;
std::string resName;
std::list<std::string> listResources;
bool parsingSuccessful = reader.parse(strJSON, root );
if ( !parsingSuccessful )
{
CLog::Log(logERROR, "JSONHandler: Parse resource: no valid JSON data");
return listResources;
}
for(Json::ValueIterator itr = root.begin() ; itr != root.end() ; itr++)
{
Json::Value valu = *itr;
resName = valu.get("slug", "unknown").asString();
if (resName.size() == 0 || resName == "unknown")
CLog::Log(logERROR, "JSONHandler: Parse resource: no valid JSON data while iterating");
listResources.push_back(resName);
CLog::Log(logINFO, "JSONHandler: found resource on Transifex server: %s", resName.c_str());
};
CLog::Log(logINFO, "JSONHandler: Found %i resources at Transifex server", listResources.size());
return listResources;
};
示例7: parseCamera
void JsonParser::parseCamera(Json::Value &root){
LOG_DEBUG("Parsing Camera.");
bool foundCamera = false;
// Options
for( Json::ValueIterator itr = root.begin() ; itr != root.end() ; itr++ ) {
std::string key = itr.key().asString();
if (key == "renderCam") {
foundCamera = true;
// read all standard data
double r_fieldOfView = getDoubleAttr("fov", *itr);
Transform r_transform = getTransformAttr("transforms", *itr);
// TODO: check for any ones we've skipped and warn the user
// TODO: handle errors gracefully
// apply read data
(*renderEnv->globals)[FieldOfView] = r_fieldOfView;
cameraTransform = new Transform(r_transform);
LOG_DEBUG("Done parsing Camera.\n");
break;
}
}
if (!foundCamera) {
LOG_WARNING("No render camera found in file " << filename << ".");
}
}
示例8: buildWaypointList
static void buildWaypointList(WaypointClient* userdata)
{
WaypointClient* anInstance = (WaypointClient*) userdata;
Fl_Input_Choice * fromWPChoice = anInstance->frWps;
Fl_Input_Choice * toWPChoice = anInstance->toWps;
fromWPChoice->clear();
toWPChoice->clear();
Json::Value waypointsArray = anInstance->getWaypoints().get("waypoints",0);
if (waypointsArray.size() == 0)
{
fromWPChoice->add("EMPTY");
toWPChoice->add("EMPTY");
}
else
{
for (Json::ValueIterator itr = waypointsArray.begin(); itr != waypointsArray.end(); itr++)
{
Json::Value waypoint = *itr;
string name = waypoint["name"].asString();
fromWPChoice->add(name.c_str());
toWPChoice->add(name.c_str());
}
}
fromWPChoice->value(0);
toWPChoice->value(0);
SelectedFromWP(NULL, anInstance);
}
示例9: LoadFromJson
bool cInventory::LoadFromJson(Json::Value & a_Value)
{
int SlotIdx = 0;
for (Json::Value::iterator itr = a_Value.begin(); itr != a_Value.end(); ++itr, SlotIdx++)
{
cItem Item;
Item.FromJson(*itr);
// The JSON originally included the 4 crafting slots and the result slot, so we need to skip the first 5 items:
if (SlotIdx < 5)
{
continue;
}
// If we loaded all the slots, stop now, even if the JSON has more:
if (SlotIdx - 5 >= invNumSlots)
{
break;
}
int GridSlotNum = 0;
cItemGrid * Grid = GetGridForSlotNum(SlotIdx - 5, GridSlotNum);
ASSERT(Grid != nullptr);
Grid->SetSlot(GridSlotNum, Item);
} // for itr - a_Value[]
return true;
}
示例10: loadManifest
Manifest DappLoader::loadManifest(std::string const& _manifest)
{
/// https://github.com/ethereum/go-ethereum/wiki/URL-Scheme
Manifest manifest;
Json::Reader jsonReader;
Json::Value root;
jsonReader.parse(_manifest, root, false);
Json::Value entries = root["entries"];
for (Json::ValueIterator it = entries.begin(); it != entries.end(); ++it)
{
Json::Value const& entryValue = *it;
std::string path = entryValue["path"].asString();
if (path.size() == 0 || path[0] != '/')
path = "/" + path;
std::string contentType = entryValue["contentType"].asString();
std::string strHash = entryValue["hash"].asString();
if (strHash.length() == 64)
strHash = "0x" + strHash;
h256 hash = jsToFixed<32>(strHash);
unsigned httpStatus = entryValue["status"].asInt();
manifest.entries.push_back(ManifestEntry{ path, hash, contentType, httpStatus });
}
return manifest;
}
示例11: input
/**
* Read a map of {list_name : class_list} from json
*/
std::unordered_map<std::string, std::vector<std::string> > ConfigFiles::load_class_lists() {
std::unordered_map<std::string, std::vector<std::string> > lists;
std::string class_lists_filename;
this->m_json.get("class_lists", "", class_lists_filename);
if (class_lists_filename.empty()) {
return lists;
}
std::ifstream input(class_lists_filename);
Json::Reader reader;
Json::Value root;
bool parsing_succeeded = reader.parse(input, root);
always_assert_log(parsing_succeeded, "Failed to parse class list json from file: %s\n%s",
class_lists_filename.c_str(),
reader.getFormattedErrorMessages().c_str());
for (Json::ValueIterator it = root.begin(); it != root.end(); ++it) {
std::vector<std::string> class_list;
Json::Value current_list = *it;
for (Json::ValueIterator list_it = current_list.begin(); list_it != current_list.end(); ++list_it) {
lists[it.key().asString()].push_back((*list_it).asString());
}
}
lists["secondary_dex_head.list"] = get_coldstart_classes();
return lists;
}
示例12: if
qpid::types::Variant::List agocontrol::jsonToVariantList(Json::Value value) {
Variant::List list;
try {
for (Json::ValueIterator it = value.begin(); it != value.end(); it++) {
if ((*it).size() > 0) {
// cout << "JSON Type: " << (*it).type() << endl;
if ((*it).type() == 6) {
list.push_back(jsonToVariantList((*it)));
} else if ((*it).type() == 7) {
list.push_back(jsonToVariantMap((*it)));
}
} else {
if ((*it).isString()) list.push_back( (*it).asString());
if ((*it).isBool()) list.push_back( (*it).asBool());
if ((*it).isInt()) list.push_back( (*it).asInt());
if ((*it).isUInt()) list.push_back( (*it).asUInt());
if ((*it).isDouble()) list.push_back( (*it).asDouble());
}
}
} catch (const std::exception& error) {
cout << "ERROR! Exception during JSON->Variant::Map conversion!" << endl;
stringstream errorstring;
errorstring << error.what();
cout << "EXCEPTION: " << errorstring.str() << endl;
}
return list;
}
示例13: getMsgList
int Response::getMsgList(std::string &s, std:: vector <msgRecord> &vmr) const {
Json::Value root;
stringToJson(s, root);
try {
Json::Value json = root["result"][0U]["value"];
for (int i = 0; i != json.size(); i++) {
Json::Value temp = json[i];
int srcID, targetID, postTime, msgType;
std::string msgText;
for (__typeof(temp.begin()) it = temp.begin(); it != temp.end(); it++) {
if (it.key().asString() == "srcID")
srcID = (*it).asInt();
else if (it.key().asString() == "targetID")
targetID = (*it).asInt();
else if (it.key().asString() == "msgText")
msgText = (*it).asString();
else if (it.key().asString() == "postTime")
postTime = (*it).asInt();
else if (it.key().asString() == "msgType")
msgType = (*it).asInt();
}
MsgRecord mr(srcID, targetID, msgText, msgType);
mr.postTime = postTime;
vmr.push_back(mr);
}
} catch (...) {
return ERROR;
}
return 0;
}
示例14: load_config
int load_config(const char *cfg_root)
{
Json::Value root;
if (this->load_json_cfg(cfg_root, SKILL_CFG_PATH, root) != 0)
return -1;
for (int i = CAREER_LI_LIANG; i <= CAREER_ZHI_LI; ++i)
this->career_skill_map_.insert(i, new ilist<int>());
for(Json::Value::iterator iter = root.begin();
iter != root.end();
++iter)
{
int cid = ::atoi(iter.key().asCString());
if (!clsid::is_skill(cid))
{
e_log->error("%d is not skill in %s!", cid, SKILL_CFG_PATH);
return -1;
}
skill_cfg_obj *sco = new skill_cfg_obj();
this->skill_cfg_obj_map_.insert(std::make_pair(cid, sco));
if (this->load_json(*iter, sco, cid) != 0)
return -1;
if (clsid::is_char_skill(cid)
&& util::is_career_ok(sco->career_))
this->career_skill_map_.find(sco->career_)->push_back(cid);
}
return 0;
}
示例15: runtime_error
Model *ResourceManager::loadModel(const Json::Value& value,
const std::unordered_map<std::string, ResPtr<Resource> >& externalResources)
{
Json::Value lods = getMember(value, "lods");
if (not lods.isArray())
{
throw std::runtime_error("Unable to get the LODs.");
}
Model *model = NEW(Model);
if (value.isMember("stippledLODs"))
{
model->mStippledLODs = value["stippledLODs"].asBool();
}
for (Json::Value::iterator it = lods.begin(); it != lods.end(); ++it)
{
Json::Value lod = *it;
std::string mesh = getMember(lod, "mesh").asString();
std::string material = getMember(lod, "material").asString();
float distance = getMember(lod, "distance").asFloat();
model->mLODs.push_back(LOD(externalResources.at(mesh).cast<Mesh>(),
externalResources.at(material).cast<Material>(),
distance));
}
model->sortLODs();
return model;
}