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


C++ JsonObject::has_string方法代码示例

本文整理汇总了C++中JsonObject::has_string方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonObject::has_string方法的具体用法?C++ JsonObject::has_string怎么用?C++ JsonObject::has_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonObject的用法示例。


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

示例1: deserialize

void it_artifact_armor::deserialize(JsonObject &jo)
{
    id = jo.get_string("id");
    name = jo.get_string("name");
    description = jo.get_string("description");
    sym = jo.get_int("sym");
    color = int_to_color(jo.get_int("color"));
    price = jo.get_int("price");
    // LEGACY: Since it seems artifacts get serialized out to disk, and they're
    // dynamic, we need to allow for them to be read from disk for, oh, I guess
    // quite some time. Loading and saving once will write things out as a JSON
    // array.
    if (jo.has_string("m1")) {
        materials.push_back(jo.get_string("m1"));
    }
    if (jo.has_string("m2")) {
        materials.push_back(jo.get_string("m2"));
    }
    // Assumption, perhaps dangerous, that we won't wind up with m1 and m2 and
    // a materials array in our serialized objects at the same time.
    if (jo.has_array("materials")) {
        JsonArray jarr = jo.get_array("materials");
        for (int i = 0; i < jarr.size(); ++i) {
            materials.push_back(jarr.get_string(i));
        }
    }
    if (materials.size() == 0) {
        // I don't think we need this, but a lot of code seems to want at least
        // one material and I'm not sure I found every single corner case.
        materials.push_back("null");
    }
    volume = jo.get_int("volume");
    weight = jo.get_int("weight");
    melee_dam = jo.get_int("melee_dam");
    melee_cut = jo.get_int("melee_cut");
    m_to_hit = jo.get_int("m_to_hit");
    item_tags = jo.get_tags("item_flags");

    jo.read( "covers", covers);
    encumber = jo.get_int("encumber");
    coverage = jo.get_int("coverage");
    thickness = jo.get_int("material_thickness");
    env_resist = jo.get_int("env_resist");
    warmth = jo.get_int("warmth");
    storage = jo.get_int("storage");
    power_armor = jo.get_bool("power_armor");

    JsonArray ja = jo.get_array("effects_worn");
    while (ja.has_more()) {
        effects_worn.push_back((art_effect_passive)ja.next_int());
    }
}
开发者ID:Suseika,项目名称:Cataclysm-DDA,代码行数:52,代码来源:artifact.cpp

示例2: load_wheel

void vpart_info::load_wheel( cata::optional<vpslot_wheel> &whptr, JsonObject &jo )
{
    vpslot_wheel wh_info;
    if( whptr ) {
        wh_info = *whptr;
    }
    assign( jo, "rolling_resistance", wh_info.rolling_resistance );
    assign( jo, "contact_area", wh_info.contact_area );
    wh_info.terrain_mod = standard_terrain_mod;
    wh_info.or_rating = 0.5f;
    if( jo.has_string( "wheel_type" ) ) {
        const std::string wheel_type = jo.get_string( "wheel_type" );
        if( wheel_type == "rigid" ) {
            wh_info.terrain_mod = rigid_terrain_mod;
            wh_info.or_rating = 0.1;
        } else if( wheel_type == "off-road" ) {
            wh_info.terrain_mod = off_road_terrain_mod;
            wh_info.or_rating = 0.7;
        } else if( wheel_type == "racing" ) {
            wh_info.terrain_mod = racing_terrain_mod;
            wh_info.or_rating = 0.3;
        } else if( wheel_type == "treads" ) {
            wh_info.terrain_mod = treads_terrain_mod;
            wh_info.or_rating = 0.9;
        }
    }

    whptr = wh_info;
    assert( whptr );
}
开发者ID:cellxiecao,项目名称:Cataclysm-DDA,代码行数:30,代码来源:veh_type.cpp

示例3: load_vehicle_spawn

void VehicleFactory::load_vehicle_spawn(JsonObject &jo)
{
    const std::string spawn_id = jo.get_string("id");
    VehicleSpawn spawn;

    JsonArray types = jo.get_array("spawn_types");

    while (types.has_more()) {
        JsonObject type = types.next_object();

        if(type.has_object("vehicle_json")) {
            JsonObject vjo = type.get_object("vehicle_json");
            spawn.add(type.get_float("weight"), std::make_shared<VehicleFunction_json>(vjo));
        }
        else if(type.has_string("vehicle_function")) {
            if(builtin_functions.count(type.get_string("vehicle_function")) == 0) {
                type.throw_error("load_vehicle_spawn: unable to find builtin function", "vehicle_function");
            }

            spawn.add(type.get_float("weight"), std::make_shared<VehicleFunction_builtin>(
                builtin_functions[type.get_string("vehicle_function")]));
        }
        else {
            type.throw_error("load_vehicle_spawn: missing required vehicle_json (object) or vehicle_function (string).");
        }
    }

    spawns[spawn_id] = spawn;
}
开发者ID:Lap,项目名称:Cataclysm-DDA,代码行数:29,代码来源:vehicle_factory.cpp

示例4: load_fault

void fault::load_fault( JsonObject &jo )
{
    fault f;

    f.id_ = fault_id( jo.get_string( "id" ) );
    f.name_ = _( jo.get_string( "name" ) );
    f.description_ = _( jo.get_string( "description" ) );

    f.time_ = jo.get_int( "time" );

    auto sk = jo.get_array( "skills" );
    while( sk.has_more() ) {
        auto cur = sk.next_array();
        f.skills_.emplace( skill_id( cur.get_string( 0 ) ), cur.size() >= 2 ? cur.get_int( 1 ) : 1 );
    }

    if( jo.has_string( "requirements" ) ) {
        f.requirements_ = requirement_id( jo.get_string( "requirements" ) );

    } else {
        auto req = jo.get_object( "requirements" );
        const requirement_id req_id( std::string( "inline_fault_" ) + f.id_.str() );
        requirement_data::load_requirement( req, req_id );
        f.requirements_ = req_id;
    }

    if( faults_all.find( f.id_ ) != faults_all.end() ) {
        jo.throw_error( "parsed fault overwrites existing definition", "id" );
    } else {
        faults_all[ f.id_ ] = f;
    }
}
开发者ID:CleverRaven,项目名称:Cataclysm-DDA,代码行数:32,代码来源:fault.cpp

示例5: load

bool map_bash_info::load(JsonObject &jsobj, std::string member, bool isfurniture) {
    if( jsobj.has_object(member) ) {
        JsonObject j = jsobj.get_object(member);

        if ( jsonint(j, "num_tests", num_tests ) == false ) {
            if ( jsonint(j, "str_min", str_min ) && jsonint(j, "str_max", str_max ) ) {
                num_tests = 1;
            }
        } else if ( num_tests > 0 ) {
            str_min = j.get_int("str_min");
            str_max = j.get_int("str_max");
        }

        jsonint(j, "str_min_blocked", str_min_blocked );
        jsonint(j, "str_max_blocked", str_max_blocked );
        jsonint(j, "str_min_roll", str_min_roll );
        jsonint(j, "chance", chance );
        jsonstring(j, "sound", sound );
        jsonstring(j, "sound_fail", sound_fail );

        if ( jsonstring(j, "ter_set", ter_set ) == false && isfurniture == false ) {
            ter_set = "t_rubble";
            debugmsg("terrain[\"%s\"].bash.ter_set is not set!",jsobj.get_string("id").c_str() );
        }

        if ( j.has_array("items") ) {
            JsonArray ja = j.get_array("items");
            if (ja.size() > 0) {
                int c=0;
                while ( ja.has_more() ) {
                    if ( ja.has_object(c) ) {
                        JsonObject jio = ja.next_object();
                        if ( jio.has_string("item") && jio.has_int("amount") ) {
                            if ( jio.has_int("minamount") ) {
                                map_bash_item_drop drop( jio.get_string("item"), jio.get_int("amount"), jio.get_int("minamount") );
                                jsonint(jio, "chance", drop.chance);
                                items.push_back(drop);
                            } else {
                                map_bash_item_drop drop( jio.get_string("item"), jio.get_int("amount") );
                                jsonint(jio, "chance", drop.chance);
                                items.push_back(drop);
                            }
                        } else {
                            debugmsg("terrain[\"%s\"].bash.items[%d]: invalid entry",jsobj.get_string("id").c_str(),c);
                        }
                    } else {
                        debugmsg("terrain[\"%s\"].bash.items[%d]: invalid entry",jsobj.get_string("id").c_str(),c);
                    }
                    c++;
                }
            }
        }

//debugmsg("%d/%d %s %s/%s %d",str_min,str_max, ter_set.c_str(), sound.c_str(), sound_fail.c_str(), items.size() );
        return true;
    } else {
        return false;
    }
}
开发者ID:JedrekD,项目名称:Cataclysm-DDA,代码行数:59,代码来源:mapdata.cpp

示例6: load

void profession::load( JsonObject &jo, const std::string & )
{
    //If the "name" is an object then we have to deal with gender-specific titles,
    if( jo.has_object( "name" ) ) {
        JsonObject name_obj = jo.get_object( "name" );
        _name_male = pgettext( "profession_male", name_obj.get_string( "male" ).c_str() );
        _name_female = pgettext( "profession_female", name_obj.get_string( "female" ).c_str() );
    } else if( jo.has_string( "name" ) ) {
        // Same profession names for male and female in English.
        // Still need to different names in other languages.
        const std::string name = jo.get_string( "name" );
        _name_female = pgettext( "profession_female", name.c_str() );
        _name_male = pgettext( "profession_male", name.c_str() );
    } else if( !was_loaded ) {
        jo.throw_error( "missing mandatory member \"name\"" );
    }

    if( !was_loaded || jo.has_member( "description" ) ) {
        const std::string desc = jo.get_string( "description" );
        // These also may differ depending on the language settings!
        _description_male = pgettext( "prof_desc_male", desc.c_str() );
        _description_female = pgettext( "prof_desc_female", desc.c_str() );
    }

    mandatory( jo, was_loaded, "points", _point_cost );

    if( !was_loaded || jo.has_member( "items" ) ) {
        JsonObject items_obj = jo.get_object( "items" );

        if( items_obj.has_array( "both" ) ) {
            optional( items_obj, was_loaded, "both", legacy_starting_items, item_reader {} );
        }
        if( items_obj.has_object( "both" ) ) {
            _starting_items = item_group::load_item_group( *items_obj.get_raw( "both" ), "collection" );
        }
        if( items_obj.has_array( "male" ) ) {
            optional( items_obj, was_loaded, "male", legacy_starting_items_male, item_reader {} );
        }
        if( items_obj.has_object( "male" ) ) {
            _starting_items_male = item_group::load_item_group( *items_obj.get_raw( "male" ), "collection" );
        }
        if( items_obj.has_array( "female" ) ) {
            optional( items_obj, was_loaded, "female",  legacy_starting_items_female, item_reader {} );
        }
        if( items_obj.has_object( "female" ) ) {
            _starting_items_female = item_group::load_item_group( *items_obj.get_raw( "female" ),
                                     "collection" );
        }
    }
    optional( jo, was_loaded, "no_bonus", no_bonus );

    optional( jo, was_loaded, "skills", _starting_skills, skilllevel_reader {} );
    optional( jo, was_loaded, "addictions", _starting_addictions, addiction_reader {} );
    // TODO: use string_id<bionic_type> or so
    optional( jo, was_loaded, "CBMs", _starting_CBMs, auto_flags_reader<bionic_id> {} );
    // TODO: use string_id<mutation_branch> or so
    optional( jo, was_loaded, "traits", _starting_traits, auto_flags_reader<trait_id> {} );
    optional( jo, was_loaded, "flags", flags, auto_flags_reader<> {} );
}
开发者ID:AreasAside,项目名称:Cataclysm-DDA,代码行数:59,代码来源:profession.cpp

示例7: LoadMonsterWhitelist

void MonsterGroupManager::LoadMonsterWhitelist( JsonObject &jo )
{
    if( jo.has_string( "mode" ) && jo.get_string( "mode" ) == "EXCLUSIVE" ) {
        monster_whitelist_is_exclusive = true;
    }
    add_to_set( monster_whitelist, jo, "monsters" );
    add_to_set( monster_categories_whitelist, jo, "categories" );
}
开发者ID:CleverRaven,项目名称:Cataclysm-DDA,代码行数:8,代码来源:mongroup.cpp

示例8: load_object

// copypasta: init.cpp
void load_object(JsonObject &jo)
{
    std::string type = jo.get_string("type");
    if ( ! jo.has_string("type") )
    {
        jo.throw_error( "JSON object has no type" );
    }
}
开发者ID:1942rob,项目名称:Cataclysm-DDA,代码行数:9,代码来源:chkjson.cpp

示例9: load

/**
 *Caches a vehicle definition from a JsonObject to be loaded after itypes is initialized.
 */
void vehicle_prototype::load(JsonObject &jo)
{
    vehicle_prototype &vproto = vtypes[ vproto_id( jo.get_string( "id" ) ) ];
    // If there are already parts defined, this vehicle prototype overrides an existing one.
    // If the json contains a name, it means a completely new prototype (replacing the
    // original one), therefor the old data has to be cleared.
    // If the json does not contain a name (the prototype would have no name), it means appending
    // to the existing prototype (the parts are not cleared).
    if( !vproto.parts.empty() && jo.has_string( "name" ) ) {
        vproto = std::move( vehicle_prototype() );
    }
    if( vproto.parts.empty() ) {
        vproto.name = jo.get_string( "name" );
    }

    vgroups[vgroup_id(jo.get_string("id"))].add_vehicle(vproto_id(jo.get_string("id")), 100);

    JsonArray parts = jo.get_array("parts");
    while (parts.has_more()) {
        JsonObject part = parts.next_object();
        const point pxy( part.get_int("x"), part.get_int("y") );
        const vpart_str_id pid( part.get_string( "part" ) );
        vproto.parts.emplace_back( pxy, pid );
    }

    JsonArray items = jo.get_array("items");
    while(items.has_more()) {
        JsonObject spawn_info = items.next_object();
        vehicle_item_spawn next_spawn;
        next_spawn.pos.x = spawn_info.get_int("x");
        next_spawn.pos.y = spawn_info.get_int("y");
        next_spawn.chance = spawn_info.get_int("chance");
        if(next_spawn.chance <= 0 || next_spawn.chance > 100) {
            debugmsg("Invalid spawn chance in %s (%d, %d): %d%%",
                     vproto.name.c_str(), next_spawn.pos.x, next_spawn.pos.y, next_spawn.chance);
        }
        if(spawn_info.has_array("items")) {
            //Array of items that all spawn together (ie jack+tire)
            JsonArray item_group = spawn_info.get_array("items");
            while(item_group.has_more()) {
                next_spawn.item_ids.push_back(item_group.next_string());
            }
        } else if(spawn_info.has_string("items")) {
            //Treat single item as array
            next_spawn.item_ids.push_back(spawn_info.get_string("items"));
        }
        if(spawn_info.has_array("item_groups")) {
            //Pick from a group of items, just like map::place_items
            JsonArray item_group_names = spawn_info.get_array("item_groups");
            while(item_group_names.has_more()) {
                next_spawn.item_groups.push_back(item_group_names.next_string());
            }
        } else if(spawn_info.has_string("item_groups")) {
            next_spawn.item_groups.push_back(spawn_info.get_string("item_groups"));
        }
        vproto.item_spawns.push_back( std::move( next_spawn ) );
    }
}
开发者ID:DeNarr,项目名称:Cataclysm-DDA,代码行数:61,代码来源:veh_typedef.cpp

示例10: assign_function

void assign_function( JsonObject &jo, const std::string &id, Fun &target, const std::map<std::string, Fun> &cont )
{
    if( jo.has_string( id ) ) {
        const auto iter = cont.find( jo.get_string( id ) );
        if( iter != cont.end() ) {
            target = iter->second;
        } else {
            jo.throw_error( "Invalid mission function", id );
        }
    }
}
开发者ID:Guuo,项目名称:Cataclysm-DDA,代码行数:11,代码来源:missiondef.cpp

示例11: load_object

// copypasta: init.cpp
void load_object(JsonObject &jo)
{
    std::string type = jo.get_string("type");
    if ( ! jo.has_string("type") )
    {
        std::stringstream err;
        err << jo.line_number() << ": ";
        err << "JSON object has no type";
        throw err.str();
    }
}
开发者ID:Agnososyk,项目名称:Cataclysm-DDA,代码行数:12,代码来源:chkjson.cpp

示例12: deserialize

void npc_favor::deserialize(JsonIn &jsin)
{
    JsonObject jo = jsin.get_object();
    type = npc_favor_type(jo.get_int("type"));
    jo.read("value", value);
    jo.read("itype_id", item_id);
    skill = NULL;
    if (jo.has_int("skill_id")) {
        skill = Skill::skill(jo.get_int("skill_id"));
    } else if (jo.has_string("skill_id")) {
        skill = Skill::skill(jo.get_string("skill_id"));
    }
}
开发者ID:Agnososyk,项目名称:Cataclysm-DDA,代码行数:13,代码来源:savegame_json.cpp

示例13: load_damage_instance

damage_instance load_damage_instance( JsonObject &jo )
{
    damage_instance di;
    if( jo.has_array( "values" ) ) {
        JsonArray jarr = jo.get_array( "values" );
        while( jarr.has_more() ) {
            JsonObject curr = jarr.next_object();
            di.damage_units.push_back( load_damage_unit( curr ) );
        }
    } else if( jo.has_string( "damage_type" ) ) {
        di.damage_units.push_back( load_damage_unit( jo ) );
    }

    return di;
}
开发者ID:tycho,项目名称:Cataclysm-DDA,代码行数:15,代码来源:damage.cpp

示例14: facings

VehicleFunction_json::VehicleFunction_json(JsonObject &jo)
    : vehicle(jo.get_string("vehicle")),
    number(jo, "number"),
    fuel(jo.get_int("fuel")),
    status(jo.get_int("status"))
{
    if(jo.has_string("placement")) {
        placement = jo.get_string("placement");
    }
    else {
        //location = std::make_unique<Vehicle_Location>(jmapgen_int(jo, "x"), jmapgen_int(jo, "y"), facings);
        // that would be better, but it won't exist until c++14, so for now we do this:
        VehicleFacings facings(jo, "facing");
        location.reset(new VehicleLocation(jmapgen_int(jo, "x"), jmapgen_int(jo, "y"), facings));
    }
}
开发者ID:Lap,项目名称:Cataclysm-DDA,代码行数:16,代码来源:vehicle_factory.cpp

示例15: load_mutation_attack

static mut_attack load_mutation_attack( JsonObject &jo )
{
    mut_attack ret;
    jo.read( "attack_text_u", ret.attack_text_u );
    jo.read( "attack_text_npc", ret.attack_text_npc );
    jo.read( "required_mutations", ret.required_mutations );
    jo.read( "blocker_mutations", ret.blocker_mutations );
    jo.read( "hardcoded_effect", ret.hardcoded_effect );

    if( jo.has_string( "body_part" ) ) {
        ret.bp = get_body_part_token( jo.get_string( "body_part" ) );
    }

    jo.read( "chance", ret.chance );

    if( jo.has_array( "base_damage" ) ) {
        JsonArray jo_dam = jo.get_array( "base_damage" );
        ret.base_damage = load_damage_instance( jo_dam );
    } else if( jo.has_object( "base_damage" ) ) {
        JsonObject jo_dam = jo.get_object( "base_damage" );
        ret.base_damage = load_damage_instance( jo_dam );
    }

    if( jo.has_array( "strength_damage" ) ) {
        JsonArray jo_dam = jo.get_array( "strength_damage" );
        ret.strength_damage = load_damage_instance( jo_dam );
    } else if( jo.has_object( "strength_damage" ) ) {
        JsonObject jo_dam = jo.get_object( "strength_damage" );
        ret.strength_damage = load_damage_instance( jo_dam );
    }

    if( ret.attack_text_u.empty() || ret.attack_text_npc.empty() ) {
        jo.throw_error( "Attack message unset" );
    }

    if( !ret.hardcoded_effect && ret.base_damage.empty() && ret.strength_damage.empty() ) {
        jo.throw_error( "Damage unset" );
    } else if( ret.hardcoded_effect && ( !ret.base_damage.empty() || !ret.strength_damage.empty() ) ) {
        jo.throw_error( "Damage and hardcoded effect are both set (must be one, not both)" );
    }

    if( ret.chance <= 0 ) {
        jo.throw_error( "Chance of procing must be set and positive" );
    }

    return ret;
}
开发者ID:ymber,项目名称:Cataclysm-DDA,代码行数:47,代码来源:mutation_data.cpp


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