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


C++ enif_get_list_cell函数代码示例

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


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

示例1: eterm_to_geom_polygon

GEOSGeometry*
eterm_to_geom_polygon(ErlNifEnv *env, const ERL_NIF_TERM *eterm)
{
    ERL_NIF_TERM outer_eterm, inner_eterm, tail;
    unsigned int rings_num, i;
    GEOSCoordSequence *outer_seq, *inner_seq;
    GEOSGeometry *outer_geom, *geom;
    GEOSGeometry **geoms;

    enif_get_list_length(env, *eterm, &rings_num);
    enif_get_list_cell(env, *eterm, &outer_eterm, &inner_eterm);
    outer_seq = eterm_to_geom_linestring_coords(env, &outer_eterm);
    outer_geom = GEOSGeom_createLinearRing(outer_seq);

    // if there are holes
    geoms = malloc(sizeof(GEOSGeometry*)*rings_num-1);
    for (i=0; enif_get_list_cell(env, inner_eterm, &inner_eterm, &tail); i++) {
        inner_seq = eterm_to_geom_linestring_coords(env, &inner_eterm);
        geoms[i] = GEOSGeom_createLinearRing(inner_seq);
        inner_eterm = tail;
    }
    geom = GEOSGeom_createPolygon(outer_geom, geoms, rings_num-1);
    free(geoms);
    return geom;
}
开发者ID:gleber,项目名称:erlgeom,代码行数:25,代码来源:erlgeom.c

示例2: compare_lists

int
compare_lists(int depth, couch_ejson_ctx_t* ctx, ERL_NIF_TERM a, ERL_NIF_TERM b)
{
    ERL_NIF_TERM headA, tailA;
    ERL_NIF_TERM headB, tailB;
    int aIsEmpty, bIsEmpty;
    int result;

    while (1) {
        aIsEmpty = !enif_get_list_cell(ctx->env, a, &headA, &tailA);
        bIsEmpty = !enif_get_list_cell(ctx->env, b, &headB, &tailB);

        if (aIsEmpty) {
            if (bIsEmpty) {
                return 0;
            }
            return -1;
        }

        if (bIsEmpty) {
            return 1;
        }

        result = less_ejson(depth + 1, ctx, headA, headB);

        if (ctx->error || result != 0) {
            return result;
        }

        a = tailA;
        b = tailB;
    }

    return result;
}
开发者ID:aatwgen,项目名称:couchdb,代码行数:35,代码来源:couch_ejson_compare.c

示例3: set_GEOSCoordSeq_from_eterm_list

/* Currently support for 2 dimensions only */
int
set_GEOSCoordSeq_from_eterm_list(GEOSCoordSequence *seq, int pos,
        ErlNifEnv *env, const ERL_NIF_TERM *coords) {
    double dbl_coord;
    int int_coord;
    ERL_NIF_TERM head, tail;

    if (enif_get_list_cell(env, *coords, &head, &tail)) {
        if (enif_get_int(env, head, &int_coord)) {
            dbl_coord = int_coord;
        }
        else if (!enif_get_double(env, head, &dbl_coord)) {
            return 0;
        }
        GEOSCoordSeq_setX(seq, pos, dbl_coord);

        enif_get_list_cell(env, tail, &head, &tail);
        if (enif_get_int(env, head, &int_coord)) {
            dbl_coord = int_coord;
        }
        else if (!enif_get_double(env, head, &dbl_coord)) {
            return 0;
        }
        GEOSCoordSeq_setY(seq, pos, dbl_coord);
        return 1;
    }
    return 0;
}
开发者ID:gleber,项目名称:erlgeom,代码行数:29,代码来源:erlgeom.c

示例4: dh_compute_key_nif

ERL_NIF_TERM dh_compute_key_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{/* (OthersPublicKey, MyPrivateKey, DHParams=[P,G]) */
    BIGNUM *other_pub_key = NULL,
        *dh_p = NULL,
        *dh_g = NULL;
    DH *dh_priv = DH_new();

    /* Check the arguments and get
          my private key (dh_priv),
          the peer's public key (other_pub_key),
          the parameters p & q
    */

    {
        BIGNUM *dummy_pub_key = NULL,
               *priv_key = NULL;
        ERL_NIF_TERM head, tail;

        if (!get_bn_from_bin(env, argv[0], &other_pub_key)
            || !get_bn_from_bin(env, argv[1], &priv_key)
            || !enif_get_list_cell(env, argv[2], &head, &tail)
            || !get_bn_from_bin(env, head, &dh_p)
            || !enif_get_list_cell(env, tail, &head, &tail)
            || !get_bn_from_bin(env, head, &dh_g)
            || !enif_is_empty_list(env, tail)

            /* Note: DH_set0_key() does not allow setting only the
             * private key, although DH_compute_key() does not use the
             * public key. Work around this limitation by setting
             * the public key to a copy of the private key.
             */
            || !(dummy_pub_key = BN_dup(priv_key))
            || !DH_set0_key(dh_priv, dummy_pub_key, priv_key)
            || !DH_set0_pqg(dh_priv, dh_p, NULL, dh_g)
            ) {
            if (dh_p) BN_free(dh_p);
            if (dh_g) BN_free(dh_g);
            if (other_pub_key) BN_free(other_pub_key);
            if (dummy_pub_key) BN_free(dummy_pub_key);
            if (priv_key) BN_free(priv_key);
            return enif_make_badarg(env);
        }
    }
    {
        ErlNifBinary ret_bin;
        int size;

        enif_alloc_binary(DH_size(dh_priv), &ret_bin);
        size = DH_compute_key(ret_bin.data, other_pub_key, dh_priv);
        BN_free(other_pub_key);
        DH_free(dh_priv);
        if (size<=0) {
            enif_release_binary(&ret_bin);
            return atom_error;
        }

        if (size != ret_bin.size) enif_realloc_binary(&ret_bin, size);
        return enif_make_binary(env, &ret_bin);
    }
}
开发者ID:KennethL,项目名称:otp,代码行数:60,代码来源:dh.c

示例5: x509_parse_subject

static int x509_parse_subject(ErlNifEnv* env, ERL_NIF_TERM subject_tuple, int *num_subject_entries, x509_subject_entry **subject_entries){
  int num_subject_tuple;
  unsigned num_subject_terms;
  ERL_NIF_TERM head, tail;
  int pair_arity;
  char *name;
  char *value;
  char *subject_string = NULL;
  const ERL_NIF_TERM* pair;
  int idx;
  x509_subject_entry* se;
  unsigned value_len;
  const ERL_NIF_TERM* subject_terms;

  *subject_entries = NULL;
  *num_subject_entries = 0;

  /* make sure this is a tuple with first term 'subject' */
  if(!enif_get_tuple(env, subject_tuple, &num_subject_tuple, &subject_terms) ||
     !atom_to_string(env, subject_terms[0], &subject_string) ||
     strncmp(subject_string, SUBJECT_STR, subject_strlen)) {
    if(subject_string) free(subject_string);
    return 0;
  }
  free(subject_string);

  /* create room for the x509_subject_entry structs */
  if(!enif_get_list_length(env, subject_terms[1], &num_subject_terms) || 
     (NULL == (se = (x509_subject_entry*)malloc(num_subject_terms * sizeof(x509_subject_entry))))) return 0;

  /* get the first entry and prime the pump for walking the rest */
  if(!enif_get_list_cell(env, subject_terms[1], &head, &tail) || 
     !enif_get_tuple(env, head, &pair_arity, &pair) ||
     pair_arity!=2) { return 0; }

  for(idx=0; idx<num_subject_terms; idx++){
    atom_to_string(env, pair[0], &name);

    enif_get_list_length(env, pair[1], &value_len);
    value = (char*)malloc(value_len+1);
    enif_get_string(env, pair[1], value, value_len+1, ERL_NIF_LATIN1);
    (se+idx)->name = name;
    (se+idx)->value = value;

    if(!enif_get_list_cell(env, tail, &head, &tail) || 
       !enif_get_tuple(env, head, &pair_arity, &pair) ||
       pair_arity!=2) { break; }
  }

  *num_subject_entries = num_subject_terms;
  *subject_entries = se;
  return 1;
}
开发者ID:chef,项目名称:chef_certgen,代码行数:53,代码来源:chef_certgen.c

示例6: pynerl_term_to_obj

// convert an erlang term to a python object
// return None if the type can't be converted
static PyObject* pynerl_term_to_obj(ErlNifEnv* env, ERL_NIF_TERM term) {
	int vint;
	Py_ssize_t arity, i;
	long int vlong;
	double vdouble;
	char buff[BUFF_SIZE];
	PyObject* obj;
	ERL_NIF_TERM list, head, tail;
	const ERL_NIF_TERM *terms;

	// TODO: add more types
	if (enif_get_long(env, term, &vlong)) {
		obj = PyLong_FromLong(vlong);
	}
	else if (enif_get_double(env, term, &vdouble)) {
		obj = PyFloat_FromDouble(vlong);
	}
	else if (enif_is_empty_list(env, term)) {
		obj = PyList_New(0);
	}
	else if (enif_get_tuple(env, term, &vint, &terms)) {
		arity = vint;
		obj = PyTuple_New(arity);

		for (i = 0; i < arity; i++) {
			PyTuple_SetItem(obj, i, pynerl_term_to_obj(env, terms[(int)i]));
		}
	}
	else if (enif_is_identical(term, enif_make_atom(env, "true"))) {
		obj = Py_True;
	}
	else if (enif_is_identical(term, enif_make_atom(env, "false"))) {
		obj = Py_False;
	}
	else if (enif_get_string(env, term, buff, BUFF_SIZE, ERL_NIF_LATIN1)) {
		obj = PyUnicode_FromString(buff);
	}
	else if (enif_get_list_cell(env, term, &head, &tail)) {
		obj = PyList_New(0);
		list = term;

		while (enif_get_list_cell(env, list, &head, &tail)) {
			PyList_Append(obj, pynerl_term_to_obj(env, head));
			list = tail;
		}
	}
	else {
		obj = Py_None;
	}

	return obj;
}
开发者ID:marianoguerra,项目名称:pynerl,代码行数:54,代码来源:pynerl.c

示例7: to_js_object

jsval
to_js_object(ErlNifEnv* env, JSContext* cx, ERL_NIF_TERM list)
{
    JSObject* ret;
    jsval kval;
    jsval vval;
    jsid idp;
    ERL_NIF_TERM head;
    ERL_NIF_TERM tail;
    const ERL_NIF_TERM* pair;
    int arity;

    ret = JS_NewObject(cx, NULL, NULL, NULL);
    if(ret == NULL) return JSVAL_VOID;
    
    if(enif_is_empty_list(env, list))
    {
        return OBJECT_TO_JSVAL(ret);
    }

    if(!enif_get_list_cell(env, list, &head, &tail))
    {
        return JSVAL_VOID;
    }

    do {
        if(!enif_get_tuple(env, head, &arity, &pair))
        {
            return JSVAL_VOID;
        }
        
        if(arity != 2)
        {
            return JSVAL_VOID;
        }
        
        kval = to_js_key(env, cx, pair[0]);
        if(kval == JSVAL_VOID) return JSVAL_VOID;
        if(!JS_ValueToId(cx, kval, &idp)) return JSVAL_VOID;
        vval = to_js(env, cx, pair[1]);
        if(vval == JSVAL_VOID) return JSVAL_VOID;
        
        if(!JS_SetPropertyById(cx, ret, idp, &vval))
        {
            return JSVAL_VOID;
        }
    } while(enif_get_list_cell(env, tail, &head, &tail));
    
    return OBJECT_TO_JSVAL(ret);
}
开发者ID:alepharchives,项目名称:iErl,代码行数:50,代码来源:to_js.c

示例8: cb_mtouch_args

void* cb_mtouch_args(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    mtouch_args_t* args = (mtouch_args_t*)enif_alloc(sizeof(mtouch_args_t));

    ERL_NIF_TERM* currKey;
    ERL_NIF_TERM tail;
    ErlNifBinary key_binary;

    if (!enif_get_list_length(env, argv[0], &args->numkeys)) goto error0;
    args->keys = malloc(sizeof(char*) * args->numkeys);
    args->nkeys = malloc(sizeof(size_t) * args->numkeys);
    currKey = malloc(sizeof(ERL_NIF_TERM));
    tail = argv[0];
    int i = 0;
    while(0 != enif_get_list_cell(env, tail, currKey, &tail)) {
        if (!enif_inspect_iolist_as_binary(env, *currKey, &key_binary)) goto error1;
        args->keys[i] = malloc(sizeof(char) * key_binary.size);
        memcpy(args->keys[i], key_binary.data, key_binary.size);
        args->nkeys[i] = key_binary.size;
        i++;
    }

    args->exp = malloc(sizeof(int64_t) * args->numkeys);
    tail = argv[1];
    int i2 = 0;
    while(0 != enif_get_list_cell(env, tail, currKey, &tail)) {
        if (!enif_get_long(env, *currKey, &args->exp[i2])) goto error2;
        i2++;
    }

    free(currKey);

    return (void*)args;

    int f = 0;

    error2:
    free(args->exp);
    error1:
    for(f = 0; f < i; f++) {
        free(args->keys[f]);
    }
    free(args->keys);
    free(args->nkeys);
    error0:
    enif_free(args);

    return NULL;
}
开发者ID:muut,项目名称:cberl,代码行数:49,代码来源:cb.c

示例9: zip

static ERL_NIF_TERM zip(ErlNifEnv* env, ERL_NIF_TERM list)
{
    ERL_NIF_TERM key, val, tmp1, tmp2;

    if (enif_get_list_cell(env, list, &key, &tmp1)) {
	if (enif_get_list_cell(env, tmp1, &val, &tmp2)) {
	    return enif_make_list_cell(env,
				       enif_make_tuple2(env, key, val),
				       zip(env, tmp2));
	} else {
	    return enif_make_list_cell(env, key, enif_make_list(env, 0));
	}
    } else
	return list;
}
开发者ID:jabber-at,项目名称:p1_yaml,代码行数:15,代码来源:fast_yaml.c

示例10: do_bind

static ERL_NIF_TERM
do_bind(ErlNifEnv *env, sqlite3 *db, sqlite3_stmt *stmt, const ERL_NIF_TERM arg)
{
    int parameter_count = sqlite3_bind_parameter_count(stmt);
    int i, is_list, r;
    ERL_NIF_TERM list, head, tail;
    unsigned int list_length;

    is_list = enif_get_list_length(env, arg, &list_length);
    if(!is_list) 
	    return make_error_tuple(env, "bad_arg_list");
    if(parameter_count != list_length) 
	    return make_error_tuple(env, "args_wrong_length");

    sqlite3_reset(stmt);
     
    list = arg;
    for(i=0; i < list_length; i++) {
	    enif_get_list_cell(env, list, &head, &tail);
	    r = bind_cell(env, head, stmt, i+1);
	    if(r == -1) 
	        return make_error_tuple(env, "wrong_type");
	    if(r != SQLITE_OK)
	        return make_sqlite3_error_tuple(env, r, db);
	    list = tail;
    }
     
    return make_atom(env, "ok");
}
开发者ID:alepharchives,项目名称:esqlite,代码行数:29,代码来源:esqlite3_nif.c

示例11: atoi

char *nif_arg_list_to_string(ErlNifEnv *env, ERL_NIF_TERM list, int *arg_size)
{
    ERL_NIF_TERM head, tail;
    char str_length[PREFIX_LEN], *args;
    int i, length, character;

    for(i=0; i<PREFIX_LEN; i++) {
        if(enif_get_list_cell(env, list, &head, &tail)) {
            if(!enif_get_int(env, head, &character)) {
                return NULL;
            }
            str_length[i] = (char)character;
            list = tail;
        } else {
            return NULL;
        }
    };

    length = atoi(str_length)+1;
    args = (char *)calloc(length, sizeof(char));

    nif_list_to_string(env, list, args);
    *arg_size = length;

    return args;
};
开发者ID:bharad,项目名称:babysitter,代码行数:26,代码来源:nif_decode.c

示例12: do_load_info

static void do_load_info(ErlNifEnv* env, ERL_NIF_TERM load_info, int* retvalp)
{
    NifModPrivData* data = priv_data(env);
    ERL_NIF_TERM head, tail;
    unsigned ix;

    for (ix=0; ix<RT_MAX; ix++) {
	data->rt_arr[ix] = NULL;
    }
    for (head = load_info; enif_get_list_cell(env, head, &head, &tail);
	  head = tail) {
	const ERL_NIF_TERM* arr;
	int arity;

	CHECK(enif_get_tuple(env, head, &arity, &arr));
	switch (arity) {
	case 6:
	    open_resource_type(env, arr);
	    break;
	case 2:
	    CHECK(arr[0] == am_return);
	    CHECK(enif_get_int(env, arr[1], retvalp));
	    break;
	default:
	    CHECK(0);
	}
    }    
    CHECK(enif_is_empty_list(env, head));
}
开发者ID:0x00evil,项目名称:otp,代码行数:29,代码来源:nif_mod.c

示例13: init_parser

int init_parser(Parser* parser, ErlNifEnv* env, ERL_NIF_TERM arg, ErlNifBinary* buffer, ERL_NIF_TERM columns) {
	parser->env = env;
	parser->atoms = enif_priv_data(env);
	parser->raw = arg;
	parser->buffer = buffer->data;

	if(!enif_get_list_length(env, columns, &parser->table_width)) return 0; 

	ERL_NIF_TERM list, head, tail;
	int val, index = 0;

	parser->columns = (int *) enif_alloc(parser->table_width * sizeof(int));
	list = columns;

	while(enif_get_list_cell(env, list, &head, &tail)) {
		if (!enif_get_int(env, head, &val)) return 0;
		parser->columns[index] = val;

		index++;
		list = tail;
	}

	parser->frame_start = 0;
	parser->frame_size = 0;
	parser->buffer_size = buffer->size;

	return 1;
}
开发者ID:GWeise,项目名称:Emysql,代码行数:28,代码来源:parse.c

示例14: make_attrs

static int make_attrs(ErlNifEnv* env, struct buf *rbuf, ERL_NIF_TERM attrs)
{
  ErlNifBinary name, data;
  ERL_NIF_TERM head, tail;
  const ERL_NIF_TERM *tuple;
  int arity, ret = 1;
  
  while (enif_get_list_cell(env, attrs, &head, &tail)) {
    if (enif_get_tuple(env, head, &arity, &tuple)) {
      if (arity == 2) {
	if (enif_inspect_iolist_as_binary(env, tuple[0], &name) &&
	    enif_inspect_iolist_as_binary(env, tuple[1], &data)) {
	  buf_add_char(env, rbuf, ' ');
	  buf_add_str(env, rbuf, (char *)name.data, name.size);
	  buf_add_str(env, rbuf, "='", 2);
	  crypt(env, rbuf, data.data, data.size);
	  buf_add_char(env, rbuf, '\'');
	  attrs = tail;
	} else {
	  ret = 0;
	  break;
	};
      } else {
	ret = 0;
	break;
      };
    } else {
      ret = 0;
      break;
    };
  };
  
  return ret;
}
开发者ID:James1133,项目名称:ejabberd,代码行数:34,代码来源:xml.c

示例15: decode_flags

int decode_flags(ErlNifEnv* env, ERL_NIF_TERM list, int *prot, int *flags, bool *direct, bool *lock)
{
  bool l = true;
  bool d = false;
  int f = MAP_FILE;
  int p = 0;
  ERL_NIF_TERM head;
  while (enif_get_list_cell(env, list, &head, &list)) {

    if (enif_is_identical(head, ATOM_READ)) {
      p |= PROT_READ;
    } else if (enif_is_identical(head, ATOM_DIRECT)) {
      d = true;
    } else if (enif_is_identical(head, ATOM_LOCK)) {
      l = true;
    } else if (enif_is_identical(head, ATOM_NOLOCK)) {
      l = false;
    } else if (enif_is_identical(head, ATOM_WRITE)) {
      p |= PROT_WRITE;
//    } else if (enif_is_identical(head, ATOM_NONE)) {
//    p |= PROT_NONE;

    } else if (enif_is_identical(head, ATOM_PRIVATE)) {
      f |= MAP_PRIVATE;
    } else if (enif_is_identical(head, ATOM_SHARED)) {
      f |= MAP_SHARED;
//  } else if (enif_is_identical(head, ATOM_ANON)) {
//    f |= MAP_ANON;
//  } else if (enif_is_identical(head, ATOM_FILE)) {
//    f |= MAP_FILE;
//  } else if (enif_is_identical(head, ATOM_FIXED)) {
//    f |= MAP_FIXED;
    } else if (enif_is_identical(head, ATOM_NOCACHE)) {
      f |= MAP_NOCACHE;

    } else {
      return 0;
    }
  }

  // direct cannot be write
  if (d & ((p & PROT_WRITE) != 0))
    return 0;

  // default to private
  if ((f & (MAP_SHARED|MAP_PRIVATE)) == 0)
    f |= MAP_PRIVATE;

  // default to read-only
  if ((p & (PROT_READ|PROT_WRITE)) == 0)
    p |= PROT_READ;

  *flags = f;
  *prot = p;
  *direct = d;
  *lock = l;

  return 1;
}
开发者ID:alepharchives,项目名称:emmap,代码行数:59,代码来源:emmap.cpp


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