本文整理汇总了C++中NUM2INT函数的典型用法代码示例。如果您正苦于以下问题:C++ NUM2INT函数的具体用法?C++ NUM2INT怎么用?C++ NUM2INT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NUM2INT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rb_proc_arity
int rb_proc_arity(VALUE self)
{
return (int)NUM2INT(rb_funcall(self, rb_intern("arity"), 0));
}
示例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));
}
示例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)));
}
示例4: rg_set_spacing
static VALUE
rg_set_spacing(VALUE self, VALUE spacing)
{
pango_layout_set_spacing(_SELF(self), NUM2INT(spacing));
return self;
}
示例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;
}
示例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;
}
//.........这里部分代码省略.........
示例7: rg_set_height
static VALUE
rg_set_height(VALUE self, VALUE width)
{
pango_layout_set_height(_SELF(self), NUM2INT(width));
return self;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例12: rg_unmark_day
static VALUE
rg_unmark_day(VALUE self, VALUE day)
{
gtk_calendar_unmark_day(_SELF(self), NUM2INT(day));
return self;
}
示例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;
}
示例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;
}
示例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;
}