本文整理汇总了C++中parse_enum函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_enum函数的具体用法?C++ parse_enum怎么用?C++ parse_enum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_enum函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetValuesGP
/**
* Gets values associated to a given option for the GenPrepare function.
*
* @param varName NULL-terminated string containing the option name
* @param varValue NULL-terminated string containing the option value
* @param PB a pointer to a structure containing benchmark parameters for this session
*/
static void
GetValuesGP (const char *varName,
const char *varValue,
UflipParams *PB)
{
const char *fmt_str [3] = { "None", "Seq", "Rnd" };
const int fmt_enum [3] = { NONE, SEQ, RND };
if (get_common_values (varName, varValue, PB))
return;
/* still some specific options to parse */
if (get_common_gen_values (varName, varValue, PB))
return;
/* still not fatal */
if (strcasecmp (varName, "OutName") == 0)
{
strcpy (PB->outName, varValue);
}
else if (parse_number ("IOC", varName, varValue, "%d", &PB->IOCount));
else if (parse_number ("IOC2", varName, varValue, "%d", &PB->IOCount2));
else if (parse_number ("Pause", varName, varValue, "%d", &PB->pauseExp))
{
PB->pauseExp *= 1000;
}
else if (parse_enum ("FormatType", varName, varValue, fmt_str, fmt_enum, 3,
&PB->fmtType, sizeof (PB->fmtType)));
else
{
/* ok, now this is fatal */
PrintHelp (varName);
}
}
示例2: parse_alias
/* XXX EXTRA_PARAM and PARAM_NUM are a kludge to get in
* backward-compatible support for "format" parameter type. The
* latter is only valid if the former is non-NULL, which is only in
* top-level context. */
static int
parse_alias(struct protolib *plib, struct locus *loc,
char **str, struct arg_type_info **retp, int *ownp,
struct param **extra_param, size_t param_num)
{
/* For backward compatibility, we need to support things like
* stringN (which is like string[argN], string[N], and also
* bare string. We might, in theory, replace this by
* preprocessing configure file sources with M4, but for now,
* "string" is syntax. */
if (strncmp(*str, "string", 6) == 0) {
(*str) += 6;
return parse_string(plib, loc, str, retp, ownp);
} else if (try_parse_kwd(str, "format") >= 0
&& extra_param != NULL) {
/* For backward compatibility, format is parsed as
* "string", but it smuggles to the parameter list of
* a function a "printf" argument pack with this
* parameter as argument. */
if (parse_string(plib, loc, str, retp, ownp) < 0)
return -1;
return build_printf_pack(loc, extra_param, param_num);
} else if (try_parse_kwd(str, "enum") >=0) {
return parse_enum(plib, loc, str, retp, ownp);
} else {
*retp = NULL;
return 0;
}
}
示例3: fw3_parse_limit
bool
fw3_parse_limit(void *ptr, const char *val, bool is_list)
{
struct fw3_limit *limit = ptr;
enum fw3_limit_unit u = FW3_LIMIT_UNIT_SECOND;
char *e;
int n;
if (*val == '!')
{
limit->invert = true;
while (isspace(*++val));
}
n = strtol(val, &e, 10);
if (errno == ERANGE || errno == EINVAL)
return false;
if (*e && *e++ != '/')
return false;
if (!strlen(e))
return false;
if (!parse_enum(&u, e, limit_units, 0, FW3_LIMIT_UNIT_DAY))
return false;
limit->rate = n;
limit->unit = u;
return true;
}
示例4: assert
/*
* Parse the value based on the field table
*
* @param context The main context pointer
* @param rest String to parse
* @param field Field item to parse
* @param value Returns the value that was parsed
* @return the remainder of the string after the value was parsed
*/
static char
*parse_field_value(build_image_context *context,
char *rest,
field_item *field,
u_int32_t *value)
{
assert(rest != NULL);
assert(field != NULL);
assert((field->type != field_type_enum)
|| (field->enum_table != NULL));
switch (field->type) {
case field_type_enum:
rest = parse_enum(context, rest, field->enum_table, value);
break;
case field_type_u32:
rest = parse_u32(rest, value);
break;
case field_type_u8:
rest = parse_u8(rest, value);
break;
default:
printf("Unexpected field type %d at line %d\n",
field->type, __LINE__);
rest = NULL;
break;
}
return rest;
}
示例5: parse
file_contents parse(parse_source source) {
file_contents contents;
contents.imports = ll_new();
contents.enums = ll_new();
contents.unions = ll_new();
contents.structs = ll_new();
contents.functions = ll_new();
optional op = get_token(&source);
while(op_has(op)) {
parse_token current = *((parse_token*)op_get(op));
if(equals(current.data, new_slice("struct"))) {
struct_declaration *dec = analyze_struct(&source);
ll_add_last(contents.structs, dec);
} else if(equals(current.data, new_slice("union"))) {
struct_declaration *dec = analyze_struct(&source);
ll_add_last(contents.unions, dec);
} else if(equals(current.data, new_slice("func"))) {
func_declaration *func = analyze_func(&source);
ll_add_last(contents.functions, func);
} else if(equals(current.data, new_slice("import"))) {
import_declaration *imp = parse_import(&source);
ll_add_last(contents.imports, imp);
} else if(equals(current.data, new_slice("enum"))) {
enum_declaration *enm = parse_enum(&source);
ll_add_last(contents.enums, enm);
}//TODO: Throw an error for an unexpected token
op = get_token(&source);
}
return contents;
}
示例6: get_common_values
/**
* Parses the following options/values: Dev, Size, Fake. They are common to all functions.
*
* @param varName option name
* @param varValue option value
* @param PB pointer to a struct where to store the parsed options
* @return false if given @a varName isn't a known option or if given @a varValue
* isn't a valid value for the option, otherwise true.
*/
static bool
get_common_values (const char *varName,
const char *varValue,
UflipParams *PB)
{
const char *fake_str [2] = { "True", "False" };
const bool fake_enum [2] = { true, false };
if (strcasecmp (varName, "Dev") == 0)
{
PB->device = uflip_device_new (varValue);
}
else if (parse_number ("Size", varName, varValue, "%d", &PB->deviceSize))
{
PB->deviceSize /= BLOCK;
PB->deviceSize *= BLOCK;
}
else if (parse_enum ("Fake", varName, varValue, fake_str, fake_enum, 2,
&PB->fake, sizeof (PB->fake)));
else
{
return false; /* warning, unknown option! */
}
return true; /* option found and parsed. */
}
示例7: parse_module
/** Parse module.
*
* Parse a program module.
*
* The input is read using the lexer associated with @a parse. The resulting
* declarations are added to existing declarations in the program associated
* with @a parse.
*
* If any parse error occurs, parse->error will @c b_true when this function
* returns. parse->error_bailout will be @c b_true if the error has not
* been recovered yet. Similar holds for other parsing functions in this
* module.
*
* @param parse Parser object.
*/
void parse_module(parse_t *parse)
{
stree_csi_t *csi;
stree_enum_t *enum_d;
stree_modm_t *modm;
while (lcur_lc(parse) != lc_eof && !parse_is_error(parse)) {
switch (lcur_lc(parse)) {
case lc_class:
case lc_struct:
case lc_interface:
csi = parse_csi(parse, lcur_lc(parse), NULL);
modm = stree_modm_new(mc_csi);
modm->u.csi = csi;
list_append(&parse->cur_mod->members, modm);
break;
case lc_enum:
enum_d = parse_enum(parse, NULL);
modm = stree_modm_new(mc_enum);
modm->u.enum_d = enum_d;
list_append(&parse->cur_mod->members, modm);
break;
default:
lunexpected_error(parse);
lex_next(parse->lex);
break;
}
}
}
示例8: parse_type
static int32_t
parse_type(struct snmp_toolinfo *snmptoolctx, enum tok *tok,
enum snmp_tc *tc, struct enum_pairs **snmp_enum)
{
int32_t syntax, mem;
syntax = val;
*tc = 0;
if (*tok == TOK_ENUM || *tok == TOK_BITS) {
if (*snmp_enum == NULL) {
if ((*snmp_enum = enum_pairs_init()) == NULL)
return (-1);
mem = 1;
*tc = SNMP_TC_OWN;
} else
mem = 0;
if (gettoken(snmptoolctx) != '(') {
warnx("'(' expected after ENUM/BITS");
return (-1);
}
if ((*tok = gettoken(snmptoolctx)) != TOK_NUM) {
warnx("need value for ENUM//BITS");
if (mem == 1) {
free(*snmp_enum);
*snmp_enum = NULL;
}
return (-1);
}
if (parse_enum(snmptoolctx, tok, *snmp_enum) < 0) {
enum_pairs_free(*snmp_enum);
*snmp_enum = NULL;
return (-1);
}
*tok = gettoken(snmptoolctx);
} else if (*tok == TOK_DEFTYPE) {
struct enum_type *t;
*tc = 0;
t = snmp_enumtc_lookup(snmptoolctx, nexttok);
if (t != NULL)
*snmp_enum = t->snmp_enum;
*tok = gettoken(snmptoolctx);
} else {
if ((*tok = gettoken(snmptoolctx)) == '|') {
if (parse_subtype(snmptoolctx, tok, tc) < 0)
return (-1);
}
}
return (syntax);
}
示例9: parse_decl
void parse_decl(context& ctx) throw (coord) {
parse_enum(ctx);
if (ctx.tag == IDENT)
parse_vars(ctx);
if (ctx.tag != SEMICOLON)
throw ctx.start;
next_token(ctx);
}
示例10: parse_session_id
__owur static int parse_session_id(SSL_TEST_CTX *test_ctx, const char *value)
{
int ret_value;
if (!parse_enum(ssl_session_id, OSSL_NELEM(ssl_session_id),
&ret_value, value)) {
return 0;
}
test_ctx->session_id_expected = ret_value;
return 1;
}
示例11: parse_key_update_type
__owur static int parse_key_update_type(SSL_TEST_CTX *test_ctx, const char *value)
{
int ret_value;
if (!parse_enum(ssl_key_update_types, OSSL_NELEM(ssl_key_update_types),
&ret_value, value)) {
return 0;
}
test_ctx->key_update_type = ret_value;
return 1;
}
示例12: parse_handshake_mode
__owur static int parse_handshake_mode(SSL_TEST_CTX *test_ctx, const char *value)
{
int ret_value;
if (!parse_enum(ssl_handshake_modes, OSSL_NELEM(ssl_handshake_modes),
&ret_value, value)) {
return 0;
}
test_ctx->handshake_mode = ret_value;
return 1;
}
示例13: parse_test_method
__owur static int parse_test_method(SSL_TEST_CTX *test_ctx, const char *value)
{
int ret_value;
if (!parse_enum(ssl_test_methods, OSSL_NELEM(ssl_test_methods),
&ret_value, value)) {
return 0;
}
test_ctx->method = ret_value;
return 1;
}
示例14: parse_expected_result
__owur static int parse_expected_result(SSL_TEST_CTX *test_ctx, const char *value)
{
int ret_value;
if (!parse_enum(ssl_test_results, OSSL_NELEM(ssl_test_results),
&ret_value, value)) {
return 0;
}
test_ctx->expected_result = ret_value;
return 1;
}
示例15: parse_servername_callback
__owur static int parse_servername_callback(SSL_TEST_SERVER_CONF *server_conf,
const char *value)
{
int ret_value;
if (!parse_enum(ssl_servername_callbacks,
OSSL_NELEM(ssl_servername_callbacks), &ret_value, value)) {
return 0;
}
server_conf->servername_callback = ret_value;
return 1;
}