本文整理汇总了C++中NUM2LONG函数的典型用法代码示例。如果您正苦于以下问题:C++ NUM2LONG函数的具体用法?C++ NUM2LONG怎么用?C++ NUM2LONG使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NUM2LONG函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: lazy_take_func
static VALUE
lazy_take_func(VALUE val, VALUE args, int argc, VALUE *argv)
{
long remain;
VALUE memo = rb_ivar_get(argv[0], id_memo);
if (NIL_P(memo)) {
memo = args;
}
rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
if ((remain = NUM2LONG(memo)-1) == 0) {
return Qundef;
}
else {
rb_ivar_set(argv[0], id_memo, LONG2NUM(remain));
return Qnil;
}
}
开发者ID:corinroyal,项目名称:serenegreens,代码行数:18,代码来源:enumerator.c
示例2: des_check_deserialize_args
/*
* Check the arguments to a deserialize function and process args
*/
static void des_check_deserialize_args(AMF_DESERIALIZER *des, int argc, VALUE *argv) {
VALUE src;
rb_scan_args(argc, argv, "01", &src);
if(des->depth == 0) {
if(src != Qnil) {
des_set_src(des, src);
} else {
rb_raise(rb_eArgError, "Missing deserialization source");
}
} else {
if(src != Qnil) {
rb_raise(rb_eArgError, "Already deserializing a source - don't pass a new one");
} else {
// Make sure pos matches src pos in case StringIO source pos changed
des->pos = NUM2LONG(rb_funcall(des->src, rb_intern("pos"), 0));
}
}
}
开发者ID:ryanwilliams,项目名称:rocket-amf,代码行数:21,代码来源:deserializer.c
示例3: memory_put_string
/*
* call-seq: memory.put_string(offset, str)
* @param [Numeric] offset
* @param [String] str
* @return [self]
* @raise {SecurityError} when writing unsafe string to memory
* @raise {IndexError} if +offset+ is too great
* @raise {NullPointerError} if memory not initialized
* Put a string in memory.
*/
static VALUE
memory_put_string(VALUE self, VALUE offset, VALUE str)
{
AbstractMemory* ptr = MEMORY(self);
long off, len;
Check_Type(str, T_STRING);
off = NUM2LONG(offset);
len = RSTRING_LEN(str);
checkWrite(ptr);
checkBounds(ptr, off, len + 1);
memcpy(ptr->address + off, RSTRING_PTR(str), len);
*((char *) ptr->address + off + len) = '\0';
return self;
}
开发者ID:Bill-Affinity,项目名称:sample_app,代码行数:28,代码来源:AbstractMemory.c
示例4: method_test_and_store_results_separately
// Run a test command, and store the result in two separate strings
//
// Example:
// out, err, rc, major, minor = target.test_and_store_results_separately("find /etc -type l", "nobody")
// Input:
// command: the command to run
// user: the user under which to run the command
// (optional, defaults to "root")
// timeout: the time in seconds after which the command is aborted
// (optional, defaults to 60L)
// Output:
// out: the standard output of the command
// err: the standard error of the command
// rc: the return code of the testing platform
// major: the return code of the system under test
// minor: the return code of the command
VALUE method_test_and_store_results_separately(VALUE self, VALUE ruby_args)
{
long len;
VALUE ruby_command,
ruby_user,
ruby_timeout;
struct twopence_target *target;
twopence_buf_t stdout_buf, stderr_buf;
twopence_status_t status;
int rc;
Check_Type(ruby_args, T_ARRAY);
len = RARRAY_LEN(ruby_args);
if (len < 1 || len > 3)
rb_raise(rb_eArgError, "wrong number of arguments");
ruby_command = rb_ary_entry(ruby_args, 0);
if (len >= 2)
{
ruby_user = rb_ary_entry(ruby_args, 1);
Check_Type(ruby_user, T_STRING);
}
else ruby_user = rb_str_new2("root");
if (len >= 3)
{
ruby_timeout = rb_ary_entry(ruby_args, 2);
Check_Type(ruby_timeout, T_FIXNUM);
}
else ruby_timeout = LONG2NUM(60L);
Data_Get_Struct(self, struct twopence_target, target);
twopence_buf_init(&stdout_buf);
twopence_buf_init(&stderr_buf);
twopence_buf_resize(&stdout_buf, 65536);
twopence_buf_resize(&stderr_buf, 65536);
rc = twopence_test_and_store_results_separately(target,
StringValueCStr(ruby_user), NUM2LONG(ruby_timeout), StringValueCStr(ruby_command),
&stdout_buf, &stderr_buf, &status);
return rb_ary_new3(5,
buffer_value(&stdout_buf),
buffer_value(&stderr_buf),
INT2NUM(rc), INT2NUM(status.major), INT2NUM(status.minor));
}
开发者ID:CasaMallo,项目名称:twopence,代码行数:60,代码来源:target.c
示例5: lazy_take
static VALUE
lazy_take(VALUE obj, VALUE n)
{
long len = NUM2LONG(n);
VALUE lazy;
if (len < 0) {
rb_raise(rb_eArgError, "attempt to take negative size");
}
if (len == 0) {
VALUE len = INT2FIX(0);
lazy = lazy_to_enum_i(obj, sym_cycle, 1, &len, 0);
}
else {
lazy = rb_block_call(rb_cLazy, id_new, 1, &obj,
lazy_take_func, n);
}
return lazy_set_method(lazy, rb_ary_new3(1, n), lazy_take_size);
}
开发者ID:takuto-h,项目名称:ruby,代码行数:19,代码来源:enumerator.c
示例6: lazy_zip_arrays_func
static VALUE
lazy_zip_arrays_func(VALUE val, VALUE arrays, int argc, VALUE *argv)
{
VALUE yielder, ary, memo;
long i, count;
yielder = argv[0];
memo = rb_attr_get(yielder, id_memo);
count = NIL_P(memo) ? 0 : NUM2LONG(memo);
ary = rb_ary_new2(RARRAY_LEN(arrays) + 1);
rb_ary_push(ary, argv[1]);
for (i = 0; i < RARRAY_LEN(arrays); i++) {
rb_ary_push(ary, rb_ary_entry(RARRAY_AREF(arrays, i), count));
}
rb_funcall(yielder, id_yield, 1, ary);
rb_ivar_set(yielder, id_memo, LONG2NUM(++count));
return Qnil;
}
开发者ID:takuto-h,项目名称:ruby,代码行数:19,代码来源:enumerator.c
示例7: rb_struct_aref
VALUE
rb_struct_aref(VALUE s, VALUE idx)
{
long i;
if (RB_TYPE_P(idx, T_STRING) || RB_TYPE_P(idx, T_SYMBOL)) {
return rb_struct_aref_id(s, rb_to_id(idx));
}
i = NUM2LONG(idx);
if (i < 0) i = RSTRUCT_LEN(s) + i;
if (i < 0)
rb_raise(rb_eIndexError, "offset %ld too small for struct(size:%ld)",
i, RSTRUCT_LEN(s));
if (RSTRUCT_LEN(s) <= i)
rb_raise(rb_eIndexError, "offset %ld too large for struct(size:%ld)",
i, RSTRUCT_LEN(s));
return RSTRUCT_PTR(s)[i];
}
开发者ID:Chatto,项目名称:VGdesk,代码行数:19,代码来源:struct.c
示例8: syserr_initialize
static VALUE
syserr_initialize(int argc, VALUE *argv, VALUE self)
{
#if !defined(_WIN32)
char *strerror();
#endif
const char *err;
VALUE mesg, error;
VALUE klass = rb_obj_class(self);
if (klass == rb_eSystemCallError) {
rb_scan_args(argc, argv, "11", &mesg, &error);
if (argc == 1 && FIXNUM_P(mesg)) {
error = mesg; mesg = Qnil;
}
if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &klass)) {
/* change class */
if (TYPE(self) != T_OBJECT) { /* insurance to avoid type crash */
rb_raise(rb_eTypeError, "invalid instance type");
}
RBASIC(self)->klass = klass;
}
}
else {
rb_scan_args(argc, argv, "01", &mesg);
error = rb_const_get(klass, rb_intern("Errno"));
}
if (!NIL_P(error)) err = strerror(NUM2INT(error));
else err = "unknown error";
if (!NIL_P(mesg)) {
VALUE str = mesg;
StringValue(str);
mesg = rb_sprintf("%s - %.*s", err,
(int)RSTRING_LEN(str), RSTRING_PTR(str));
}
else {
mesg = rb_str_new2(err);
}
rb_call_super(1, &mesg);
rb_iv_set(self, "errno", error);
return self;
}
开发者ID:technohippy,项目名称:oruby,代码行数:43,代码来源:error.c
示例9: rb_struct_aref
VALUE
rb_struct_aref(VALUE s, VALUE idx)
{
long i;
if (TYPE(idx) == T_STRING || TYPE(idx) == T_SYMBOL) {
return rb_struct_aref_id(s, rb_to_id(idx));
}
i = NUM2LONG(idx);
if (i < 0) i = RSTRUCT(s)->len + i;
if (i < 0)
rb_raise(rb_eIndexError, "offset %ld too small for struct(size:%ld)",
i, RSTRUCT(s)->len);
if (RSTRUCT(s)->len <= i)
rb_raise(rb_eIndexError, "offset %ld too large for struct(size:%ld)",
i, RSTRUCT(s)->len);
return RSTRUCT(s)->ptr[i];
}
开发者ID:asimoov,项目名称:emscripted-ruby,代码行数:19,代码来源:struct.c
示例10: recursive_hash
static VALUE
recursive_hash(VALUE s, VALUE dummy, int recur)
{
long i, len;
st_index_t h;
VALUE n, *ptr;
h = rb_hash_start(rb_hash(rb_obj_class(s)));
if (!recur) {
ptr = RSTRUCT_PTR(s);
len = RSTRUCT_LEN(s);
for (i = 0; i < len; i++) {
n = rb_hash(ptr[i]);
h = rb_hash_uint(h, NUM2LONG(n));
}
}
h = rb_hash_end(h);
return INT2FIX(h);
}
开发者ID:Chatto,项目名称:VGdesk,代码行数:19,代码来源:struct.c
示例11: f_imul
inline static VALUE
f_imul(long a, long b)
{
VALUE r;
long c;
if (a == 0 || b == 0)
return ZERO;
else if (a == 1)
return LONG2NUM(b);
else if (b == 1)
return LONG2NUM(a);
c = a * b;
r = LONG2NUM(c);
if (NUM2LONG(r) != c || (c / a) != b)
r = rb_big_mul(rb_int2big(a), rb_int2big(b));
return r;
}
开发者ID:alloy,项目名称:mr-experimental,代码行数:19,代码来源:rational.c
示例12: RAWTRACE
jobject rho_cast_helper<jobject, VALUE>::operator()(JNIEnv *env, VALUE value)
{
RAWTRACE("rho_cast<jobject, VALUE>");
if (NIL_P(value))
return 0;
if (!initConvertor(env))
return 0;
switch(TYPE(value))
{
case RUBY_T_SYMBOL:
value = rb_funcall(value, rb_intern("to_s"), 0);
case RUBY_T_STRING:
RAWTRACE("Convert to String object");
return env->NewStringUTF(RSTRING_PTR(value));
case RUBY_T_ARRAY:
RAWTRACE("Convert to Collection object");
return convertRubyArrayToJavaCollection(value);
case RUBY_T_HASH:
RAWTRACE("Convert to Map object");
return convertRubyHashToJavaMap(value);
case RUBY_T_TRUE:
RAWTRACE("Convert to TRUE Boolean obeject");
return RhoJniConvertor::getBooleanObject(true);
case RUBY_T_FALSE:
RAWTRACE("Convert to FALSE Boolean object");
return RhoJniConvertor::getBooleanObject(false);
case RUBY_T_FIXNUM:
case RUBY_T_BIGNUM:
RAWTRACE("Convert to Integer object");
return RhoJniConvertor::getIntegerObject(NUM2LONG(value));
case RUBY_T_FLOAT:
case RUBY_T_RATIONAL:
RAWTRACE("Convert to Double object");
return RhoJniConvertor::getDoubleObject(NUM2DBL(value));
}
RAWLOG_ERROR1("rho_cast<jobject, VALUE>: wrong type of VALUE: %d", TYPE(value));
return 0;
}
开发者ID:CSanshulgandhi,项目名称:rhodes,代码行数:42,代码来源:JNIRhoRuby.cpp
示例13: bdb_sary_fetch
static VALUE
bdb_sary_fetch(int argc, VALUE *argv, VALUE obj)
{
VALUE pos, ifnone;
bdb_DB *dbst;
long idx;
GetDB(obj, dbst);
rb_scan_args(argc, argv, "11", &pos, &ifnone);
idx = NUM2LONG(pos);
if (idx < 0) {
idx += dbst->len;
}
if (idx < 0 || dbst->len <= idx) {
return ifnone;
}
pos = INT2NUM(idx);
return bdb_get(1, &pos, obj);
}
开发者ID:tevren,项目名称:ruby-bdb,代码行数:20,代码来源:recnum.c
示例14: des_set_src
/*
* Set the source of the amf reader to a StringIO object, creating a new one to
* wrap the source if it's only a string
*/
void des_set_src(AMF_DESERIALIZER *des, VALUE src) {
VALUE klass = CLASS_OF(src);
if(klass == cStringIO) {
VALUE str = rb_funcall(src, rb_intern("string"), 0);
des->src = src;
des->stream = RSTRING_PTR(str);
des->pos = NUM2LONG(rb_funcall(src, rb_intern("pos"), 0));
des->size = RSTRING_LEN(str);
} else if(klass == rb_cString) {
VALUE args[1] = {src};
des->src = rb_class_new_instance(1, args, cStringIO);
des->stream = RSTRING_PTR(src);
des->pos = 0;
des->size = RSTRING_LEN(src);
} else {
rb_raise(rb_eArgError, "Invalid source type to deserialize from");
}
if(des->pos >= des->size) rb_raise(rb_eRangeError, "already at the end of the source");
}
开发者ID:qianthinking,项目名称:rocketamf,代码行数:24,代码来源:deserializer.c
示例15: rb_u_string_index_m
/* @overload index(pattern, offset = 0)
*
* Returns the minimal index of the receiver where PATTERN matches, equal to or
* greater than _i_, where _i_ = OFFSET if OFFSET ≥ 0, _i_ = {#length} -
* abs(OFFSET) otherwise, or nil if there is no match.
*
* If PATTERN is a Regexp, the Regexp special variables `$&`, `$'`,
* <code>$\`</code>, `$1`, `$2`, …, `$`_n_ are updated accordingly.
*
* If PATTERN responds to #to_str, the matching is performed by byte
* comparison.
*
* @param [Regexp, #to_str] pattern
* @param [#to_int] offset
* @return [Integer, nil]
* @see #rindex */
VALUE
rb_u_string_index_m(int argc, VALUE *argv, VALUE self)
{
VALUE sub, rboffset;
long offset = 0;
if (rb_scan_args(argc, argv, "11", &sub, &rboffset) == 2)
offset = NUM2LONG(rboffset);
const struct rb_u_string *string = RVAL2USTRING(self);
const char *begin = rb_u_string_begin_from_offset(string, offset);
if (begin == NULL) {
if (TYPE(sub) == T_REGEXP)
rb_backref_set(Qnil);
return Qnil;
}
switch (TYPE(sub)) {
case T_REGEXP:
offset = rb_u_string_index_regexp(self, begin, sub, false);
break;
default: {
VALUE tmp = rb_check_string_type(sub);
if (NIL_P(tmp))
rb_u_raise(rb_eTypeError, "type mismatch: %s given",
rb_obj_classname(sub));
sub = tmp;
}
/* fall through */
case T_STRING:
offset = rb_u_string_index(self, sub, offset);
break;
}
if (offset < 0)
return Qnil;
return LONG2NUM(offset);
}
开发者ID:now,项目名称:u,代码行数:57,代码来源:rb_u_string_index.c
示例16: measure_gc_time
static double
measure_gc_time()
{
#if defined(HAVE_RB_GC_TOTAL_TIME)
#define MEASURE_GC_TIME_ENABLED Qtrue
return rb_gc_total_time();
#elif defined(HAVE_RB_GC_TIME)
#define MEASURE_GC_TIME_ENABLED Qtrue
const double conversion = 1000000.0;
#if HAVE_LONG_LONG
return NUM2LL(rb_gc_time()) / conversion;
#else
return NUM2LONG(rb_gc_time()) / conversion;
#endif
#else
#define MEASURE_GC_TIME_ENABLED Qfalse
return 0.0;
#endif
}
开发者ID:Angeldude,项目名称:sonic-pi,代码行数:21,代码来源:rp_measure_gc_time.c
示例17: step_sec_timeval
void
step_sec_timeval( VALUE secs, struct timeval *t)
{
switch (TYPE(secs)) {
case T_FIXNUM:
t->tv_sec = FIX2LONG(secs), t->tv_usec = 0;
if (t->tv_sec < 0)
rb_raise( rb_eArgError, "time interval must be positive");
break;
case T_FLOAT:
if (RFLOAT(secs)->value < 0.0)
rb_raise( rb_eArgError, "time interval must be positive");
else {
double f, d;
d = modf( RFLOAT(secs)->value, &f);
t->tv_sec = (time_t) f, t->tv_usec = (time_t) (d*1e6+0.5);
if (f != t->tv_sec)
rb_raise( rb_eRangeError, "time interval out of Time range",
RFLOAT(secs)->value);
}
break;
case T_BIGNUM:
t->tv_sec = NUM2LONG(secs), t->tv_usec = 0;
if (t->tv_sec < 0)
rb_raise(rb_eArgError, "time interval must be positive");
break;
case T_NIL:
t->tv_sec = 0, t->tv_usec = 0;
break;
default:
rb_raise( rb_eTypeError, "can't convert %s into time interval",
rb_obj_classname( secs));
break;
}
}
开发者ID:rubyworks,项目名称:carats,代码行数:40,代码来源:itimer.c
示例18: num2timespec
static void num2timespec(struct timespec *ts, VALUE t)
{
switch (TYPE(t)) {
case T_FIXNUM:
case T_BIGNUM:
ts->tv_sec = NUM2TIMET(t);
ts->tv_nsec = 0;
break;
case T_FLOAT: {
double f, d;
double val = RFLOAT_VALUE(t);
d = modf(val, &f);
if (d >= 0) {
ts->tv_nsec = (long)(d * 1e9 + 0.5);
} else {
ts->tv_nsec = (long)(-d * 1e9 + 0.5);
if (ts->tv_nsec > 0) {
ts->tv_nsec = 1000000000 - ts->tv_nsec;
f -= 1;
}
}
ts->tv_sec = (time_t)f;
if (f != ts->tv_sec)
rb_raise(rb_eRangeError, "%f out of range", val);
}
break;
default: {
VALUE f;
VALUE ary = rb_funcall(t, id_divmod, 1, INT2FIX(1));
Check_Type(ary, T_ARRAY);
ts->tv_sec = NUM2TIMET(rb_ary_entry(ary, 0));
f = rb_ary_entry(ary, 1);
f = rb_funcall(f, '*', 1, INT2FIX(1000000000));
ts->tv_nsec = NUM2LONG(f);
}
}
}
开发者ID:tmm1,项目名称:ruby_posix_mq,代码行数:40,代码来源:posix_mq.c
示例19: datetime_gregorian__components
VALUE
datetime_gregorian__components(int argc, VALUE *argv, VALUE self)
{
long cyear, cday_number; // those should/will be a 64bit int
int cmonth, cweek, cdayofyear, cdayofmonth, cdayofweek, cdays, isleap;
struct tm *tm_now;
struct timeval tv_now;
VALUE year, month, week, dayofyear, dayofmonth, dayofweek, ps_number, timezone, language;
rb_scan_args(argc, argv, "9", &year, &month, &week, &dayofyear, &dayofmonth, &dayofweek, &ps_number, &timezone, &language);
if (gettimeofday(&tv_now, 0) < 0) { // stolen from time.c (ruby18)
rb_sys_fail("gettimeofday");
}
tm_now = gmtime(&(tv_now.tv_sec));
if (!(NIL_P(year) && NIL_P(month) && NIL_P(week) && NIL_P(dayofyear) && NIL_P(dayofmonth) && NIL_P(dayofweek))) {
cyear = NIL_P(year) ? (long)tm_now->tm_year+1900 : NUM2LONG(year);
if (!(NIL_P(month) && NIL_P(dayofmonth))) {
int cdoy;
isleap = (((cyear%4==0) && !(cyear%100==0)) || (cyear%400==0));
cmonth = NIL_P(month) ? 1 : FIX2INT(month);
if (1 > cmonth || cmonth > 12) {
rb_raise(rb_eArgError, "Month out of bounds");
}
if (cdayofmonth > (isleap ? DAYS_IN_MONTH2[month] : DAYS_IN_MONTH1[month])) {
rb_raise(rb_eArgError, "Day of month out of bounds");
}
cdayofmonth = NIL_P(dayofmonth) ? 1 : FIX2INT(dayofmonth);
cdays = cyear*365+(cyear/4)-(cyear/100)+(cyear/400)+(cyear%4!=0)+(cyear%100!=0)+(cyear%400!=0);
cdoy = (isleap ? DAYS_UNTIL_MONTH2[month-1] : DAYS_UNTIL_MONTH1[month-1]) + dayofmonth;
cday_number = cdays+cdoy;
}
}
return rb_funcall(rb_cDatetimeGregorian, id_new, 4, INT2NUM(cday_number), ps_number, timezone, language);
}
开发者ID:ameravant,项目名称:chronos,代码行数:39,代码来源:chronos_core.c
示例20: memory_get_array_of_string
static VALUE
memory_get_array_of_string(int argc, VALUE* argv, VALUE self)
{
VALUE offset = Qnil, countnum = Qnil, retVal = Qnil;
AbstractMemory* ptr;
long off;
int count;
rb_scan_args(argc, argv, "11", &offset, &countnum);
off = NUM2LONG(offset);
count = (countnum == Qnil ? 0 : NUM2INT(countnum));
retVal = rb_ary_new2(count);
Data_Get_Struct(self, AbstractMemory, ptr);
checkRead(ptr);
if (countnum != Qnil) {
int i;
checkBounds(ptr, off, count * sizeof (char*));
for (i = 0; i < count; ++i) {
const char* strptr = *((const char**) (ptr->address + off) + i);
rb_ary_push(retVal, (strptr == NULL ? Qnil : rb_tainted_str_new2(strptr)));
}
} else {
checkBounds(ptr, off, sizeof (char*));
for ( ; off < ptr->size - (long) sizeof (void *); off += (long) sizeof (void *)) {
const char* strptr = *(const char**) (ptr->address + off);
if (strptr == NULL) {
break;
}
rb_ary_push(retVal, rb_tainted_str_new2(strptr));
}
}
return retVal;
}
开发者ID:Burgestrand,项目名称:ffi,代码行数:39,代码来源:AbstractMemory.c
注:本文中的NUM2LONG函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论