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


C++ enif_make_list函数代码示例

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


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

示例1: enif_make_list

static void *start_element_handler(expat_parser *parser_data, const XML_Char *name, const XML_Char **atts)
{
    ErlNifBinary element_name;
    ERL_NIF_TERM attrs_list = enif_make_list(parser_data->env, 0);
    int i;

    element_name = encode_name(parser_data, name);
    for(i = 0; atts[i]; i += 2);
    while(i)
        {
            ErlNifBinary attr_name, attr_value;

            enif_alloc_binary(strlen(atts[i-1]), &attr_value);
            strcpy((char *) attr_value.data, (const char *)atts[i-1]);
            attr_name = encode_name(parser_data, atts[i-2]);

            ERL_NIF_TERM attr = enif_make_tuple(parser_data->env, 2,
                                                enif_make_binary(parser_data->env, &attr_name),
                                                enif_make_binary(parser_data->env, &attr_value));
            attrs_list = enif_make_list_cell(parser_data->env, attr, attrs_list);

            i -= 2;
        };


    ERL_NIF_TERM event = enif_make_tuple(parser_data->env, 4, XML_ELEMENT_START,
                                         enif_make_binary(parser_data->env, &element_name),
                                         parser_data->xmlns,
                                         attrs_list);
    parser_data->result = enif_make_list_cell(parser_data->env, event, parser_data->result);
    parser_data->xmlns = enif_make_list(parser_data->env, 0);

    return NULL;
};
开发者ID:RGafiyatullin,项目名称:exml,代码行数:34,代码来源:exml_event.c

示例2: enif_make_list

static void *start_element_handler(expat_parser *parser_data, const XML_Char *name, const XML_Char **atts)
{
    ERL_NIF_TERM element_name;
    ERL_NIF_TERM attrs_list = enif_make_list(parser_data->env, 0);
    int i;

    element_name = encode_name(parser_data, name);
    for(i = 0; atts[i]; i += 2);
    while(i)
    {
        ERL_NIF_TERM attr_name, attr_value;

        size_t atts_len = strlen(atts[i-1]);
        unsigned char *attr_data = enif_make_new_binary(parser_data->env, atts_len, &attr_value);
        strncpy((char*)attr_data, (const char *)atts[i-1], atts_len);
        attr_name = encode_name(parser_data, atts[i-2]);

        ERL_NIF_TERM attr = enif_make_tuple(parser_data->env, 2, attr_name, attr_value);
        attrs_list = enif_make_list_cell(parser_data->env, attr, attrs_list);

        i -= 2;
    };


    ERL_NIF_TERM event = enif_make_tuple(parser_data->env, 4, XML_ELEMENT_START,
                                         element_name,
                                         parser_data->xmlns,
                                         attrs_list);
    parser_data->result = enif_make_list_cell(parser_data->env, event, parser_data->result);
    parser_data->xmlns = enif_make_list(parser_data->env, 0);

    return NULL;
};
开发者ID:emd123,项目名称:kazoo,代码行数:33,代码来源:exml_event.c

示例3: macros

static ERL_NIF_TERM macros(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    const ERL_NIF_TERM* a;
    ERL_NIF_TERM lists, tuples;
    int arity;
    if (!enif_get_tuple(env, argv[0], &arity, &a) || arity != 9) {
	return enif_make_badarg(env);
    }
    
    lists = enif_make_list(env,9,
			   enif_make_list1(env,a[0]),
			   enif_make_list2(env,a[0],a[1]),
			   enif_make_list3(env,a[0],a[1],a[2]),
			   enif_make_list4(env,a[0],a[1],a[2],a[3]),
			   enif_make_list5(env,a[0],a[1],a[2],a[3],a[4]),
			   enif_make_list6(env,a[0],a[1],a[2],a[3],a[4],a[5]),
			   enif_make_list7(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6]),
			   enif_make_list8(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]),
			   enif_make_list9(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]));
    tuples = enif_make_list(env,9,
			    enif_make_tuple1(env,a[0]),
			    enif_make_tuple2(env,a[0],a[1]),
			    enif_make_tuple3(env,a[0],a[1],a[2]),
			    enif_make_tuple4(env,a[0],a[1],a[2],a[3]),
			    enif_make_tuple5(env,a[0],a[1],a[2],a[3],a[4]),
			    enif_make_tuple6(env,a[0],a[1],a[2],a[3],a[4],a[5]),
			    enif_make_tuple7(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6]),
			    enif_make_tuple8(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]),
			    enif_make_tuple9(env,a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]));
    return enif_make_tuple2(env,lists,tuples);
}
开发者ID:cristiangreco,项目名称:otp,代码行数:31,代码来源:nif_SUITE.c

示例4: decode_init

ERL_NIF_TERM
decode_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    Decoder* d;
    jiffy_st* st = (jiffy_st*) enif_priv_data(env);
    ERL_NIF_TERM tmp_argv[5];
    ERL_NIF_TERM opts;
    ERL_NIF_TERM val;

    if(argc != 2) {
        return enif_make_badarg(env);
    }

    d = dec_new(env);
    if(d == NULL) {
        return make_error(st, env, "internal_error");
    }

    tmp_argv[0] = argv[0];
    tmp_argv[1] = enif_make_resource(env, d);
    tmp_argv[2] = st->atom_error;
    tmp_argv[3] = enif_make_list(env, 0);
    tmp_argv[4] = enif_make_list(env, 0);

    enif_release_resource(d);

    opts = argv[1];
    if(!enif_is_list(env, opts)) {
        return enif_make_badarg(env);
    }

    while(enif_get_list_cell(env, opts, &val, &opts)) {
        if(get_bytes_per_iter(env, val, &(d->bytes_per_red))) {
            continue;
        } else if(get_bytes_per_red(env, val, &(d->bytes_per_red))) {
            continue;
        } else if(enif_compare(val, d->atoms->atom_return_maps) == 0) {
#if MAP_TYPE_PRESENT
            d->return_maps = 1;
#else
            return enif_make_badarg(env);
#endif
        } else if(enif_compare(val, d->atoms->atom_return_trailer) == 0) {
            d->return_trailer = 1;
        } else if(enif_compare(val, d->atoms->atom_dedupe_keys) == 0) {
            d->dedupe_keys = 1;
        } else if(enif_compare(val, d->atoms->atom_use_nil) == 0) {
            d->null_term = d->atoms->atom_nil;
        } else if(get_null_term(env, val, &(d->null_term))) {
            continue;
        } else {
            return enif_make_badarg(env);
        }
    }

    return decode_iter(env, 5, tmp_argv);
}
开发者ID:apache,项目名称:couchdb-jiffy,代码行数:57,代码来源:decoder.c

示例5: encode_init

ERL_NIF_TERM
encode_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    jiffy_st* st = (jiffy_st*) enif_priv_data(env);
    Encoder* e;

    ERL_NIF_TERM opts;
    ERL_NIF_TERM val;
    ERL_NIF_TERM tmp_argv[3];

    if(argc != 2) {
        return enif_make_badarg(env);
    }

    e = enc_new(env);
    if(e == NULL) {
        return make_error(st, env, "internal_error");
    }

    tmp_argv[0] = enif_make_resource(env, e);
    tmp_argv[1] = enif_make_list(env, 1, argv[0]);
    tmp_argv[2] = enif_make_list(env, 0);

    enif_release_resource(e);

    opts = argv[1];
    if(!enif_is_list(env, opts)) {
        return enif_make_badarg(env);
    }

    while(enif_get_list_cell(env, opts, &val, &opts)) {
        if(enif_compare(val, e->atoms->atom_uescape) == 0) {
            e->uescape = 1;
        } else if(enif_compare(val, e->atoms->atom_pretty) == 0) {
            e->pretty = 1;
        } else if(enif_compare(val, e->atoms->atom_escape_forward_slashes) == 0) {
            e->escape_forward_slashes = 1;
        } else if(enif_compare(val, e->atoms->atom_use_nil) == 0) {
            e->use_nil = 1;
        } else if(enif_compare(val, e->atoms->atom_force_utf8) == 0) {
            // Ignore, handled in Erlang
        } else if(get_bytes_per_iter(env, val, &(e->bytes_per_red))) {
            continue;
        } else if(get_bytes_per_red(env, val, &(e->bytes_per_red))) {
            continue;
        } else {
            return enif_make_badarg(env);
        }
    }

    return encode_iter(env, 3, tmp_argv);
}
开发者ID:DLive,项目名称:rest-edoc,代码行数:52,代码来源:encoder.c

示例6: enum_to_term

ERL_NIF_TERM enum_to_term(ErlNifEnv* env, StringEnumeration* en) {
    
    ERL_NIF_TERM head, tail;
    UErrorCode status = U_ZERO_ERROR;
    const char* buf;
    int32_t len;


    en->reset(status);   
    CHECK(env, status);

    tail = enif_make_list(env, 0);

    while (true) {
        buf = en->next(&len, status);
        CHECK(env, status);
        if (buf == NULL) 
            return tail;

        if (len > 255) 
            ERROR_STRING(env, "too_long_enum_element");

        head = enif_make_atom(env, buf);
        tail = enif_make_list_cell(env, head, tail);
    }
}
开发者ID:alepharchives,项目名称:i18n,代码行数:26,代码来源:i18n_nif.cpp

示例7: parse

static ERL_NIF_TERM parse(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    XML_Parser **parser;
    int is_final, res, errcode;
    ErlNifBinary stream;
    char *errstring;

    assert(argc == 3);

    if (!enif_get_resource(env, argv[0], PARSER_POINTER, (void **)&parser))
        return enif_make_badarg(env);

    if (!enif_is_binary(env, argv[1]))
        return enif_make_badarg(env);

    enif_get_int(env, argv[2], &is_final);
    enif_inspect_binary(env, argv[1], &stream);

    expat_parser *parser_data = XML_GetUserData((XML_Parser)(*parser));
    parser_data->result = enif_make_list(env, 0);
    parser_data->env = env;
    XML_SetUserData((XML_Parser)(*parser), parser_data);

    res = XML_Parse((XML_Parser)(*parser), (const char *)stream.data, stream.size, is_final);
    if(!res)
        {
            errcode = XML_GetErrorCode((XML_Parser)(*parser));
            errstring = (char *)XML_ErrorString(errcode);

            return enif_make_tuple(env, 2, ERROR,
                                   enif_make_string(env, errstring, ERL_NIF_LATIN1));
        }

    return enif_make_tuple(env, 2, OK, parser_data->result);
};
开发者ID:erszcz,项目名称:exml,代码行数:35,代码来源:exml_event.c

示例8: send_list_seq

static ERL_NIF_TERM send_list_seq(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    ErlNifPid to;
    ERL_NIF_TERM msg;
    ErlNifEnv* msg_env;
    int i, res;
    
    if (!enif_get_int(env, argv[0], &i)) {
	return enif_make_badarg(env);
    }
    if (argv[1] == atom_self) {
	enif_self(env, &to);
    }
    else if (!enif_get_local_pid(env, argv[1], &to)) {
	return enif_make_badarg(env);
    }
    msg_env = enif_alloc_env();
    msg = enif_make_list(msg_env,0);
    for ( ; i>0 ; i--) {
	msg = enif_make_list_cell(msg_env, enif_make_int(msg_env, i), msg);
    }
    res = enif_send(env, &to, msg_env, msg);
    enif_free_env(msg_env);
    return enif_make_tuple2(env, atom_ok, enif_make_int(env,res));
}
开发者ID:cristiangreco,项目名称:otp,代码行数:25,代码来源:nif_SUITE.c

示例9: mem_read

static ERL_NIF_TERM
mem_read(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
  unsigned int err, l, i, tmp;
  char element;
  int ar;
  char* ptr;
  ERL_NIF_TERM list, head, *tpl;


  err = enif_get_tuple(env, argv[0], &ar, (const ERL_NIF_TERM**)(&tpl));
  if (err) {
    err = nifty_get_ptr(env, tpl[0], (ptr_t*)&ptr);
  }
  if (!err) {
    goto error;
  }

  err = enif_get_uint(env, argv[1], &l);
  if (!err) {
    goto error;
  }

  list = enif_make_list(env, 0);

  for (i=0;i<l;i++) {
    element = (char)*(ptr+(l-1)-i);
    tmp = element & 0xff;
    head = enif_make_uint(env, tmp);
    list = enif_make_list_cell(env, head, list);
  }
  return list;
 error:
  return enif_make_badarg(env);
}
开发者ID:276361270,项目名称:nifty,代码行数:35,代码来源:nifty.c

示例10: split

ERL_NIF_TERM split(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    ErlNifBinary in;
    cloner* ptr; 
    UBreakIterator* iter; 
    int len = -1, last, pos, is_valid;
    UErrorCode status = U_ZERO_ERROR;
    ERL_NIF_TERM head, tail;
    UChar* bin; 
    UChar* text;
    

    if (argc != 2)
        return enif_make_badarg(env);

    /* Last argument must be a binary */
    if (!(enif_inspect_binary(env, argv[1], &in)
       && enif_get_resource(env, argv[0], iterator_type, (void**) &ptr))) {
        return enif_make_badarg(env);
    }    
    iter = (UBreakIterator*) cloner_get(ptr);
    CHECK_RES(env, iter);

    if (iter == NULL) {
        return enif_make_badarg(env);
    }


    text = (UChar*) in.data;

    ubrk_setText(iter, text, TO_ULEN(in.size), &status);
    CHECK(env, status);
    
    tail = enif_make_list(env, 0);
    pos = (int) ubrk_last(iter);

    while (pos) {
        last = pos;
        is_valid = is_valid_elem(ptr, iter);

        /* get the next elem. */
        pos = (int) ubrk_previous(iter);

        if (pos == UBRK_DONE)
            pos = 0;

        if (is_valid) /* Is the old element valid? */
        {
            len = FROM_ULEN(last - pos);

            bin = (UChar*) enif_make_new_binary(env, len, &head);
            memcpy(bin, 
                (const char*) (text + pos), 
                len);
            tail = enif_make_list_cell(env, head, tail);
        }
    };

    return tail;
}
开发者ID:alepharchives,项目名称:i18n,代码行数:60,代码来源:i18n_string.cpp

示例11: geef_reflog_read

ERL_NIF_TERM
geef_reflog_read(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	git_reflog *reflog;
	geef_repository *repo;
	ErlNifBinary bin;
	int error;
	size_t count, i;
	ERL_NIF_TERM list;

	if (!enif_get_resource(env, argv[0], geef_repository_type, (void **) &repo))
		return enif_make_badarg(env);

	if (!enif_inspect_iolist_as_binary(env, argv[1], &bin))
		return enif_make_badarg(env);

	if (!geef_terminate_binary(&bin))
		return geef_oom(env);

	if ((error = git_reflog_read(&reflog, repo->repo, (char *)bin.data)) < 0)
		return geef_error(env);

	count = git_reflog_entrycount(reflog);
	list = enif_make_list(env, 0);

	for (i = count; i > 0; i--) {
		ErlNifBinary id_old, id_new, message;
		ERL_NIF_TERM tentry, name, email, time, offset;
		const git_reflog_entry *entry;

		entry = git_reflog_entry_byindex(reflog, i-1);

		if (geef_oid_bin(&id_old, git_reflog_entry_id_old(entry)))
			goto on_oom;

		if (geef_oid_bin(&id_new, git_reflog_entry_id_new(entry)))
			goto on_oom;

		if (geef_signature_to_erl(&name, &email, &time, &offset,
					  env, git_reflog_entry_committer(entry)))
			goto on_oom;

		if (geef_string_to_bin(&message, git_reflog_entry_message(entry)))
			goto on_oom;

		tentry = enif_make_tuple7(env, name, email, time, offset,
					  enif_make_binary(env, &id_old),
					  enif_make_binary(env, &id_new),
					  enif_make_binary(env, &message));
		list = enif_make_list_cell(env, tentry, list);
	}

	git_reflog_free(reflog);
	return enif_make_tuple2(env, atoms.ok, list);

on_oom:
	git_reflog_free(reflog);
	return geef_oom(env);
}
开发者ID:CODECOMMUNITY,项目名称:geef,代码行数:59,代码来源:reflog.c

示例12: test_list_element_error

static ERL_NIF_TERM test_list_element_error(ErlNifEnv* env, int /*argc*/, 
    const ERL_NIF_TERM /*argv*/[])
{
    ERL_NIF_TERM list;

    list = enif_make_list(env, 0);
    ERROR_ELEMENT(env, U_INTERNAL_PROGRAM_ERROR, list, 1);
}
开发者ID:alepharchives,项目名称:i18n,代码行数:8,代码来源:i18n_nif.cpp

示例13: test_list_element_error

static ERL_NIF_TERM test_list_element_error(ErlNifEnv* env, int /*argc*/, 
    const ERL_NIF_TERM /*argv*/[])
{
    ERL_NIF_TERM list;

    list = enif_make_list(env, 0);
    return list_element_error(env, list, 1);
}
开发者ID:djui,项目名称:i18n,代码行数:8,代码来源:i18n_nif.cpp

示例14: x_cluster_stat

ERL_NIF_TERM x_cluster_stat(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    const char * func_name = "x_cluster_stat()";

    uint64_t id;
    if (!enif_get_uint64(env, argv[0], &id))
    {
        logger.error(MOD_NAME, func_name, "enif get params failed");
        return enif_make_badarg(env);
    }

    logger.debug(MOD_NAME, func_name, "cluster : %ld", id);

    rados_t cluster = map_cluster_get(id);
    if (cluster == NULL)
    {
        logger.error(MOD_NAME, func_name, "cluster non-existing : %ld", id);
        return enif_make_badarg(env);
    }

    rados_cluster_stat_t stat;
    int err = rados_cluster_stat(cluster, &stat);
    if (err < 0)
    {
        logger.error(MOD_NAME, func_name, "failed to get stat for %ld: %s", id, strerror(-err));
        return make_error_tuple(env, -err);
    }

    ERL_NIF_TERM term_list = enif_make_list(env, 0);
    ERL_NIF_TERM t = enif_make_uint64(env, stat.num_objects);
    term_list = enif_make_list_cell(env,
                                    enif_make_tuple2(env,
                                                     enif_make_atom(env, "num_objects"),
                                                     t),
                                    term_list);
    t = enif_make_uint64(env, stat.kb_avail);
    term_list = enif_make_list_cell(env,
                                    enif_make_tuple2(env,
                                                     enif_make_atom(env, "kb_avail"),
                                                     t),
                                    term_list);
    t = enif_make_uint64(env, stat.kb_used);
    term_list = enif_make_list_cell(env,
                                    enif_make_tuple2(env,
                                                     enif_make_atom(env, "kb_used"),
                                                     t),
                                    term_list);
    t = enif_make_uint64(env, stat.kb);
    term_list = enif_make_list_cell(env,
                                    enif_make_tuple2(env,
                                                     enif_make_atom(env, "kb"),
                                                     t),
                                    term_list);

    return enif_make_tuple2(env,
                            enif_make_atom(env, "ok"),
                            term_list);
}
开发者ID:amimimor,项目名称:cephelix,代码行数:58,代码来源:rados_cluster.cpp

示例15: i18n_info

static ERL_NIF_TERM i18n_info(ErlNifEnv* env, int /*argc*/, 
    const ERL_NIF_TERM /*argv*/[])
{

#if I18N_INFO
    ERL_NIF_TERM head, tail;
    tail = enif_make_list(env, 0);

    #if I18N_SEARCH
        head = enif_make_tuple2(env, ATOM_SEARCH, i18n_search_info(env));
        tail = enif_make_list_cell(env, head, tail);
    #endif

    return tail;
#else
    return enif_make_list(env, 0);
#endif
}
开发者ID:djui,项目名称:i18n,代码行数:18,代码来源:i18n_nif.cpp


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