本文整理汇总了C++中json::value::iterator::key方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::key方法的具体用法?C++ iterator::key怎么用?C++ iterator::key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::value::iterator
的用法示例。
在下文中一共展示了iterator::key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: importData
bool SpriteData::importData(Json::Value root)
{
mSpriteHash.clear();
if (root.empty())
{
return false;
}
else
{
mResourceDirPath = QString::fromStdString(root["resourceDirPath"].asString());
Json::Value sprites = root["sprites"];
for(Json::Value::iterator iter = sprites.begin() ; sprites.end() != iter ; iter++)
{
QString keyName = QString::fromStdString(iter.key().asString());
Json::Value data = *iter;
SpriteDef sDef;
sDef.mGridX = data["gridX"].asInt();
sDef.mGridY = data["gridY"].asInt();
sDef.mCenterX = data["centerX"].asInt();
sDef.mCenterY = data["centerY"].asInt();
sDef.mImageID = keyName;
mSpriteHash.insert(keyName, sDef);
}
return true;
}
}
示例2: load_config
int load_config(const char *cfg_root)
{
Json::Value root;
if (this->load_json_cfg(cfg_root, BASIC_ATTR_CFG_PATH, root) != 0)
return -1;
this->basic_attr_cfg_info_ = new basic_attr_cfg_info[CHAR_CAREER_CNT + 1]();
for (Json::Value::iterator iter = root.begin();
iter != root.end();
++iter)
{
int career = ::atoi(iter.key().asCString());
if (!util::is_career_ok(career)) return -1;
basic_attr_cfg_info &baci = this->basic_attr_cfg_info_[career];
baci.attr_val_[ATTR_T_HP] = ((*iter)["sheng_ming"]).asInt();
baci.attr_val_[ATTR_T_MP] = ((*iter)["fa_li"]).asInt();
baci.attr_val_[ATTR_T_GONG_JI] = ((*iter)["gong_ji"]).asInt();
baci.attr_val_[ATTR_T_FANG_YU] = ((*iter)["fang_yu"]).asInt();
baci.attr_val_[ATTR_T_MING_ZHONG] = ((*iter)["ming_zhong"]).asInt();
baci.attr_val_[ATTR_T_SHAN_BI] = ((*iter)["shan_bi"]).asInt();
baci.attr_val_[ATTR_T_BAO_JI] = ((*iter)["bao_ji"]).asInt();
baci.attr_val_[ATTR_T_KANG_BAO] = ((*iter)["kang_bao"]).asInt();
baci.attr_val_[ATTR_T_SHANG_MIAN] = ((*iter)["shang_mian"]).asInt();
}
return 0;
}
示例3: load_config
int load_config(const char *cfg_root)
{
Json::Value root;
if (this->load_json_cfg(cfg_root, CHENG_JIU_CFG_PATH, root) != 0)
return -1;
for (Json::Value::iterator iter = root.begin();
iter != root.end();
++iter)
{
int cj_id = ::atoi(iter.key().asCString());
cheng_jiu_obj *cjo = new cheng_jiu_obj();
this->cheng_jiu_obj_map_.insert(std::make_pair(cj_id, cjo));
cjo->show_lvl_ = (*iter)["show_lvl"].asInt();
cjo->value_ = (*iter)["param"].asInt();
cjo->title_ = (*iter)["title"].asInt();
cjo->next_cj_id_ = (*iter)["next_index"].asInt();
cjo->lucky_rate_ = (*iter)["lucky_rate"].asInt();
if ((cj_id / 1000) != (cjo->next_cj_id_ / 1000))
return -1;
char bf[128] = {0};
::strncpy(bf, (*iter)["award"].asCString(), sizeof(bf));
char *tok_p = NULL;
char *token = NULL;
for (token = ::strtok_r(bf, ";", &tok_p);
token != NULL;
token = ::strtok_r(NULL, ";", &tok_p))
{
item_amount_bind_t v;
int bind = 0;
if (::sscanf(token, "%d,%d,%d",
&v.cid_, &v.amount_, &bind) != 3)
return -1;
v.bind_ = bind;
cjo->award_list_.push_back(v);
}
::memset(bf, 0, sizeof(bf));
::strncpy(bf, (*iter)["lucky_award"].asCString(), sizeof(bf));
tok_p = NULL;
token = NULL;
for (token = ::strtok_r(bf, ";", &tok_p);
token != NULL;
token = ::strtok_r(NULL, ";", &tok_p))
{
item_amount_bind_t v;
int bind = 0;
if (::sscanf(token, "%d,%d,%d",
&v.cid_, &v.amount_, &bind) != 3)
return -1;
v.bind_ = bind;
cjo->lucky_award_.push_back(v);
}
}
return 0;
}
示例4: init
void AI_Machine::init(void) {
const Json::Value &all_ai_json = CONFIG_INSTANCE->config_json()["ai"]["ai_behavior"];
if (all_ai_json == Json::Value::null) {
LOG_ABORT("configure file error.");
}
for (Json::Value::iterator iter = all_ai_json.begin(); iter != all_ai_json.end(); ++iter) {
int ai_id = atoi(iter.key().asCString());
AI_Data *ai_data = new AI_Data;
Composite_Node *ai_behavior = new CompositeNode_Selector();
ai_data->ai_behavior = ai_behavior;
behavior_init(*iter, ai_behavior);
ai_data_map_.insert(std::make_pair(ai_id, ai_data));
}
{
Composite_Node* pselect_idle = new CompositeNode_Selector();
pselect_idle->add_child(CREATE_TERMINATE_NODE(Be_Idle));
blockhead_ai_ = pselect_idle;
}
{
Composite_Node* psequence_ai_behavior = new CompositeNode_Sequence();
psequence_ai_behavior->add_child(CREATE_TERMINATE_NODE(Co_Idle_Status));
psequence_ai_behavior->add_child(CREATE_TERMINATE_NODE(Be_Idle));
//psequence_ai_behavior->add_child(CREATE_TERMINATE_NODE(Co_Die_Status));
//psequence_ai_behavior->add_child(CREATE_TERMINATE_NODE(Be_NPC_Recover));
normal_ai_ = psequence_ai_behavior;
}
}
示例5: 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;
}
示例6: registerFloorTile
void InfrastructureFactory::registerFloorTile( const std::string& path ) {
std::string fullPath = path + "/" + TILE_SYSTEM_ROOT;
std::ifstream definitionFile;
definitionFile.exceptions( std::ios::failbit | std::ios::badbit );
definitionFile.open( fullPath );
Json::Reader reader;
Json::Value definitionJSON;
if( reader.parse( definitionFile, definitionJSON ) ) {
for( Json::Value::iterator jsonIterator = definitionJSON.begin(); jsonIterator != definitionJSON.end(); ++jsonIterator ) {
std::string key = jsonIterator.key().asString();
Json::Value tileDefinition = *jsonIterator;
if( tileDefinition.isMember( "sound" ) && tileDefinition.isMember( "image" ) ) {
tileRegistry[ key ] = std::make_shared< Tile >(
key,
path + "/" + getVariableOrValue( "sound", tileDefinition[ "sound" ].asString() ),
path + "/" + getVariableOrValue( "image", tileDefinition[ "image" ].asString() ),
tileDefinition[ "price" ].asDouble()
);
Log::getInstance().debug( "InfrastructureFactory::registerFloorTile" , "Registered " + key + " at " + fullPath );
} else {
Log::getInstance().error( "InfrastructureFactory::registerFloorTile", "Unable to create floor tile at path " + fullPath + ": missing fields." );
}
}
} else {
Log::getInstance().error( "InfrastructureFactory::registerFloorTile", "Unable to parse JSON file " + fullPath );
}
}
示例7: ReadSpriteFile
void SagoSpriteHolder::ReadSpriteFile(const std::string& filename) {
string fullfile = "sprites/"+filename;
string content = sago::GetFileContent(fullfile.c_str());
Json::Value root; // will contains the root value after parsing
Json::Reader reader;
bool parsingSuccessful = reader.parse( content, root );
if ( !parsingSuccessful ) {
cerr << "Failed to parse: " << fullfile << "\n"
<< reader.getFormattedErrorMessages() << "\n";
return;
}
for (Json::Value::iterator it = root.begin(); it != root.end() ; ++it) {
string spriteName = it.key().asString();
Json::Value value = (*it);
string textureName = value.get("texture","fallback").asString();
int topx = value.get("topx",0).asInt();
int topy = value.get("topy",0).asInt();
int height = value.get("height",0).asInt();
int width = value.get("width",0).asInt();
int number_of_frames = value.get("number_of_frames",1).asInt();
int frame_time = value.get("frame_time",1).asInt();
int originx = value.get("originx",0).asInt();
int originy = value.get("originy",0).asInt();
if (number_of_frames < 1) {
number_of_frames = 1;
}
if (frame_time < 1) {
frame_time = 1;
}
std::shared_ptr<sago::SagoSprite> ptr(new SagoSprite(*(data->tex),textureName, {topx,topy,width,height},number_of_frames,frame_time));
ptr->SetOrigin({originx,originy, 0, 0});
this->data->sprites[std::string(spriteName)] = ptr;
}
}
示例8: Parse
Bool HawkJson::Parse(const Char* pData, Int32 iSize)
{
Json::Reader jReader;
Json::Value sRoot;
if (jReader.parse(pData, sRoot,false))
{
for(Json::Value::iterator it = sRoot.begin(); it != sRoot.end(); it++)
{
const Json::Value& sJsonKey = it.key();
if (sJsonKey.isNull())
return false;
AString sKey = sJsonKey.asString();
const Json::Value& sJsonVal = sRoot[sKey.c_str()];
if (sJsonVal.isNull())
return false;
JsonVal* pVal = new JsonVal;
if (ParseJsonVal(&sJsonVal, pVal))
{
m_sRoot[sKey] = pVal;
}
else
{
HAWK_DELETE(pVal);
return false;
}
}
return true;
}
return false;
}
示例9: registerWallpaper
void InfrastructureFactory::registerWallpaper( const std::string& path ) {
std::string fullPath = path + "/" + WALL_SYSTEM_ROOT;
std::ifstream definitionFile;
definitionFile.exceptions( std::ios::failbit | std::ios::badbit );
definitionFile.open( fullPath );
Json::Reader reader;
Json::Value definitionJSON;
if( reader.parse( definitionFile, definitionJSON ) ) {
for( Json::Value::iterator jsonIterator = definitionJSON.begin(); jsonIterator != definitionJSON.end(); ++jsonIterator ) {
std::string key = jsonIterator.key().asString();
if( key != "_grey" ) {
Json::Value wallpaperDefinition = *jsonIterator;
if( wallpaperDefinition.isMember( "image" ) ) {
wallpaperRegistry[ key ] = std::make_shared< Wallpaper >(
key,
path + "/" + wallpaperDefinition[ "image" ].asString(),
wallpaperDefinition[ "price" ].asDouble()
);
Log::getInstance().debug( "InfrastructureFactory::registerWallpaper" , "Registered " + key + " at " + fullPath );
} else {
Log::getInstance().error( "InfrastructureFactory::registerWallpaper", "Unable to create wallpaper at path " + fullPath + ": missing fields." );
}
} else {
Log::getInstance().warn( "InfrastructureFactory::registerWallpaper", "Cannot register wallpaper: \"_grey\" is a reserved id." );
}
}
} else {
Log::getInstance().error( "InfrastructureFactory::wallpaper", "Unable to parse JSON file " + fullPath );
}
}
示例10: load_config
int load_config(const char *cfg_root)
{
Json::Value root;
if (this->load_json_cfg(cfg_root, JING_JI_AWARD_CFG_PATH, root) != 0)
return -1;
for (Json::Value::iterator iter = root.begin();
iter != root.end();
++iter)
{
int id = ::atoi(iter.key().asCString());
if (id >= MAX_AWARD_KIND_COUNT) return -1;
jj_award_obj *jao = new jj_award_obj();
this->jj_award_obj_map_.insert(id, jao);
jao->rank_min_ = (*iter)["rank_min"].asInt();
jao->rank_max_ = (*iter)["rank_max"].asInt();
jao->bind_diamond_ = (*iter)["bind_zuanshi"].asInt();
jao->coin_ = (*iter)["coin"].asInt();
jao->ji_fen_ = (*iter)["ji_fen"].asInt();
}
return 0;
}
示例11: GetLights
bool CPhilipsHue::GetLights(const Json::Value &root)
{
if (root["lights"].empty())
return false;
for (Json::Value::iterator iLight = root["lights"].begin(); iLight != root["lights"].end(); ++iLight)
{
Json::Value light = *iLight;
if (light.isObject())
{
std::string szLID = iLight.key().asString();
int lID = atoi(szLID.c_str());
_tHueLight tlight;
tlight.level = 0;
tlight.sat = 0; // Philips 0- 254, should be corrected to 0 - 255 ?
tlight.hue = 0; // Philips 0 - 65535, should be converted to 0 - 255 ?
tlight.on = light["state"]["on"].asBool();
bool bDoSend = true;
_eHueLightType LType = HLTYPE_NORMAL;
if (!light["state"]["bri"].empty())
{
//Lamp with brightness control
LType = HLTYPE_DIM;
int tbri = light["state"]["bri"].asInt();
if ((tbri != 0) && (tbri != 255))
tbri += 1; //hue reports 255 as 254
tlight.level = int((100.0f / 255.0f)*float(tbri));
}
if ((!light["state"]["sat"].empty()) && (!light["state"]["hue"].empty()))
{
//Lamp with hue/sat control
LType = HLTYPE_RGBW;
tlight.sat = light["state"]["sat"].asInt();
tlight.hue = light["state"]["hue"].asInt();
}
if (m_lights.find(lID) != m_lights.end())
{
_tHueLight alight = m_lights[lID];
if (
(alight.on == tlight.on) &&
(alight.level == tlight.level) &&
(alight.sat == tlight.sat) &&
(alight.hue == tlight.hue)
)
{
bDoSend = false;
}
}
m_lights[lID] = tlight;
if (bDoSend)
{
//_log.Log(LOG_STATUS, "HueBridge state change: tbri = %d, level = %d", tbri, tlight.level);
InsertUpdateSwitch(lID, LType, tlight.on, tlight.level, tlight.sat, tlight.hue, light["name"].asString(), "");
}
}
}
return true;
}
示例12: ParseValueStringOrMap
Res ParseValueStringOrMap(const Context* ctx,
Config* cfg,
const Json::Value& val,
const string& equals_string,
const string& separator_string,
string* out) {
if (val.isString()) {
*out = val.asString();
} else if (val.isArray()) {
// Evaluate as a lisp expression.
Res err = EvalToString(ctx, cfg, val, out);
if (!err.Ok()) {
err.AppendDetail("in ParseValueStringOrMap(): array eval of '" +
val.toStyledString() + "'");
return err;
}
} else if (val.isObject()) {
// Evaluate as a named-value map.
bool done_first = false;
out->clear();
for (Json::Value::iterator it = val.begin(); it != val.end(); ++it) {
if (!it.key().isString()) {
return Res(ERR_PARSE,
"ParseValueStringOrMap(): key is not a string: '" +
it.key().toStyledString());
}
const Json::Value& map_val = *it;
string result;
Res err = EvalToString(ctx, cfg, map_val, &result);
if (!err.Ok()) {
err.AppendDetail("in ParseValueStringOrMap(): key '" +
it.key().toStyledString() + "'");
return err;
}
if (done_first) {
*out += separator_string;
}
*out += it.key().asString();
*out += equals_string;
*out += result;
done_first = true;
}
}
return Res(OK);
}
示例13: load_json
int load_json(Json::Value &root)
{
for (Json::Value::iterator iter = root.begin();
iter != root.end();
++iter)
{
int id = ::atoi(iter.key().asCString());
_mst_spawn_info *p = new _mst_spawn_info();
p->idx_ = id;
p->mst_cid_ = (*iter)["monster_cid"].asInt();
p->dir_ = (*iter)["toward"].asInt();
this->mst_spawn_info_map_.insert(p->idx_, p);
}
return 0;
}
示例14: settingsFile
/**
* Clumsily define the defaults application-wide in this constructor.
* Is there a way to do this in bulk using C++11 uniform initialisation?
*/
ConfigManager::ConfigManager() {
configRoot[ "fps_overview" ] = 30;
configRoot[ "vsync_limiter_overview" ] = false;
configRoot[ "min_log_level" ] = 0;
configRoot[ "logfile_path" ] = "bluebear.log";
configRoot[ "logger_mode" ] = 0;
configRoot[ "viewport_x" ] = 1024;
configRoot[ "viewport_y" ] = 768;
configRoot[ "current_locale" ] = "en_US";
configRoot[ "key_switch_perspective" ] = sf::Keyboard::P;
configRoot[ "key_move_up" ] = sf::Keyboard::Up;
configRoot[ "key_move_down" ] = sf::Keyboard::Down;
configRoot[ "key_move_left" ] = sf::Keyboard::Left;
configRoot[ "key_move_right" ] = sf::Keyboard::Right;
configRoot[ "key_terminal" ] = sf::Keyboard::Tilde;
configRoot[ "key_pause" ] = sf::Keyboard::Num1;
configRoot[ "key_play" ] = sf::Keyboard::Num2;
configRoot[ "key_play_fast" ] = sf::Keyboard::Num3;
configRoot[ "key_rotate_right" ] = sf::Keyboard::E;
configRoot[ "key_rotate_left" ] = sf::Keyboard::Q;
configRoot[ "key_zoom_in" ] = sf::Keyboard::Add;
configRoot[ "key_zoom_out" ] = sf::Keyboard::Subtract;
configRoot[ "disable_image_cache" ] = false;
configRoot[ "disable_texture_cache" ] = false;
configRoot[ "ui_theme" ] = "system/ui/default.theme";
configRoot[ "max_ingame_terminal_scrollback" ] = 100;
// Load settings.json from file
std::ifstream settingsFile( SETTINGS_PATH );
Json::Value settingsJSON;
Json::Reader reader;
if( reader.parse( settingsFile, settingsJSON ) ) {
// Override defaults
// iterators - barf
for( Json::Value::iterator jsonIterator = settingsJSON.begin(); jsonIterator != settingsJSON.end(); ++jsonIterator ) {
// BARF
Json::Value key = jsonIterator.key();
Json::Value value = *jsonIterator;
// Store every value as a string because strong typing is a PITA
configRoot[ key.asString() ] = value;
}
}
}
示例15: load_config
int load_config(const char *cfg_root)
{
Json::Value root;
if (this->load_json_cfg(cfg_root, MAIL_CFG_PATH, root) != 0)
return -1;
for(Json::Value::iterator iter = root.begin();
iter != root.end();
++iter)
{
int id = ::atoi(iter.key().asCString());
mail_obj *mo = new mail_obj();
this->mail_obj_map_.insert(id, mo);
if (this->load_json(*iter, mo) != 0)
return -1;
}
return 0;
}