• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ optional函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: optional

HCI::optional HCI::getConnHandle(device &dev) {
  conn_info info;
  
  info.req.conn_num = 1;
  info.req.dev_id = _dev_id;
  

  if(ioctl(_hci_sock, HCIGETCONNLIST, &info) < 0) {
    err::code = err::LIB_SYS;
    
    return optional();
  }
  
  uint16_t handle;
  
  for(hci_conn_info &x: info.info) {
    if(bacmp(&x.bdaddr, &dev.bdaddr) == 0) {
      handle = x.handle;
      
      return optional(handle);
    }
  }
  
  return optional();  
}
开发者ID:loki-47-6F-64,项目名称:kitty,代码行数:25,代码来源:bluetooth.cpp


示例2: fb_add_metadata

static fb_metadata_t *parse_metadata(fb_parser_t *P)
{
    fb_token_t *t, *t0;
    fb_metadata_t *md = 0;

    if (!(t0 = optional(P, '('))) {
        return 0;
    }
    if ((t = optional(P, LEX_TOK_ID)))
    for (;;) {
        fb_add_metadata(P, &md);
        md->ident = t;
        if (optional(P, ':')) {
            parse_value(P, &md->value, allow_string_value, "scalar or string value expected");
        }
        if (P->failed >= FLATCC_MAX_ERRORS) {
            return md;
        }
        if (!optional(P, ',')) {
            break;
        }
        if (!(t = match(P, LEX_TOK_ID, "attribute name expected identifier after ','"))) {
            break;
        }
    }
    advance(P, ')', "metadata expected ')' to match", t0);
    revert_metadata(&md);
    return md;
}
开发者ID:Tao-Ma,项目名称:flatcc,代码行数:29,代码来源:parser.c


示例3: mandatory

void furn_t::load( JsonObject &jo )
{
    mandatory( jo, was_loaded, "name", name, translated_string_reader );
    mandatory( jo, was_loaded, "move_cost_mod", movecost );
    mandatory( jo, was_loaded, "required_str", move_str_req );
    optional( jo, was_loaded, "max_volume", max_volume, legacy_volume_reader, DEFAULT_MAX_VOLUME_IN_SQUARE );
    optional( jo, was_loaded, "crafting_pseudo_item", crafting_pseudo_item, "" );

    load_symbol( jo );
    transparent = false;

    for( auto & flag : jo.get_string_array( "flags" ) ) {
        set_flag( flag );
    }

    if( jo.has_member( "examine_action" ) ) {
        examine = iexamine_function_from_string( jo.get_string( "examine_action" ) );
    } else {
        examine = iexamine_function_from_string( "none" );
    }

    optional( jo, was_loaded, "open", open, string_id_reader<furn_t> {}, NULL_ID );
    optional( jo, was_loaded, "close", close, string_id_reader<furn_t> {}, NULL_ID );

    bash.load( jo, "bash", true );
    deconstruct.load( jo, "deconstruct", true );
}
开发者ID:nonymous,项目名称:Cataclysm-DDA,代码行数:27,代码来源:mapdata.cpp


示例4: client

	bool dto_complex::parse( const rapidjson::Value& json )
	{
		if( json.IsObject() && json.HasMember( key() ) && json[key()].IsObject() )
		{
			for( auto& child : get_children() )
			{
				child->set_client( client() );
				if( !child->parse( json[key()] ) && !optional() )
				{
					return false;
				}
			}
			
			return true;
		}
		else if( json.IsObject() )
		{
			for( auto& child : get_children() )
			{
				child->set_client( client() );
				if( !child->parse( json ) && !optional()  )
				{
					return false;
				}
			}
			
			return true;
		}

		set_present( false );
		return optional();
	}
开发者ID:wrren,项目名称:riot-api-cpp,代码行数:32,代码来源:dto_complex.cpp


示例5: parse_enum_decl

/* `enum` must already be matched. */
static void parse_enum_decl(fb_parser_t *P, fb_compound_type_t *ct)
{
    fb_token_t *t, *t0;
    fb_member_t *member;

    if (!(ct->symbol.ident = match(P, LEX_TOK_ID, "enum declaration expected identifier"))) {
        goto fail;
    }
    if (optional(P, ':')) {
        parse_type(P, &ct->type);
        if (ct->type.type != vt_scalar_type) {
            error_tok(P, ct->type.t, "integral type expected");
        } else {
            switch (ct->type.t->id) {
            case tok_kw_float:
            case tok_kw_double:
                error_tok(P, ct->type.t, "integral type expected");
            default:
                break;
            }
        }
    }
    ct->metadata = parse_metadata(P);
    if (!((t0 = match(P, '{', "enum declaration expected '{'")))) {
        goto fail;
    }
    for (;;) {
        if (!(t = match(P, LEX_TOK_ID,
                "member identifier expected"))) {
            goto fail;
        }
        if (P->failed >= FLATCC_MAX_ERRORS) {
            goto fail;
        }
        member = fb_add_member(P, &ct->members);
        member->symbol.ident = t;
        if (optional(P, '=')) {
            t = P->token;
            parse_value(P, &member->value, 0, "integral constant expected");
            /* Leave detailed type (e.g. no floats) and range checking to a later stage. */
        }
        /*
         * Trailing comma is optional in flatc but not in grammar, we
         * follow flatc.
         */
        if (!optional(P, ',') || P->token->id == '}') {
            break;
        }
        P->doc = 0;
    }
    if (t0) {
        advance(P, '}', "enum missing closing '}' to match", t0);
    }
    revert_symbols(&ct->members);
    return;
fail:
    recover(P, '}', 1);
}
开发者ID:Tao-Ma,项目名称:flatcc,代码行数:59,代码来源:parser.c


示例6: parse_type

/* ':' must already be matched */
static void parse_type(fb_parser_t *P, fb_value_t *v)
{
    fb_token_t *t = 0;
    fb_token_t *t0 = P->token;
    int vector = 0;

    v->type = vt_invalid;
    while ((t = optional(P, '['))) {
        ++vector;
    }
    if (vector > 1) {
        error_tok(P, t0, "vector type can only be one-dimensional");
    }
    switch (P->token->id) {
    case tok_kw_int:
    case tok_kw_bool:
    case tok_kw_byte:
    case tok_kw_long:
    case tok_kw_uint:
    case tok_kw_float:
    case tok_kw_short:
    case tok_kw_ubyte:
    case tok_kw_ulong:
    case tok_kw_ushort:
    case tok_kw_double:
        v->t = P->token;
        v->type = vector ? vt_vector_type : vt_scalar_type;
        next(P);
        break;
    case tok_kw_string:
        v->t = P->token;
        v->type = vector ? vt_vector_string_type : vt_string_type;
        next(P);
        break;
    case LEX_TOK_ID:
        parse_ref(P, &v->ref);
        v->type = vector ? vt_vector_type_ref : vt_type_ref;
        break;
    case ']':
        error_tok(P, t, "vector type cannot be empty");
        break;
    default:
        error_tok(P, t, "invalid type specifier");
        break;
    }
    while (optional(P, ']') && vector--) {
    }
    if (vector) {
        error_tok_2(P, t, "vector type missing ']' to match", t0);
    }
    if ((t = optional(P, ']'))) {
        error_tok_2(P, t, "extra ']' not matching", t0);
        while (optional(P, ']')) {
        }
    }
}
开发者ID:Tao-Ma,项目名称:flatcc,代码行数:57,代码来源:parser.c


示例7: mandatory

void overmap_connection::subtype::load( JsonObject &jo )
{
    static const typed_flag_reader<decltype( connection_subtype_flag_map )> flag_reader{ connection_subtype_flag_map, "invalid connection subtype flag" };

    mandatory( jo, false, "terrain", terrain );
    mandatory( jo, false, "locations", locations );

    optional( jo, false, "basic_cost", basic_cost, 0 );
    optional( jo, false, "flags", flags, flag_reader );
}
开发者ID:Barhandar,项目名称:Cataclysm-DDA,代码行数:10,代码来源:overmap_connection.cpp


示例8: optional

void species_type::load( JsonObject &jo, const std::string & )
{
    const auto flag_reader = enum_flags_reader<m_flag> { "monster flag" };
    optional( jo, was_loaded, "flags", flags, flag_reader );

    const auto trigger_reader = enum_flags_reader<mon_trigger> { "monster trigger" };
    optional( jo, was_loaded, "anger_triggers", anger, trigger_reader );
    optional( jo, was_loaded, "placate_triggers", placate, trigger_reader );
    optional( jo, was_loaded, "fear_triggers", fear, trigger_reader );
}
开发者ID:vidarsk,项目名称:Cataclysm-DDA,代码行数:10,代码来源:monstergenerator.cpp


示例9: pgettext

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


示例10: optional

void species_type::load( JsonObject &jo )
{
    MonsterGenerator &gen = MonsterGenerator::generator();

    const typed_flag_reader<decltype( gen.flag_map )> flag_reader{ gen.flag_map, "invalid monster flag" };
    optional( jo, was_loaded, "flags", flags, flag_reader );

    const typed_flag_reader<decltype( gen.trigger_map )> trigger_reader{ gen.trigger_map, "invalid monster trigger" };
    optional( jo, was_loaded, "anger_triggers", anger_trig, trigger_reader );
    optional( jo, was_loaded, "placate_triggers", placate_trig, trigger_reader );
    optional( jo, was_loaded, "fear_triggers", fear_trig, trigger_reader );
}
开发者ID:Argoroth,项目名称:Cataclysm-DDA,代码行数:12,代码来源:monstergenerator.cpp


示例11: mandatory

void mission_type::load( JsonObject &jo, const std::string & )
{
    mandatory( jo, was_loaded, "name", name, translated_string_reader );

    mandatory( jo, was_loaded, "difficulty", difficulty );
    mandatory( jo, was_loaded, "value", value );

    auto djo = jo.get_object( "dialogue" );
    // @todo There should be a cleaner way to do it
    mandatory( djo, was_loaded, "describe", dialogue[ "describe" ] );
    mandatory( djo, was_loaded, "offer", dialogue[ "offer" ] );
    mandatory( djo, was_loaded, "accepted", dialogue[ "accepted" ] );
    mandatory( djo, was_loaded, "rejected", dialogue[ "rejected" ] );
    mandatory( djo, was_loaded, "advice", dialogue[ "advice" ] );
    mandatory( djo, was_loaded, "inquire", dialogue[ "inquire" ] );
    mandatory( djo, was_loaded, "success", dialogue[ "success" ] );
    mandatory( djo, was_loaded, "success_lie", dialogue[ "success_lie" ] );
    mandatory( djo, was_loaded, "failure", dialogue[ "failure" ] );

    optional( jo, was_loaded, "urgent", urgent );
    optional( jo, was_loaded, "item", item_id );
    optional( jo, was_loaded, "count", item_count, 1 );

    goal = jo.get_enum_value<decltype(goal)>( "goal" );

    assign_function( jo, "place", place, tripoint_function_map );
    assign_function( jo, "start", start, mission_function_map );
    assign_function( jo, "end", end, mission_function_map );
    assign_function( jo, "fail", fail, mission_function_map );

    if( jo.has_int( "deadline_low" ) ) {
        deadline_low = DAYS( jo.get_int( "deadline_low" ) );
    }

    if( jo.has_int( "deadline_high" ) ) {
        deadline_high = DAYS( jo.get_int( "deadline_high" ) );
    }

    if( jo.has_member( "origins" ) ) {
        origins.clear();
        for( auto &m : jo.get_tags( "origins" ) ) {
            origins.emplace_back( io::string_to_enum_look_up( io::origin_map, m ) );
        }
    }

    if( jo.has_member( "followup" ) ) {
        follow_up = mission_type_id( jo.get_string( "followup" ) );
    }

    if( jo.has_member( "destination" ) ) {
        target_id = oter_id( jo.get_string( "destination" ) );
    }
}
开发者ID:Guuo,项目名称:Cataclysm-DDA,代码行数:53,代码来源:missiondef.cpp


示例12: parse_cmdline

// Command line parsing
std::pair<bool, etix::tool::opt_parse>
parse_cmdline(int argc, char* argv[]) {
    auto opt_parse = etix::tool::opt_parse{ argc, argv };

    opt_parse.optional("-c", "Path to the configuration file (-c /path/to/conf)", true);
    opt_parse.optional("-l", "Set log level (-l 4 will only show warnings and errors)", true);
    opt_parse.optional("-d", "Launch the discovery tool on the given subnet", false);
    opt_parse.optional("-b", "Launch the bruteforce tool on all discovered devices", false);
    opt_parse.optional("-t", "Generate thumbnails from detected cameras", false);
    opt_parse.optional("-g", "Check if the stream can be opened with GStreamer", false);
    opt_parse.optional("-v", "Display Cameradar's version", false);
    opt_parse.optional("-h", "Display this help", false);
    opt_parse.execute();

    if (opt_parse.exist("-h")) {
        opt_parse.print_help();
        return std::make_pair(false, opt_parse);
    } else if (opt_parse.exist("-v")) {
        print_version();
        return std::make_pair(false, opt_parse);
    } else if (opt_parse.has_error()) {
        std::cout << "Usage: ./cameradar [option]\n\toptions:\n" << std::endl;
        opt_parse.print_help();
        return std::make_pair(false, opt_parse);
    }

    return std::make_pair(true, opt_parse);
}
开发者ID:boban-dj,项目名称:cameradar,代码行数:29,代码来源:main.cpp


示例13: mandatory

void material_type::load( JsonObject &jsobj )
{
    mandatory( jsobj, was_loaded, "name", _name, translated_string_reader );

    mandatory( jsobj, was_loaded, "bash_resist", _bash_resist );
    mandatory( jsobj, was_loaded, "cut_resist", _cut_resist );
    mandatory( jsobj, was_loaded, "acid_resist", _acid_resist );
    mandatory( jsobj, was_loaded, "elec_resist", _elec_resist );
    mandatory( jsobj, was_loaded, "fire_resist", _fire_resist );
    mandatory( jsobj, was_loaded, "chip_resist", _chip_resist );
    mandatory( jsobj, was_loaded, "density", _density );

    optional( jsobj, was_loaded, "salvaged_into", _salvaged_into, "null" );
    optional( jsobj, was_loaded, "repaired_with", _repaired_with, "null" );
    optional( jsobj, was_loaded, "edible", _edible, false );
    optional( jsobj, was_loaded, "soft", _soft, false );

    auto arr = jsobj.get_array( "vitamins" );
    while( arr.has_more() ) {
        auto pair = arr.next_array();
        _vitamins.emplace( vitamin_id( pair.get_string( 0 ) ), pair.get_float( 1 ) );
    }

    mandatory( jsobj, was_loaded, "bash_dmg_verb", _bash_dmg_verb, translated_string_reader );
    mandatory( jsobj, was_loaded, "cut_dmg_verb", _cut_dmg_verb, translated_string_reader );

    JsonArray jsarr = jsobj.get_array( "dmg_adj" );
    while( jsarr.has_more() ) {
        _dmg_adj.push_back( _( jsarr.next_string().c_str() ) );
    }

    JsonArray burn_data_array = jsobj.get_array( "burn_data" );
    for( size_t intensity = 0; intensity < MAX_FIELD_DENSITY; intensity++ ) {
        if( burn_data_array.has_more() ) {
            JsonObject brn = burn_data_array.next_object();
            _burn_data[ intensity ] = load_mat_burn_data( brn );
        } else {
            // If not specified, supply default
            bool flammable = _fire_resist <= ( int )intensity;
            mat_burn_data mbd;
            if( flammable ) {
                mbd.burn = 1;
            }

            _burn_data[ intensity ] = mbd;
        }
    }
}
开发者ID:CrAzYPiLoT-SS13,项目名称:Cataclysm-DDA,代码行数:48,代码来源:material.cpp


示例14: parse_union_decl

/* `union` must already be matched. */
static void parse_union_decl(fb_parser_t *P, fb_compound_type_t *ct)
{
    fb_token_t *t0;
    fb_member_t *member;
    fb_ref_t *ref;

    if (!(ct->symbol.ident = match(P, LEX_TOK_ID, "union declaration expected identifier"))) {
        goto fail;
    }
    ct->metadata = parse_metadata(P);
    if (!((t0 = match(P, '{', "union declaration expected '{'")))) {
        goto fail;
    }
    for (;;) {
        if (P->token->id != LEX_TOK_ID) {
            error_tok(P, P->token, "union expects an identifier");
            goto fail;
        }
        if (P->failed >= FLATCC_MAX_ERRORS) {
            goto fail;
        }
        member = fb_add_member(P, &ct->members);
        parse_ref(P, &ref);
        member->type.ref = ref;
        member->type.type = vt_type_ref;
        while (ref->link) {
            ref = ref->link;
        }
        /* The union member is the unqualified reference. */
        member->symbol.ident = ref->ident;
        if (optional(P, '=')) {
            parse_value(P, &member->value, 0, "integral constant expected");
            /* Leave detailed type (e.g. no floats) and range checking to a later stage. */
        }
        if (!optional(P, ',') || P->token->id == '}') {
            break;
        }
        P->doc = 0;
    }
    advance(P, '}', "union missing closing '}' to match", t0);
    revert_symbols(&ct->members);
    /* Add implicit `NONE` member first in the list. */
    member = fb_add_member(P, &ct->members);
    member->symbol.ident = &P->t_none;
    return;
fail:
    recover2(P, ';', 1, '}', 0);
}
开发者ID:Tao-Ma,项目名称:flatcc,代码行数:49,代码来源:parser.c


示例15: parse_method

static void parse_method(fb_parser_t *P, fb_member_t *fld)
{
    fb_token_t *t;
    if (!(t = match(P, LEX_TOK_ID, "method expected identifier"))) {
        goto fail;
    }
    fld->symbol.ident = t;
    if (!match(P, '(', "method expected '(' after identifier")) {
        goto fail;
    }
    parse_type(P, &fld->req_type);
    if (!match(P, ')', "method expected ')' after request type")) {
        goto fail;
    }
    if (!match(P, ':', "method expected ':' before mandatory response type")) {
        goto fail;
    }
    parse_type(P, &fld->type);
    if ((t = optional(P, '='))) {
        error_tok(P, t, "method does not accept an initializer");
        goto fail;
    }
    fld->metadata = parse_metadata(P);
    advance(P, ';', "method must be terminated with ';'", 0);
    return;
fail:
    recover2(P, ';', 1, '}', 0);
}
开发者ID:Tao-Ma,项目名称:flatcc,代码行数:28,代码来源:parser.c


示例16: parse_compound_type

/* `struct` or `table` must already be matched. */
static void parse_compound_type(fb_parser_t *P, fb_compound_type_t *ct)
{
    fb_token_t *t = 0;

    if (!(t = match(P, LEX_TOK_ID, "Declaration expected an identifier"))) {
        goto fail;
    }
    ct->symbol.ident = t;
    ct->metadata = parse_metadata(P);
    if (!(match(P, '{', "Declaration expected '{'"))) {
        goto fail;
    }
    t = P->token;

/* Allow empty tables and structs. */
#if 0
    if (P->token->id == '}') {
        error_tok(P, t, "table / struct declaration cannot be empty");
    }
#endif
    while (P->token->id != '}') {
        parse_field(P, fb_add_member(P, &ct->members));
        if (P->failed >= FLATCC_MAX_ERRORS) {
            goto fail;
        }
    }
    if (!optional(P, '}') && t) {
        error_tok_2(P, P->token, "Declaration missing closing '}' to match", t);
    }
    revert_symbols(&ct->members);
    return;
fail:
    recover(P, '}', 1);
}
开发者ID:eric-bentley,项目名称:flatcc,代码行数:35,代码来源:parser.c


示例17: while

static void ComplexDictionary::build(string name) {
    string buffer;
    while (cin >> buffer) {
        size_t index = -1;
        if (buffer.find("//") != string::npos) {
            if (index = buffer.find("&")) {
                reversal(buffer);
            }
            else if (index = buffer.find("[")) {
                size_t endIndex = buffer.find("]");
                insertEach(buffer, index, endIndex);
            }
            else if (index = buffer.find("?")) {
                optional(buffer, index);
            }
            else if (index = buffer.find("!")) {
                swap(buffer, index);
            }
            else
                words.push_back(buffer);
        }
    }

    reverse(words.begin(), words.end());
}
开发者ID:cruzb,项目名称:Project1,代码行数:25,代码来源:ComplexDictionary.cpp


示例18: parse_field

static void parse_field(fb_parser_t *P, fb_member_t *fld)
{
    fb_token_t *t;
    if (!(t = match(P, LEX_TOK_ID, "field expected identifier"))) {
        goto fail;
    }
    fld->symbol.ident = t;
    if (!match(P, ':', "field expected ':' before mandatory type")) {
        goto fail;
    }
    parse_type(P, &fld->type);
    if (optional(P, '=')) {
        /*
         * Because types can be named references, we do not check the
         * default assignment before the schema is fully parsed.
         * We allow the initializer to be a name in case it is an enum
         * name.
         */
        parse_value(P, &fld->value, allow_id_value, "initializer must be of scalar type");
    }
    fld->metadata = parse_metadata(P);
    advance(P, ';', "field must be terminated with ';'", 0);
    return;
fail:
    recover2(P, ';', 1, '}', 0);
}
开发者ID:Tao-Ma,项目名称:flatcc,代码行数:26,代码来源:parser.c


示例19: loop1

PrologLexer::PrologLexer()
{

    lexer.rules[Prolog::Spacing] = loop1(charOf(" \t\n\r"));
    lexer.rules[Prolog::LParen] = str("(");
    lexer.rules[Prolog::RParen] = str(")");
    lexer.rules[Prolog::LBracket] = str("[");
    lexer.rules[Prolog::RBracket] = str("]");
    lexer.rules[Prolog::OnlyIf] = str(":-");
    lexer.rules[Prolog::Eq] = str("=");
    /*
    lexer.rules[Prolog::Lt] = str("<");
    lexer.rules[Prolog::Gt] = str(">");
    lexer.rules[Prolog::Le] = str("<=");
    lexer.rules[Prolog::Ge] = str(">=");
    lexer.rules[Prolog::Ne] = str("<>");
    */
    lexer.rules[Prolog::Dot] = str(".");
    lexer.rules[Prolog::Comma] = str(",");
    lexer.rules[Prolog::Semi] = str(";");
    lexer.rules[Prolog::Bar] = str("|");
    lexer.rules[Prolog::DomainsKw] = str("domains");
    lexer.rules[Prolog::PredicatesKw] = str("predicates");
    lexer.rules[Prolog::ClausesKw] = str("clauses");
    lexer.rules[Prolog::AssertKw] = str("assert");

    lexer.rules[Prolog::Str] = seq(str("\""),
                                   loop(anyBut(choice(str("\""), str("\n")))),
                                   str("\""));

    shared_ptr<RegExp> digit = charIs([](QChar c) {
        return c.isDigit();
    },"<digit>");
    shared_ptr<RegExp> letter = charIs([](QChar c) {
        return c.isLetter();
    }, "<letter>");
    shared_ptr<RegExp> smallLetter = charIs([](QChar c) {
        return c.isLower();
    }, "<lowercase>");
    shared_ptr<RegExp> capitalLetter = charIs([](QChar c) {
        return c.isUpper();
    }, "<uppercase>");
    shared_ptr<RegExp> alpha = charIs([](QChar c) {
        return c.isLetterOrNumber();
    },"<alphanumeric>");
    shared_ptr<RegExp> symbol = charOf("+-/*<>=");
    shared_ptr<RegExp> digits = seq(loop1(digit), checkNo(letter));
    shared_ptr<RegExp> smallLetterOrSymbol = choice(smallLetter, symbol);
    shared_ptr<RegExp> alphaOrUnderscore = choice(alpha, str("_"));
    shared_ptr<RegExp> alphaOrSymbol= choice(alpha, symbol);

    lexer.rules[Prolog::Num] = seq(digits,
                                   optional(seq(str("."), digits)));

    lexer.rules[Prolog::Symbol] = seq(smallLetterOrSymbol, loop(choice(digit, alphaOrSymbol)));
    lexer.rules[Prolog::Variable] = seq(choice(capitalLetter, str("_")),
                                        loop(choice(digit, alphaOrUnderscore)));

}
开发者ID:samiz,项目名称:smallprolog,代码行数:59,代码来源:prologlexer.cpp


示例20: mandatory

void morale_type_data::load( JsonObject &jo, const std::string & )
{
    mandatory( jo, was_loaded, "id", id );
    mandatory( jo, was_loaded, "text", text, translated_string_reader );

    optional( jo, was_loaded, "permanent", permanent, false );
    needs_item = text.find( "%s" ) != std::string::npos;
}
开发者ID:belazzz,项目名称:Cataclysm-DDA,代码行数:8,代码来源:morale_types.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ optionsClicked函数代码示例发布时间:2022-05-30
下一篇:
C++ option_find_str函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap