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

C++ NUM2INT函数代码示例

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

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



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

示例1: rb_proc_arity

int rb_proc_arity(VALUE self)
{
  return (int)NUM2INT(rb_funcall(self, rb_intern("arity"), 0));
}
开发者ID:Accusedbold,项目名称:shoes,代码行数:4,代码来源:database.c


示例2: t_set_rlimit_nofile

static VALUE t_set_rlimit_nofile (VALUE self, VALUE arg)
{
	arg = (NIL_P(arg)) ? -1 : NUM2INT (arg);
	return INT2NUM (evma_set_rlimit_nofile (arg));
}
开发者ID:jochemsiegel,项目名称:eventmachine,代码行数:5,代码来源:rubymain.cpp


示例3: rg_s_keyboard_grab

static VALUE
rg_s_keyboard_grab(G_GNUC_UNUSED VALUE self, VALUE win, VALUE owner_events, VALUE time)
{
    return GDKGRABSTATUS2RVAL(gdk_keyboard_grab(RVAL2GDKWINDOW(win),
                                                RVAL2CBOOL(owner_events), NUM2INT(time)));
}
开发者ID:fukuchi,项目名称:ruby-gnome2,代码行数:6,代码来源:rbgdk.c


示例4: rg_set_spacing

static VALUE
rg_set_spacing(VALUE self, VALUE spacing)
{
    pango_layout_set_spacing(_SELF(self), NUM2INT(spacing));
    return self;
}
开发者ID:Vasfed,项目名称:ruby-gnome2,代码行数:6,代码来源:rbpangolayout.c


示例5: bind_param

/* call-seq: stmt.bind_param(key, value)
 *
 * Binds value to the named (or positional) placeholder. If +param+ is a
 * Fixnum, it is treated as an index for a positional placeholder.
 * Otherwise it is used as the name of the placeholder to bind to.
 *
 * See also #bind_params.
 */
static VALUE bind_param(VALUE self, VALUE key, VALUE value)
{
  sqlite3StmtRubyPtr ctx;
  int status;
  int index;

  Data_Get_Struct(self, sqlite3StmtRuby, ctx);
  REQUIRE_OPEN_STMT(ctx);

  switch(TYPE(key)) {
    case T_SYMBOL:
      key = rb_funcall(key, rb_intern("to_s"), 0);
    case T_STRING:
      if(RSTRING_PTR(key)[0] != ':') key = rb_str_plus(rb_str_new2(":"), key);
      index = sqlite3_bind_parameter_index(ctx->st, StringValuePtr(key));
      break;
    default:
      index = (int)NUM2INT(key);
  }

  if(index == 0)
    rb_raise(rb_path2class("SQLite3::Exception"), "no such bind parameter");

  switch(TYPE(value)) {
    case T_STRING:
      if(CLASS_OF(value) == cSqlite3Blob
#ifdef HAVE_RUBY_ENCODING_H
              || rb_enc_get_index(value) == rb_ascii8bit_encindex()
#endif
        ) {
        status = sqlite3_bind_blob(
            ctx->st,
            index,
            (const char *)StringValuePtr(value),
            (int)RSTRING_LEN(value),
            SQLITE_TRANSIENT
            );
      } else {
#ifdef HAVE_RUBY_ENCODING_H
        if(!UTF8_P(value)) {
              VALUE db          = rb_iv_get(self, "@connection");
              VALUE encoding    = rb_funcall(db, rb_intern("encoding"), 0);
              rb_encoding * enc = rb_to_encoding(encoding);
              value = rb_str_export_to_enc(value, enc);
          }
#endif

        status = sqlite3_bind_text(
            ctx->st,
            index,
            (const char *)StringValuePtr(value),
            (int)RSTRING_LEN(value),
            SQLITE_TRANSIENT
            );
      }
      break;
    case T_BIGNUM:
#if SIZEOF_LONG < 8
      if (RBIGNUM_LEN(value) * SIZEOF_BDIGITS <= 8) {
          status = sqlite3_bind_int64(ctx->st, index, (sqlite3_int64)NUM2LL(value));
          break;
      }
#endif
    case T_FLOAT:
      status = sqlite3_bind_double(ctx->st, index, NUM2DBL(value));
      break;
    case T_FIXNUM:
      status = sqlite3_bind_int64(ctx->st, index, (sqlite3_int64)FIX2LONG(value));
      break;
    case T_NIL:
      status = sqlite3_bind_null(ctx->st, index);
      break;
    default:
      rb_raise(rb_eRuntimeError, "can't prepare %s",
          rb_class2name(CLASS_OF(value)));
      break;
  }

  CHECK(sqlite3_db_handle(ctx->st), status);

  return self;
}
开发者ID:kashif,项目名称:sqlite3-ruby,代码行数:90,代码来源:statement.c


示例6: weechat_ruby_exec

void *
weechat_ruby_exec (struct t_plugin_script *script,
                   int ret_type, const char *function,
                   const char *format, void **argv)
{
    VALUE rc, err;
    int ruby_error, i, argc, *ret_i;
    VALUE argv2[16];
    void *ret_value;
    struct t_plugin_script *old_ruby_current_script;

    old_ruby_current_script = ruby_current_script;
    ruby_current_script = script;

    argc = 0;
    if (format && format[0])
    {
        argc = strlen (format);
        for (i = 0; i < argc; i++)
        {
            switch (format[i])
            {
                case 's': /* string */
                    argv2[i] = rb_str_new2 ((char *)argv[i]);
                    break;
                case 'i': /* integer */
                    argv2[i] = INT2FIX (*((int *)argv[i]));
                    break;
                case 'h': /* hash */
                    argv2[i] = weechat_ruby_hashtable_to_hash (argv[i]);
                    break;
            }
        }
    }

    if (argc > 0)
    {
        rc = rb_protect_funcall ((VALUE) script->interpreter,
                                 rb_intern(function),
                                 &ruby_error, argc, argv2);
    }
    else
    {
        rc = rb_protect_funcall ((VALUE) script->interpreter,
                                 rb_intern(function),
                                 &ruby_error, 0, NULL);
    }

    if (ruby_error)
    {
        weechat_printf (NULL,
                        weechat_gettext ("%s%s: unable to run function \"%s\""),
                        weechat_prefix ("error"), RUBY_PLUGIN_NAME, function);

        err = rb_gv_get("$!");
        weechat_ruby_print_exception(err);

        return NULL;
    }

    if ((TYPE(rc) == T_STRING) && (ret_type == WEECHAT_SCRIPT_EXEC_STRING))
    {
        if (StringValuePtr (rc))
            ret_value = strdup (StringValuePtr (rc));
        else
            ret_value = NULL;
    }
    else if ((TYPE(rc) == T_FIXNUM) && (ret_type == WEECHAT_SCRIPT_EXEC_INT))
    {
        ret_i = malloc (sizeof (*ret_i));
        if (ret_i)
            *ret_i = NUM2INT(rc);
        ret_value = ret_i;
    }
    else if (ret_type == WEECHAT_SCRIPT_EXEC_HASHTABLE)
    {
        ret_value = weechat_ruby_hash_to_hashtable (rc,
                                                    WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
                                                    WEECHAT_HASHTABLE_STRING,
                                                    WEECHAT_HASHTABLE_STRING);
    }
    else
    {
        weechat_printf (NULL,
                        weechat_gettext ("%s%s: function \"%s\" must return a "
                                         "valid value"),
                        weechat_prefix ("error"), RUBY_PLUGIN_NAME, function);
        ruby_current_script = old_ruby_current_script;
        return WEECHAT_RC_OK;
    }

    if (ret_value == NULL)
    {
        weechat_printf (NULL,
                        weechat_gettext ("%s%s: not enough memory in function "
                                         "\"%s\""),
                        weechat_prefix ("error"), RUBY_PLUGIN_NAME, function);
        ruby_current_script = old_ruby_current_script;
        return NULL;
    }
//.........这里部分代码省略.........
开发者ID:sardemff7,项目名称:weechat,代码行数:101,代码来源:weechat-ruby.c


示例7: rg_set_height

static VALUE
rg_set_height(VALUE self, VALUE width)
{
    pango_layout_set_height(_SELF(self), NUM2INT(width));
    return self;
}
开发者ID:Vasfed,项目名称:ruby-gnome2,代码行数:6,代码来源:rbpangolayout.c


示例8: method_set_mouse_rel

VALUE method_set_mouse_rel(VALUE self, VALUE x, VALUE y){
  XTestFakeRelativeMotionEvent(display, NUM2INT(x), NUM2INT(y), 0);
  XSync(display, 1);
}
开发者ID:nbartlomiej,项目名称:touchkey,代码行数:4,代码来源:CMouse.c


示例9: method_set_mouse_abs

VALUE method_set_mouse_abs(VALUE self, VALUE x, VALUE y){
  // XWarpPointer(display, None, None, 0, 0, 0, 0, NUM2INT(x), NUM2INT(y));
  XTestFakeMotionEvent(display, screen, NUM2INT(x), NUM2INT(y), 0);
  XSync(display, 1);
}
开发者ID:nbartlomiej,项目名称:touchkey,代码行数:5,代码来源:CMouse.c


示例10: ossl_asn1_get_asn1type

ASN1_TYPE*
ossl_asn1_get_asn1type(VALUE obj)
{
    ASN1_TYPE *ret;
    VALUE value, rflag;
    void *ptr;
    void (*free_func)();
    long tag, flag;

    tag = ossl_asn1_default_tag(obj);
    value = ossl_asn1_get_value(obj);
    switch(tag){
    case V_ASN1_BOOLEAN:
	ptr = (void*)(VALUE)obj_to_asn1bool(value);
	free_func = NULL;
	break;
    case V_ASN1_INTEGER:         /* FALLTHROUGH */
    case V_ASN1_ENUMERATED:
	ptr = obj_to_asn1int(value);
	free_func = ASN1_INTEGER_free;
	break;
    case V_ASN1_BIT_STRING:
        rflag = rb_attr_get(obj, rb_intern("@unused_bits"));
        flag = NIL_P(rflag) ? -1 : NUM2INT(rflag);
	ptr = obj_to_asn1bstr(value, flag);
	free_func = ASN1_BIT_STRING_free;
	break;
    case V_ASN1_NULL:
	ptr = obj_to_asn1null(value);
	free_func = ASN1_NULL_free;
	break;
    case V_ASN1_OCTET_STRING:    /* FALLTHROUGH */
    case V_ASN1_UTF8STRING:      /* FALLTHROUGH */
    case V_ASN1_NUMERICSTRING:   /* FALLTHROUGH */
    case V_ASN1_PRINTABLESTRING: /* FALLTHROUGH */
    case V_ASN1_T61STRING:       /* FALLTHROUGH */
    case V_ASN1_VIDEOTEXSTRING:  /* FALLTHROUGH */
    case V_ASN1_IA5STRING:       /* FALLTHROUGH */
    case V_ASN1_GRAPHICSTRING:   /* FALLTHROUGH */
    case V_ASN1_ISO64STRING:     /* FALLTHROUGH */
    case V_ASN1_GENERALSTRING:   /* FALLTHROUGH */
    case V_ASN1_UNIVERSALSTRING: /* FALLTHROUGH */
    case V_ASN1_BMPSTRING:   
	ptr = obj_to_asn1str(value);
	free_func = ASN1_STRING_free;
	break;
    case V_ASN1_OBJECT:
	ptr = obj_to_asn1obj(value);
	free_func = ASN1_OBJECT_free;
	break;
    case V_ASN1_UTCTIME:
	ptr = obj_to_asn1utime(value);
	free_func = ASN1_TIME_free;
	break;
    case V_ASN1_GENERALIZEDTIME:
	ptr = obj_to_asn1gtime(value);
	free_func = ASN1_TIME_free;
	break;
    case V_ASN1_SET:             /* FALLTHROUGH */
    case V_ASN1_SEQUENCE:
	ptr = obj_to_asn1derstr(obj);
	free_func = ASN1_STRING_free;
	break;
    default:
	ossl_raise(eASN1Error, "unsupported ASN.1 type");
    }
    if(!(ret = OPENSSL_malloc(sizeof(ASN1_TYPE)))){
	if(free_func) free_func(ptr);
	ossl_raise(eASN1Error, "ASN1_TYPE alloc failure");
    }
    memset(ret, 0, sizeof(ASN1_TYPE));
    ASN1_TYPE_set(ret, tag, ptr);

    return ret;
}
开发者ID:AdamDotCom,项目名称:my-rvm,代码行数:75,代码来源:ossl_asn1.c


示例11: grpc_rb_time_timeval

/**
 * grpc_rb_time_timeval creates a timeval from a ruby time object.
 *
 * This func is copied from ruby source, MRI/source/time.c, which is published
 * under the same license as the ruby.h, on which the entire extensions is
 * based.
 */
gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) {
    gpr_timespec t;
    gpr_timespec *time_const;
    const char *tstr = interval ? "time interval" : "time";
    const char *want = " want <secs from epoch>|<Time>|<GRPC::TimeConst.*>";

    t.clock_type = GPR_CLOCK_REALTIME;
    switch (TYPE(time)) {
    case T_DATA:
        if (CLASS_OF(time) == grpc_rb_cTimeVal) {
            TypedData_Get_Struct(time, gpr_timespec, &grpc_rb_timespec_data_type,
                                 time_const);
            t = *time_const;
        } else if (CLASS_OF(time) == rb_cTime) {
            t.tv_sec = NUM2INT(rb_funcall(time, id_tv_sec, 0));
            t.tv_nsec = NUM2INT(rb_funcall(time, id_tv_nsec, 0));
        } else {
            rb_raise(rb_eTypeError, "bad input: (%s)->c_timeval, got <%s>,%s", tstr,
                     rb_obj_classname(time), want);
        }
        break;

    case T_FIXNUM:
        t.tv_sec = FIX2LONG(time);
        if (interval && t.tv_sec < 0)
            rb_raise(rb_eArgError, "%s must be positive", tstr);
        t.tv_nsec = 0;
        break;

    case T_FLOAT:
        if (interval && RFLOAT_VALUE(time) < 0.0)
            rb_raise(rb_eArgError, "%s must be positive", tstr);
        else {
            double f, d;

            d = modf(RFLOAT_VALUE(time), &f);
            if (d < 0) {
                d += 1;
                f -= 1;
            }
            t.tv_sec = (int64_t)f;
            if (f != t.tv_sec) {
                rb_raise(rb_eRangeError, "%f out of Time range",
                         RFLOAT_VALUE(time));
            }
            t.tv_nsec = (int)(d * 1e9 + 0.5);
        }
        break;

    case T_BIGNUM:
        t.tv_sec = NUM2LONG(time);
        if (interval && t.tv_sec < 0)
            rb_raise(rb_eArgError, "%s must be positive", tstr);
        t.tv_nsec = 0;
        break;

    default:
        rb_raise(rb_eTypeError, "bad input: (%s)->c_timeval, got <%s>,%s", tstr,
                 rb_obj_classname(time), want);
        break;
    }
    return t;
}
开发者ID:xianglinghui,项目名称:grpc,代码行数:70,代码来源:rb_grpc.c


示例12: rg_unmark_day

static VALUE
rg_unmark_day(VALUE self, VALUE day)
{
    gtk_calendar_unmark_day(_SELF(self), NUM2INT(day));
    return self;
}
开发者ID:Vasfed,项目名称:ruby-gnome2,代码行数:6,代码来源:rbgtkcalendar.c


示例13: ossl_ocspbres_add_status

static VALUE
ossl_ocspbres_add_status(VALUE self, VALUE cid, VALUE status,
			 VALUE reason, VALUE revtime,
			 VALUE thisupd, VALUE nextupd, VALUE ext)
{
    OCSP_BASICRESP *bs;
    OCSP_SINGLERESP *single;
    OCSP_CERTID *id;
    int st, rsn;
    ASN1_TIME *ths, *nxt, *rev;
    int error, i, rstatus = 0;
    VALUE tmp;

    st = NUM2INT(status);
    rsn = NIL_P(status) ? 0 : NUM2INT(reason);
    if(!NIL_P(ext)){
	/* All ary's members should be X509Extension */
	Check_Type(ext, T_ARRAY);
	for (i = 0; i < RARRAY_LEN(ext); i++)
	    OSSL_Check_Kind(RARRAY_PTR(ext)[i], cX509Ext);
    }

    error = 0;
    ths = nxt = rev = NULL;
    if(!NIL_P(revtime)){
	tmp = rb_protect(rb_Integer, revtime, &rstatus);
	if(rstatus) goto err;
	rev = X509_gmtime_adj(NULL, NUM2INT(tmp));
    }
    tmp = rb_protect(rb_Integer, thisupd, &rstatus);
    if(rstatus) goto err;
    ths = X509_gmtime_adj(NULL, NUM2INT(tmp));
    tmp = rb_protect(rb_Integer, nextupd, &rstatus);
    if(rstatus) goto err;
    nxt = X509_gmtime_adj(NULL, NUM2INT(tmp));

    GetOCSPBasicRes(self, bs);
    SafeGetOCSPCertId(cid, id);
    if(!(single = OCSP_basic_add1_status(bs, id, st, rsn, rev, ths, nxt))){
	error = 1;
	goto err;
    }

    if(!NIL_P(ext)){
	X509_EXTENSION *x509ext;
	sk_X509_EXTENSION_pop_free(single->singleExtensions, X509_EXTENSION_free);
	single->singleExtensions = NULL;
	for(i = 0; i < RARRAY_LEN(ext); i++){
	    x509ext = DupX509ExtPtr(RARRAY_PTR(ext)[i]);
	    if(!OCSP_SINGLERESP_add_ext(single, x509ext, -1)){
		X509_EXTENSION_free(x509ext);
		error = 1;
		goto err;
	    }
	    X509_EXTENSION_free(x509ext);
	}
    }

 err:
    ASN1_TIME_free(ths);
    ASN1_TIME_free(nxt);
    ASN1_TIME_free(rev);
    if(error) ossl_raise(eOCSPError, NULL);
    if(rstatus) rb_jump_tag(rstatus);

    return self;
}
开发者ID:DashYang,项目名称:sim,代码行数:67,代码来源:ossl_ocsp.c


示例14: ImageList_quantize

/*
    Method:     ImageList#quantize(<number_colors<, colorspace<, dither<, tree_depth<, measure_error>>>>>)
                     defaults: 256, Magick::RGBColorspace, true, 0, false
    Purpose:    call QuantizeImages
    Returns:    a new ImageList with quantized images. 'scene' is set to the same
                value as self.scene
*/
VALUE
ImageList_quantize(int argc, VALUE *argv, VALUE self)
{
    Image *images, *new_images;
    Image *new_image;
    QuantizeInfo quantize_info;
    ExceptionInfo exception;
    volatile VALUE new_imagelist, scene;

    GetQuantizeInfo(&quantize_info);

    switch (argc)
    {
        case 5:
            quantize_info.measure_error = (MagickBooleanType) RTEST(argv[4]);
        case 4:
            quantize_info.tree_depth = (unsigned long)NUM2INT(argv[3]);
        case 3:
            quantize_info.dither = (MagickBooleanType) RTEST(argv[2]);
        case 2:
            VALUE_TO_ENUM(argv[1], quantize_info.colorspace, ColorspaceType);
        case 1:
            quantize_info.number_colors = NUM2ULONG(argv[0]);
        case 0:
            break;
        default:
            rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 5)", argc);
            break;
    }

    if (imagelist_length(self) == 0L)
    {
        rb_raise(rb_eArgError, "no images in this image list");
    }

    // Convert image array to image sequence, clone image sequence.
    GetExceptionInfo(&exception);
    images = images_from_imagelist(self);
    new_images = CloneImageList(images, &exception);
    rm_split(images);
    rm_check_exception(&exception, new_images, DestroyOnError);
    (void) DestroyExceptionInfo(&exception);

    rm_ensure_result(new_images);


    (void) QuantizeImages(&quantize_info, new_images);
    rm_check_exception(&exception, new_images, DestroyOnError);

    // Create new ImageList object, convert mapped image sequence to images,
    // append to images array.
    new_imagelist = ImageList_new();
    while ((new_image = ShiftImageList(&new_images)))
    {
        imagelist_push(new_imagelist, rm_image_new(new_image));
    }

    // Set @scene in new ImageList object to same value as in self.
    scene = rb_iv_get(self, "@scene");
    (void) rb_iv_set(new_imagelist, "@scene", scene);

    return new_imagelist;
}
开发者ID:Flagship8787,项目名称:Suwaru-Rails,代码行数:70,代码来源:rmilist.c


示例15: rg_reparent

static VALUE
rg_reparent(VALUE self, VALUE new_parent, VALUE x, VALUE y)
{
    gdk_window_reparent(_SELF(self), _SELF(new_parent), NUM2INT(x), NUM2INT(y));
    return self;
}
开发者ID:Vasfed,项目名称:ruby-gnome2,代码行数:6,代码来源:rbgdkwindow.c


示例16: rb_cogl_texture_max_waste_param

static gint
rb_cogl_texture_max_waste_param (VALUE value)
{
  return NIL_P (value) ? 64 : NUM2INT (value);
}
开发者ID:orospakr,项目名称:rbclutter,代码行数:5,代码来源:rbcogltexture.c


示例17: sfcc_value_to_cimdata

CIMCData sfcc_value_to_cimdata(VALUE value)
{
  CIMCData data;
  memset(&data, 0, sizeof(CIMCData));
  data.state = CIMC_goodValue;
  data.type = CIMC_null;

  switch (TYPE(value))
  {
  case T_NIL:
    data.type = CIMC_null;
    data.state = CIMC_nullValue;
    break;
  case T_STRING:
    data.type = CIMC_string;
    data.value.string = cimcEnv->ft->newString(cimcEnv, to_charptr(value), NULL);
    break;
  case T_TRUE:
    data.type = CIMC_boolean;
    data.value.boolean = 1;
    break;
  case T_FALSE:
    data.type = CIMC_boolean;
    data.value.boolean = 0;
    break;
  case T_FIXNUM:
    data.type = CIMC_sint64;
    data.value.Long = NUM2INT(value);
    break;
  case T_FLOAT:
    data.type = CIMC_real64;
    data.value.real64 = NUM2DBL(value);
    break;
  case T_BIGNUM:
    data.type = CIMC_sint64;
    data.value.Long = NUM2LL(value);
    break;
/* not yet supported
  case T_HASH:
    break;
  case T_SYMBOL:
    */
  case T_ARRAY: {
    data.value.array = sfcc_rubyarray_to_cimcarray(value, &data.type);
    if (!data.value.array) {
      data.state = CIMC_badValue;
    }
    break;
  }
  case T_DATA:
  default:
    if (CLASS_OF(value) == cSfccCimString) {
      Data_Get_Struct(value, CIMCString, data.value.string);
      if (data.value.string == NULL) { /* packed a NULL pointer ? */
        data.type = CIMC_null;
        data.state = CIMC_nullValue;
      }
      else {
        data.type = CIMC_string;
      }
    }
    else if (CLASS_OF(value) == cSfccCimData) {
      CIMCData *tmp;
      Data_Get_Struct(value, CIMCData, tmp);
      data = *tmp;
    }
    else if(CLASS_OF(value) == cSfccCimInstance) {
      rb_sfcc_instance *obj;
      Data_Get_Struct(value, rb_sfcc_instance, obj);
      data.value.inst = obj->inst;
      if (data.value.inst == NULL) {
        data.type = CIMC_null;
        data.state = CIMC_nullValue;
      }else {
        data.type = CIMC_instance;
      }
    }
    else if(CLASS_OF(value) == cSfccCimObjectPath) {
      rb_sfcc_object_path *obj;
      Data_Get_Struct(value, rb_sfcc_object_path, obj);
      data.value.ref = obj->op;
      if (data.value.ref == NULL) {
        data.type = CIMC_null;
        data.state = CIMC_nullValue;
      }else {
        data.type = CIMC_ref;
      }
    }
    else if(CLASS_OF(value) == cSfccCimEnumeration) {
      rb_sfcc_enumeration *obj;
      Data_Get_Struct(value, rb_sfcc_enumeration, obj);
      data.value.Enum = obj->enm;
      if (data.value.Enum == NULL) {
        data.type = CIMC_null;
        data.state = CIMC_nullValue;
      }else {
        data.type = CIMC_enumeration;
      }
    }
    else if (CLASS_OF(value) == cSfccCimClass) {
//.........这里部分代码省略.........
开发者ID:miminar,项目名称:ruby-sfcc,代码行数:101,代码来源:sfcc.c


示例18: math_ldexp

static VALUE
math_ldexp(VALUE obj, VALUE x, VALUE n)
{
    return DBL2NUM(ldexp(Get_Double(x), NUM2INT(n)));
}
开发者ID:caguiatde,项目名称:songsplice,代码行数:5,代码来源:math.c


示例19: weechat_ruby_load

int
weechat_ruby_load (const char *filename)
{
    char modname[64];
    VALUE ruby_retcode, err, argv[1];
    int ruby_error;
    struct stat buf;

    if (stat (filename, &buf) != 0)
    {
        weechat_printf (NULL,
                        weechat_gettext ("%s%s: script \"%s\" not found"),
                        weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename);
        return 0;
    }

    if ((weechat_ruby_plugin->debug >= 2) || !ruby_quiet)
    {
        weechat_printf (NULL,
                        weechat_gettext ("%s: loading script \"%s\""),
                        RUBY_PLUGIN_NAME, filename);
    }

    ruby_current_script = NULL;
    ruby_registered_script = NULL;

    snprintf (modname, sizeof(modname), "%s%d", MOD_NAME_PREFIX, ruby_num);
    ruby_num++;

    ruby_current_module = rb_define_module (modname);

    ruby_current_script_filename = filename;

    argv[0] = rb_str_new2 (filename);
    ruby_retcode = rb_protect_funcall (ruby_current_module,
                                       rb_intern ("load_eval_file"),
                                       &ruby_error, 1, argv);

    if (ruby_retcode == Qnil)
    {
        err = rb_gv_get("$!");
        weechat_ruby_print_exception(err);
        return 0;
    }

    if (NUM2INT(ruby_retcode) != 0)
    {
        switch (NUM2INT(ruby_retcode))
        {
            case 1:
                weechat_printf (NULL,
                                weechat_gettext ("%s%s: unable to read file "
                                                 "\"%s\""),
                                weechat_prefix ("error"), RUBY_PLUGIN_NAME,
                                filename);
                break;
            case 2:
                weechat_printf (NULL,
                                weechat_gettext ("%s%s: error while loading "
                                                 "file \"%s\""),
                                weechat_prefix ("error"), RUBY_PLUGIN_NAME,
                                filename);
                break;
            case 3:
                weechat_printf (NULL,
                                weechat_gettext ("%s%s: function "
                                                 "\"weechat_init\" is missing "
                                                 "in file \"%s\""),
                                weechat_prefix ("error"), RUBY_PLUGIN_NAME,
                                filename);
                break;
        }

        if (NUM2INT(ruby_retcode) == 2)
        {
            weechat_ruby_print_exception (rb_iv_get (ruby_current_module,
                                                     "@load_eval_file_error"));
        }

        return 0;
    }

    (void) rb_protect_funcall (ruby_current_module, rb_intern ("weechat_init"),
                               &ruby_error, 0, NULL);

    if (ruby_error)
    {
        weechat_printf (NULL,
                        weechat_gettext ("%s%s: unable to eval function "
                                         "\"weechat_init\" in file \"%s\""),
                        weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename);

        err = rb_gv_get("$!");
        weechat_ruby_print_exception(err);

        if (ruby_current_script)
        {
            plugin_script_remove (weechat_ruby_plugin,
                                  &ruby_scripts, &last_ruby_script,
                                  ruby_current_script);
//.........这里部分代码省略.........
开发者ID:sardemff7,项目名称:weechat,代码行数:101,代码来源:weechat-ruby.c


示例20: cIGraph_initialize

VALUE cIGraph_initialize(int argc, VALUE *argv, VALUE self){

  igraph_t *graph;
  igraph_vector_t edge_v;
  VALUE vertex;
  VALUE directed;
  VALUE edges;
  VALUE attrs;
  VALUE v_ary;
  int vertex_n = 0;
  int current_vertex_id;
  int i;

  igraph_vector_ptr_t vertex_attr;
  igraph_vector_ptr_t edge_attr;

  igraph_i_attribute_record_t v_attr_rec;
  v_attr_rec.name  = "__RUBY__";
  v_attr_rec.type  = IGRAPH_ATTRIBUTE_PY_OBJECT;
  v_attr_rec.value = (void*)rb_ary_new();

  igraph_i_attribute_record_t e_attr_rec;
  e_attr_rec.name  = "__RUBY__";
  e_attr_rec.type  = IGRAPH_ATTRIBUTE_PY_OBJECT;
  e_attr_rec.value = (void*)rb_ary_new();

  rb_scan_args(argc,argv,"12", &edges, &directed, &attrs);

  //Initialize edge vector
  IGRAPH_FINALLY(igraph_vector_destroy,&edge_v);
  IGRAPH_FINALLY(igraph_vector_ptr_destroy,&vertex_attr);
  IGRAPH_FINALLY(igraph_vector_ptr_destroy,&edge_attr);

  IGRAPH_CHECK(igraph_vector_init_int(&edge_v,0));

  IGRAPH_CHECK(igraph_vector_ptr_init(&vertex_attr,0));
  IGRAPH_CHECK(igraph_vector_ptr_init(&edge_attr,0));

  Data_Get_Struct(self, igraph_t, graph);

  v_ary = rb_ary_new();

  if(!directed)
    IGRAPH_CHECK(igraph_to_undirected(graph,IGRAPH_TO_UNDIRECTED_COLLAPSE));

  //Loop through objects in edge Array
  for (i=0; i<RARRAY_LEN(edges); i++) {
    vertex = RARRAY_PTR(edges)[i];
    if(rb_ary_includes(v_ary,vertex)){
      //If @vertices includes this vertex then look up the vertex number
      current_vertex_id = NUM2INT(rb_funcall(v_ary,rb_intern("index"),1,vertex));
    } else {
      //Otherwise add to the list of vertices
      rb_ary_push(v_ary,vertex);
      current_vertex_id = vertex_n;
      vertex_n++;
      
      //Add object to list of vertex attributes
      rb_ary_push((VALUE)v_attr_rec.value,vertex);
      
    }
    IGRAPH_CHECK(igraph_vector_push_back(&edge_v,current_vertex_id));
    if (i % 2){
      if (attrs != Qnil){
	rb_ary_push((VALUE)e_attr_rec.value,RARRAY_PTR(attrs)[i/2]);
      } else {
	rb_ary_push((VALUE)e_attr_rec.value,Qnil);
      }
    }
  }

  IGRAPH_CHECK(igraph_vector_ptr_push_back(&vertex_attr, &v_attr_rec));
  IGRAPH_CHECK(igraph_vector_ptr_push_back(&edge_attr,   &e_attr_rec));

  if(igraph_vector_size(&edge_v) > 0){
    IGRAPH_CHECK(igraph_add_vertices(graph,vertex_n,&vertex_attr));
    IGRAPH_CHECK(igraph_add_edges(graph,&edge_v,&edge_attr));
  }

  igraph_vector_destroy(&edge_v);
  igraph_vector_ptr_destroy(&vertex_attr);
  igraph_vector_ptr_destroy(&edge_attr);

  IGRAPH_FINALLY_CLEAN(3);

  return self;

}
开发者ID:RogerPodacter,项目名称:igraph,代码行数:88,代码来源:cIGraph.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ NUM2LONG函数代码示例发布时间:2022-05-30
下一篇:
C++ NUM2DBL函数代码示例发布时间: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