当前位置: 首页>>代码示例>>C++>>正文


C++ JsonIn类代码示例

本文整理汇总了C++中JsonIn的典型用法代码示例。如果您正苦于以下问题:C++ JsonIn类的具体用法?C++ JsonIn怎么用?C++ JsonIn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了JsonIn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: format_collection

static void format_collection( JsonIn &jsin, JsonOut &jsout, int depth,
                               std::function<void(JsonIn &, JsonOut &, int, bool )>write_func )
{
    if( depth > 1 ) {
        // We're backtracking by storing jsin and jsout state before formatting
        // and restoring it afterwards if necessary.
        int in_start_pos = jsin.tell();
        bool ate_seperator = jsin.get_ate_separator();
        int out_start_pos = jsout.tell();
        bool need_separator = jsout.get_need_separator();
        write_func( jsin, jsout, depth, false );
        if( jsout.tell() - out_start_pos <= 120 ) {
            // Line is short enough, so we're done.
            return;
        } else {
            // Reset jsin and jsout to their initial state,
            // and we'll serialize while forcing wrapping.
            jsin.seek( in_start_pos );
            jsin.set_ate_separator( ate_seperator );
            jsout.seek( out_start_pos );
            if( need_separator ) {
                jsout.set_need_separator();
            }
        }
    }
    write_func( jsin, jsout, depth, true );
}
开发者ID:,项目名称:,代码行数:27,代码来源:

示例2: deserialize

void zone_manager::deserialize( JsonIn &jsin )
{
    zones.clear();

    jsin.start_array();
    while( !jsin.end_array() ) {
        JsonObject jo_zone = jsin.get_object();

        const std::string name = jo_zone.get_string( "name" );
        const std::string type = jo_zone.get_string( "type" );

        const bool invert = jo_zone.get_bool( "invert" );
        const bool enabled = jo_zone.get_bool( "enabled" );

        // Z coords need to have a default value - old saves won't have those
        const int start_x = jo_zone.get_int( "start_x" );
        const int start_y = jo_zone.get_int( "start_y" );
        const int start_z = jo_zone.get_int( "start_z", 0 );
        const int end_x = jo_zone.get_int( "end_x" );
        const int end_y = jo_zone.get_int( "end_y" );
        const int end_z = jo_zone.get_int( "end_z", 0 );

        if( has_type( type ) ) {
            add( name, type, invert, enabled,
                 tripoint( start_x, start_y, start_z ),
                 tripoint( end_x, end_y, end_z ) );
        } else {
            debugmsg( "Invalid zone type: %s", type.c_str() );
        }
    }
}
开发者ID:Mshock777,项目名称:Cataclysm-DDA,代码行数:31,代码来源:clzones.cpp

示例3: get_next

     mabuff_id get_next( JsonIn &jin ) const {
         if( jin.test_string() ) {
             return mabuff_id( jin.get_string() );
         }
         JsonObject jsobj = jin.get_object();
         return ma_buffs.load( jsobj ).id;
 }
开发者ID:Griffinhart,项目名称:Cataclysm-DDA,代码行数:7,代码来源:martialarts.cpp

示例4: load

void NameGenerator::load( JsonIn &jsin )
{
    jsin.start_array();
    while( !jsin.end_array() ) {
        JsonObject json_name = jsin.get_object();
        load_name( json_name );
    }
}
开发者ID:AlecWhite,项目名称:Cataclysm-DDA,代码行数:8,代码来源:name.cpp

示例5: write_array

static void write_array( JsonIn &jsin, JsonOut &jsout, int depth, bool force_wrap )
{
    jsout.start_array( force_wrap );
    jsin.start_array();
    while( !jsin.end_array() ) {
        format( jsin, jsout, depth );
    }
    jsout.end_array();
}
开发者ID:,项目名称:,代码行数:9,代码来源:

示例6: write_object

static void write_object( JsonIn &jsin, JsonOut &jsout, int depth, bool force_wrap )
{
    jsout.start_object( force_wrap );
    jsin.start_object();
    while( !jsin.end_object() ) {
        std::string name = jsin.get_member_name();
        jsout.member( name );
        format( jsin, jsout, depth );
    }
    jsout.end_object();
}
开发者ID:,项目名称:,代码行数:11,代码来源:

示例7: load_season_array

void load_season_array( JsonIn &js, C &container, F load_func )
{
    if( js.test_array() ) {
        js.start_array();
        for( auto &season_entry : container ) {
            season_entry = load_func( js );
            js.end_array(); // consume separator
        }
    } else {
        container.fill( load_func( js ) );
    }
}
开发者ID:1942rob,项目名称:Cataclysm-DDA,代码行数:12,代码来源:mapdata.cpp

示例8: get_next

 profession::itypedec get_next( JsonIn &jin ) const {
     // either a plain item type id string, or an array with item type id
     // and as second entry the item description.
     if( jin.test_string() ) {
         return profession::itypedec( jin.get_string(), "" );
     }
     JsonArray jarr = jin.get_array();
     const auto id = jarr.get_string( 0 );
     const auto s = jarr.get_string( 1 );
     const auto snippet = _( s.c_str() );
     return profession::itypedec( id, snippet );
 }
开发者ID:AreasAside,项目名称:Cataclysm-DDA,代码行数:12,代码来源:profession.cpp

示例9: string_to_symbol

long string_to_symbol( JsonIn &js )
{
    const std::string s = js.get_string();
    if( s == "LINE_XOXO" ) {
        return LINE_XOXO;
    } else if( s == "LINE_OXOX" ) {
        return LINE_OXOX;
    } else if( s.length() != 1 ) {
        js.error( "Symbol string must be exactly 1 character long." );
    }
    return s[0];
}
开发者ID:1942rob,项目名称:Cataclysm-DDA,代码行数:12,代码来源:mapdata.cpp

示例10: write_object

static void write_object( JsonIn &jsin, JsonOut &jsout, int depth, bool force_wrap )
{
    jsout.start_object( force_wrap );
    jsin.start_object();
    while( !jsin.end_object() ) {
        std::string name = jsin.get_member_name();
        jsout.member( name );
        bool override_wrap = false;
        if( name == "rows" || name == "blueprint" ) {
            // Introspect into the row, if it has more than one element, force it to wrap.
            int in_start_pos = jsin.tell();
            bool ate_seperator = jsin.get_ate_separator();
            {
                JsonArray arr = jsin.get_array();
                if( arr.size() > 1 ) {
                    override_wrap = true;
                }
            }
            jsin.seek( in_start_pos );
            jsin.set_ate_separator( ate_seperator );
        }
        format( jsin, jsout, depth, override_wrap );
    }
    jsout.end_object();
}
开发者ID:CleverRaven,项目名称:Cataclysm-DDA,代码行数:25,代码来源:format.cpp

示例11: deserialize

void auto_pickup::deserialize(JsonIn &jsin)
{
    vRules[(bChar) ? CHARACTER : GLOBAL].clear();

    jsin.start_array();
    while (!jsin.end_array()) {
        JsonObject jo = jsin.get_object();

        const std::string sRule = jo.get_string("rule");
        const bool bActive = jo.get_bool("active");
        const bool bExclude = jo.get_bool("exclude");

        vRules[(bChar) ? CHARACTER : GLOBAL].push_back(cRules(sRule, bActive, bExclude));
    }
}
开发者ID:DearVarun,项目名称:Cataclysm-DDA,代码行数:15,代码来源:auto_pickup.cpp

示例12: deserialize

void zone_data::deserialize( JsonIn &jsin )
{
    JsonObject data = jsin.get_object();
    data.read( "name", name );
    data.read( "type", type );
    data.read( "invert", invert );
    data.read( "enabled", enabled );
    //Legacy support
    if( data.has_member( "is_vehicle" ) ) {
        data.read( "is_vehicle", is_vehicle );
    } else {
        is_vehicle = false;
    }
    //Legacy support
    if( data.has_member( "start_x" ) ) {
        tripoint s;
        tripoint e;
        data.read( "start_x", s.x );
        data.read( "start_y", s.y );
        data.read( "start_z", s.z );
        data.read( "end_x", e.x );
        data.read( "end_y", e.y );
        data.read( "end_z", e.z );
        start = s;
        end = e;
    } else {
        data.read( "start", start );
        data.read( "end", end );
    }
    auto new_options = zone_options::create( type );
    new_options->deserialize( data );
    options = new_options;
}
开发者ID:KrazyTheFox,项目名称:Cataclysm-DDA,代码行数:33,代码来源:clzones.cpp

示例13: deserialize

void item_location::deserialize( JsonIn &js )
{
    auto obj = js.get_object();
    auto type = obj.get_string( "type" );

    int idx = -1;
    tripoint pos = tripoint_min;

    obj.read( "idx", idx );
    obj.read( "pos", pos );

    if( type == "character" ) {
        ptr.reset( new impl::item_on_person( g->u, idx ) );

    } else if( type == "map" ) {
        ptr.reset( new impl::item_on_map( pos, idx ) );

    } else if( type == "vehicle" ) {
        auto *veh = g->m.veh_at( pos );
        int part = obj.get_int( "part" );
        if( veh && part >= 0 && part < int( veh->parts.size() ) ) {
            ptr.reset( new impl::item_on_vehicle( vehicle_cursor( *veh, part ), idx ) );
        }
    }
}
开发者ID:Nullsrc,项目名称:Cataclysm-DDA,代码行数:25,代码来源:item_location.cpp

示例14: deserialize

////////////////// mission.h
////
void mission::deserialize(JsonIn &jsin)
{
    JsonObject jo = jsin.get_object();

    if (jo.has_member("type_id")) {
        type = &(g->mission_types[jo.get_int("type_id")]);
    }
    jo.read("description", description);
    jo.read("failed", failed);
    jo.read("value", value);
    jo.read("reward", reward);
    jo.read("uid", uid );
    JsonArray ja = jo.get_array("target");
    if (ja.size() == 2) {
        target.x = ja.get_int(0);
        target.y = ja.get_int(1);
    }
    follow_up = mission_id(jo.get_int("follow_up", follow_up));
    item_id = itype_id(jo.get_string("item_id", item_id));
    jo.read("deadline", deadline );
    jo.read("step", step );
    jo.read("count", count );
    jo.read("npc_id", npc_id );
    jo.read("good_fac_id", good_fac_id );
    jo.read("bad_fac_id", bad_fac_id );
}
开发者ID:Agnososyk,项目名称:Cataclysm-DDA,代码行数:28,代码来源:savegame_json.cpp

示例15: load

// The loaded name is one of usage with optional gender.
// The combinations used in names files are as follows.
//
// Backer | (Female|Male|Unisex)
// Given  | (Female|Male)        // unisex names are duplicated in each group
// Family | Unisex
// City
// World
static void load( JsonIn &jsin )
{
    jsin.start_array();

    while( !jsin.end_array() ) {
        JsonObject jo = jsin.get_object();

        // get flags of name.
        const nameFlags type =
            usage_flag( jo.get_string( "usage" ) )
            | gender_flag( jo.get_string( "gender", "" ) );

        // find group type and add name to group
        names[type].push_back( jo.get_string( "name" ) );
    }
}
开发者ID:Barhandar,项目名称:Cataclysm-DDA,代码行数:24,代码来源:name.cpp


注:本文中的JsonIn类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。