本文整理汇总了C++中JsonOut::write方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonOut::write方法的具体用法?C++ JsonOut::write怎么用?C++ JsonOut::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonOut
的用法示例。
在下文中一共展示了JsonOut::write方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: format
static void format( JsonIn &jsin, JsonOut &jsout, int depth )
{
depth++;
if( jsin.test_array() ) {
format_collection( jsin, jsout, depth, write_array );
} else if( jsin.test_object() ) {
format_collection( jsin, jsout, depth, write_object );
} else if( jsin.test_string() ) {
std::string str = jsin.get_string();
jsout.write( str );
} else if( jsin.test_number() ) {
// Have to introspect into the string to distinguish integers from floats.
// Otherwise they won't serialize correctly.
const int start_pos = jsin.tell();
double num = jsin.get_float();
const int end_pos = jsin.tell();
std::string str_form = jsin.substr( start_pos, end_pos - start_pos );
if( str_form.find( '.' ) == std::string::npos ) {
jsout.write( static_cast<long>( num ) );
} else {
// This is QUITE insane, but as far as I can tell there is NO way to configure
// an ostream to output a float/double meeting two constraints:
// Always emit a decimal point (and single trailing 0 after a bare decimal point).
// Don't emit trailing zeroes otherwise.
std::string double_str = std::to_string( num );
double_str.erase( double_str.find_last_not_of( '0' ) + 1, std::string::npos );
if( double_str.back() == '.' ) {
double_str += "0";
}
jsout.write_separator();
*jsout.get_stream() << double_str;
jsout.set_need_separator();
}
jsin.seek( end_pos );
} else if( jsin.test_bool() ) {
bool tf = jsin.get_bool();
jsout.write( tf );
} else if( jsin.test_null() ) {
jsout.write_null();
} else {
std::cerr << "Encountered unrecognized json element \"";
const int start_pos = jsin.tell();
jsin.skip_value();
const int end_pos = jsin.tell();
for( int i = start_pos; i < end_pos; ++i ) {
jsin.seek( i );
std::cerr << jsin.peek();
}
std::cerr << "\"" << std::endl;
}
}
示例2: serialize
void mission::serialize(JsonOut &json) const
{
json.start_object();
json.member("type_id", type == NULL ? -1 : (int)type->id);
json.member("description", description);
json.member("failed", failed);
json.member("value", value);
json.member("reward", reward);
json.member("uid", uid);
json.member("target");
json.start_array();
json.write(target.x);
json.write(target.y);
json.end_array();
json.member("count", count);
json.member("deadline", deadline);
json.member("npc_id", npc_id);
json.member("good_fac_id", good_fac_id);
json.member("bad_fac_id", bad_fac_id);
json.member("step", step);
json.member("follow_up", (int)follow_up);
json.end_object();
}
示例3: json_save_invcache
/*
* Save invlet cache
*/
void inventory::json_save_invcache(JsonOut &json) const
{
json.start_array();
for( std::map<std::string, std::vector<char> >::const_iterator invlet_id = invlet_cache.begin(); invlet_id != invlet_cache.end(); ++invlet_id ) {
json.start_object();
json.member( invlet_id->first );
json.start_array();
for( std::vector<char>::const_iterator sym = invlet_id->second.begin();
sym != invlet_id->second.end(); ++sym ) {
json.write( int(*sym) );
}
json.end_array();
json.end_object();
}
json.end_array();
}
示例4: serialize
void it_artifact_tool::serialize(JsonOut &json) const
{
json.start_object();
json.member("type", "artifact_tool");
// generic data
json.member("id", id);
json.member("name", name);
json.member("description", description);
json.member("sym", sym);
json.member("color", color_to_int(color));
json.member("price", price);
json.member("materials");
json.start_array();
for (auto mat : materials) {
json.write(mat);
}
json.end_array();
json.member("volume", volume);
json.member("weight", weight);
json.member("melee_dam", melee_dam);
json.member("melee_cut", melee_cut);
json.member("m_to_hit", m_to_hit);
json.member("item_flags", item_tags);
json.member("techniques", techniques);
// tool data
json.member("ammo", ammo);
json.member("max_charges", max_charges);
json.member("def_charges", def_charges);
json.member("rand_charges", rand_charges);
json.member("charges_per_use", charges_per_use);
json.member("turns_per_charge", turns_per_charge);
json.member("revert_to", revert_to);
// artifact data
json.member("charge_type", charge_type);
json.member("effects_wielded", effects_wielded);
json.member("effects_activated", effects_activated);
json.member("effects_carried", effects_carried);
json.end_object();
}
示例5: serialize
void nc_color::serialize( JsonOut &jsout ) const
{
jsout.write( attribute_value );
}
示例6: serialize
void zone_manager::serialize( JsonOut &json ) const
{
json.write( zones );
}
示例7: npcs
/*
* Prepare a json object for player, including player specific data, and data common to
players and npcs ( which json_save_actor_data() handles ).
*/
void player::serialize(JsonOut &json, bool save_contents) const
{
json.start_object();
json_save_common_variables( json );
// player-specific specifics
if ( prof != NULL ) {
json.member( "profession", prof->ident() );
}
// someday, npcs may drive
json.member( "driving_recoil", int(driving_recoil) );
json.member( "in_vehicle", in_vehicle );
json.member( "controlling_vehicle", controlling_vehicle );
// shopping carts, furniture etc
json.member( "grab_point", grab_point );
json.member( "grab_type", obj_type_name[ (int)grab_type ] );
// misc player specific stuff
json.member( "blocks_left", num_blocks );
json.member( "focus_pool", focus_pool );
json.member( "style_selected", style_selected );
// possibly related to illness[] ?
json.member( "health", health );
// crafting etc
json.member( "activity", activity );
json.member( "backlog", activity );
// mutations; just like traits but can be removed.
json.member( "mutations", my_mutations );
// "The cold wakes you up."
json.member( "temp_cur", std::vector<int>( temp_cur, temp_cur + num_bp ) );
json.member( "temp_conv", std::vector<int>( temp_conv, temp_conv + num_bp ) );
json.member( "frostbite_timer", std::vector<int>( frostbite_timer, frostbite_timer + num_bp ) );
// npc: unimplemented, potentially useful
json.member( "learned_recipes" );
json.start_array();
for (std::map<std::string, recipe*>::const_iterator iter = learned_recipes.begin(); iter != learned_recipes.end(); ++iter) {
json.write( iter->first );
}
json.end_array();
// :(
json.member( "morale", morale );
// mission stuff
json.member("active_mission", active_mission );
json.member( "active_missions", active_missions );
json.member( "completed_missions", completed_missions );
json.member( "failed_missions", failed_missions );
json.member( "player_stats", get_stats() );
if ( save_contents ) {
json.member( "worn", worn ); // also saves contents
json.member("inv");
inv.json_save_items(json);
json.member("invcache");
inv.json_save_invcache(json);
if (!weapon.is_null()) {
json.member( "weapon", weapon ); // also saves contents
}
//FIXME: seperate function, better still another file
/* for( size_t i = 0; i < memorial_log.size(); ++i ) {
ptmpvect.push_back(pv(memorial_log[i]));
}
json.member("memorial",ptmpvect);
*/
}
json.end_object();
}