本文整理汇总了C++中rb_type函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_type函数的具体用法?C++ rb_type怎么用?C++ rb_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_type函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: Buffer_initialize
static VALUE Buffer_initialize(int argc, VALUE* argv, VALUE self)
{
VALUE io = Qnil;
VALUE options = Qnil;
if(argc == 0 || (argc == 1 && argv[0] == Qnil)) {
/* Qnil */
} else if(argc == 1) {
VALUE v = argv[0];
if(rb_type(v) == T_HASH) {
options = v;
} else {
io = v;
}
} else if(argc == 2) {
io = argv[0];
options = argv[1];
if(rb_type(options) != T_HASH) {
rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(io));
}
} else {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..1)", argc);
}
BUFFER(self, b);
MessagePack_Buffer_initialize(b, io, options);
return self;
}
开发者ID:josephholsten,项目名称:msgpack-ruby,代码行数:33,代码来源:buffer_class.c
示例2: if
octave_value OR_Variable::to_octave()
{
if (ruby_val == Qtrue) {
return true;
} else if (ruby_val == Qfalse) {
return false;
} else if (ruby_val == Qnil) {
return octave_NaN;
} else if (rb_type(ruby_val) == T_FLOAT) {
return RFLOAT_VALUE(ruby_val);
} else if (rb_type(ruby_val) == T_FIXNUM) {
return FIX2LONG(ruby_val);
} else if (rb_obj_is_kind_of(ruby_val, rb_path2class("Array")) == Qtrue) {
return OR_Array(ruby_val).to_octave();
} else if (rb_obj_is_kind_of(ruby_val, rb_path2class("Hash")) == Qtrue) {
return OR_Hash(ruby_val).to_octave();
} else if (rb_obj_is_kind_of(ruby_val, rb_path2class("Octave::StructMatrix")) == Qtrue) {
return OR_StructMatrix(ruby_val).to_octave();
} else if (rb_obj_is_kind_of(ruby_val, rb_path2class("Octave::CellMatrix")) == Qtrue) {
return OR_CellMatrix(ruby_val).to_octave();
} else if (rb_obj_is_kind_of(ruby_val, rb_path2class("Octave::Matrix")) == Qtrue) {
return OR_Matrix(ruby_val).to_octave();
} else {
return OR_String(ruby_val).to_octave();
}
}
开发者ID:IlyaAndr,项目名称:octave-ruby,代码行数:26,代码来源:or-variable.cpp
示例3: FIX2INT
octave_value OR_Matrix::to_octave()
{
int row_index, column_index;
int number_of_rows = FIX2INT(rb_iv_get(ruby_val, "@m"));
int number_of_columns = FIX2INT(rb_iv_get(ruby_val, "@n"));
VALUE cells = rb_iv_get(ruby_val, "@cells");
VALUE row, cell;
Matrix matrix = Matrix(number_of_rows, number_of_columns);
for (row_index = 0; row_index < number_of_rows; row_index++) {
row = RARRAY_PTR(cells)[row_index];
for (column_index = 0; column_index < number_of_columns; column_index++) {
cell = RARRAY_PTR(row)[column_index];
if (rb_type(cell) == T_FLOAT) {
matrix(row_index, column_index) = RFLOAT_VALUE(cell);
} else if (rb_type(cell) == T_FIXNUM) {
matrix(row_index, column_index) = FIX2LONG(cell);
} else {
matrix(row_index, column_index) = octave_NaN;
}
}
}
return matrix;
}
开发者ID:IlyaAndr,项目名称:octave-ruby,代码行数:27,代码来源:or-matrix.cpp
示例4: smatrix_rb_set
VALUE smatrix_rb_set(VALUE self, VALUE x, VALUE y, VALUE value) {
smatrix_t* smatrix = NULL;
smatrix_rb_gethandle(self, &smatrix);
if (!smatrix) {
rb_raise(rb_eTypeError, "smatrix @handle is Nil, something is very bad :'(");
return Qnil;
}
if (rb_type(x) != RUBY_T_FIXNUM) {
rb_raise(rb_eTypeError, "first argument (x) must be a Fixnum");
return Qnil;
}
if (rb_type(y) != RUBY_T_FIXNUM) {
rb_raise(rb_eTypeError, "second argument (y) must be a Fixnum");
return Qnil;
}
if (rb_type(value) != RUBY_T_FIXNUM) {
rb_raise(rb_eTypeError, "third argument must be a Fixnum");
return Qnil;
}
return INT2NUM(smatrix_set(smatrix, NUM2INT(x), NUM2INT(y), NUM2INT(value)));
}
开发者ID:JC5137,项目名称:libsmatrix,代码行数:26,代码来源:smatrix_ruby.c
示例5: NS
MQ_BFL NS(argv2bufl) (struct MqS * const mqctx, struct MqBufferLS * args, int argc, VALUE *argv)
{
if (argc != 0) {
int i = 0;
if (args == NULL) args = MqBufferLCreate (argc);
if (argc >= 2) {
VALUE v = rb_type(argv[1]) == T_ARRAY ? RARRAY_PTR(argv[1])[0] : argv[1];
if (!strcmp(VAL2CST(v), MqFactoryCtxIdentGet(mqctx))) {
argc--;
argv++;
}
}
for (i=0; i < argc; i++, argv++) {
const VALUE argv2 = *argv;
if (rb_type(argv2) == T_ARRAY) {
int j;
const int argv2l = RARRAY_LEN(argv2);
VALUE *argv2P = RARRAY_PTR(argv2);
for (j=0; j<argv2l; j++, argv2P++) {
MqBufferLAppendC (args, VAL2CST(*argv2P));
}
} else {
MqBufferLAppendC (args, VALP2CST(argv));
}
}
}
return args;
}
开发者ID:BackupTheBerlios,项目名称:nhi1-svn,代码行数:30,代码来源:misc_ruby.c
示例6: subextSubletSend
VALUE
subextSubletSend(VALUE self,
VALUE value)
{
VALUE id = Qnil;
/* Check ruby object */
rb_check_frozen(self);
GET_ATTR(self, "@id", id);
/* Check object type */
if(T_STRING == rb_type(value))
{
char *list = NULL;
SubMessageData data = { { 0, 0, 0, 0, 0 } };
/* Store data */
list = strdup(RSTRING_PTR(value));
subSharedPropertySetStrings(display, DefaultRootWindow(display),
XInternAtom(display, "SUBTLE_DATA", False), &list, 1);
free(list);
data.l[0] = FIX2INT(id);
subSharedMessage(display, DefaultRootWindow(display),
"SUBTLE_SUBLET_DATA", data, 32, True);
}
else rb_raise(rb_eArgError, "Unexpected value-type `%s'",
rb_obj_classname(value));
return self;
} /* }}} */
开发者ID:AlexTalker,项目名称:subtle,代码行数:32,代码来源:sublet.c
示例7: SubletFind
/* SubletFind {{{ */
static VALUE
SubletFind(VALUE value,
int first)
{
int flags = 0;
VALUE parsed = Qnil;
char buf[50] = { 0 };
subextSubtlextConnect(NULL); ///< Implicit open connection
/* Check object type */
switch(rb_type(parsed = subextSubtlextParse(
value, buf, sizeof(buf), &flags)))
{
case T_SYMBOL:
if(CHAR2SYM("all") == parsed)
return subextSubletSingList(Qnil);
break;
case T_OBJECT:
if(rb_obj_is_instance_of(value, rb_const_get(mod, rb_intern("Sublet"))))
return parsed;
}
return subextSubtlextFindObjectsGeometry("SUBTLE_SUBLET_LIST",
"Sublet", buf, flags, first);
} /* }}} */
开发者ID:AlexTalker,项目名称:subtle,代码行数:27,代码来源:sublet.c
示例8: dh_control_write_transfer
static VALUE dh_control_write_transfer(int argc, VALUE *argv, VALUE self)
{
VALUE obmRequestType, obRequest, owValue, owIndex, oData;
rb_scan_args(argc, argv, "41", &obmRequestType, &obRequest, &owValue, &owIndex, &oData);
unsigned int timeout = 300; // TODO: make this a settable option
unsigned char * buffer = 0;
unsigned int wLength = 0;
if (oData != Qnil)
{
if (rb_type(oData) != RUBY_T_STRING)
{
rb_raise(rb_eTypeError, "Expected data to be a string or nil.");
}
buffer = RSTRING_PTR(oData);
wLength = RSTRING_LEN(oData);
if (wLength > 0xFFFF)
{
rb_raise(rb_eRangeError, "Expected length of data to be at most 65535.");
}
}
int result = libusb_control_transfer
(dh_extract(self),
FIX2INT(obmRequestType), FIX2INT(obRequest),
FIX2INT(owValue), FIX2INT(owIndex),
buffer, wLength, timeout);
if (result < 0){ raise_usb_exception(result); }
return Qnil;
}
开发者ID:DavidEGrayson,项目名称:ruby-usb-pro,代码行数:30,代码来源:device_handle.c
示例9: subSubtleSingSpawn
VALUE
subSubtleSingSpawn(VALUE self,
VALUE cmd)
{
VALUE ret = Qnil;
/* Check object type */
if(T_STRING == rb_type(cmd))
{
pid_t pid = 0;
subSubtlextConnect(NULL); ///< Implicit open connection
/* Create client with empty window id since we cannot
* know the real window id at this point (race) */
if(0 < (pid = subSharedSpawn(RSTRING_PTR(cmd))))
{
ret = subClientInstantiate((int)pid);
rb_iv_set(ret, "@pid", INT2FIX((int)pid));
}
}
else rb_raise(rb_eArgError, "Unexpected value-type `%s'",
rb_obj_classname(cmd));
return ret;
} /* }}} */
开发者ID:guns,项目名称:subtle,代码行数:26,代码来源:subtle.c
示例10: Scalar_init
static VALUE Scalar_init(VALUE self, VALUE v)
{
vx_scalar scalar = 0;
int type = rb_type(v);
switch (type)
{
case T_FIXNUM: // int32_t or int64_t based on ARCH depth
{
#if defined(ARCH_16) // microcontrollers?
vx_int16 value = FIX2INT(v);
scalar = vxCreateScalar(context, VX_TYPE_INT16, &value);
#elif defined(ARCH_32) // ARM, mobile processors
vx_int32 value = FIX2INT(v);
scalar = vxCreateScalar(context, VX_TYPE_INT32, &value);
#elif defined(ARCH_64) // Desktops
vx_int64 value = FIX2INT(v);
scalar = vxCreateScalar(context, VX_TYPE_INT64, &value);
#endif
break;
}
case T_BIGNUM: // "infinite" length, don't know what to do with this...
Check_Type(v, T_FIXNUM);
break;
case T_FLOAT: // doubles
{
vx_float64 value = NUM2DBL(v);
scalar = vxCreateScalar(context, VX_TYPE_FLOAT64, &value);
break;
}
}
DATA_PTR(self) = (void *)scalar;
return Qnil;
}
开发者ID:ofleischmann,项目名称:vision,代码行数:33,代码来源:vx_ruby.c
示例11: subGravitySingFind
VALUE
subGravitySingFind(VALUE self,
VALUE value)
{
int flags = 0;
VALUE parsed = Qnil;
char buf[50] = { 0 };
subSubtlextConnect(NULL); ///< Implicit open connection
/* Check object type */
switch(rb_type(parsed = subSubtlextParse(
value, buf, sizeof(buf), &flags)))
{
case T_SYMBOL:
if(CHAR2SYM("all") == parsed)
return subGravitySingAll(Qnil);
break;
case T_OBJECT:
if(rb_obj_is_instance_of(value, rb_const_get(mod, rb_intern("Gravity"))))
return parsed;
}
return GravityFind(buf, flags);
} /* }}} */
开发者ID:guns,项目名称:subtle,代码行数:25,代码来源:gravity.c
示例12: decode_lat_lon
static void decode_lat_lon(VALUE vlat, VALUE vlon, GeographicLib::Math::real &lat, GeographicLib::Math::real &lon)
{
std::string slat, slon;
if (rb_type(vlat) == T_STRING && rb_type(vlon) == T_STRING) {
slat = rb_string_value_cstr(&vlat);
slon = rb_string_value_cstr(&vlon);
try {
GeographicLib::DMS::DecodeLatLon(slat, slon, lat, lon);
} catch (GeographicLib::GeographicErr e) {
rb_raise(rb_eRuntimeError, "This is not a valid position.");
}
} else {
lat = rb_num2dbl(vlat);
lon = rb_num2dbl(vlon);
}
}
开发者ID:kext,项目名称:ruby-geographiclib,代码行数:16,代码来源:geographiclib.cpp
示例13: stringForceUTF8
static VALUE stringForceUTF8(VALUE arg)
{
if (rb_type(arg) == RUBY_T_STRING && ENCODING_IS_ASCII8BIT(arg))
rb_enc_associate_index(arg, rb_utf8_encindex());
return arg;
}
开发者ID:BlackLotus,项目名称:mkxp,代码行数:7,代码来源:filesystem-binding.cpp
示例14: ViewFind
/* ViewFind {{{ */
static VALUE
ViewFind(VALUE value,
int first)
{
int flags = 0;
VALUE parsed = Qnil;
char buf[50] = { 0 };
subextSubtlextConnect(NULL); ///< Implicit open connection
/* Check object type */
switch(rb_type(parsed = subextSubtlextParse(
value, buf, sizeof(buf), &flags)))
{
case T_SYMBOL:
if(CHAR2SYM("visible") == parsed)
return subextViewSingVisible(Qnil);
else if(CHAR2SYM("all") == parsed)
return subextViewSingList(Qnil);
else if(CHAR2SYM("current") == parsed)
return subextViewSingCurrent(Qnil);
break;
case T_OBJECT:
if(rb_obj_is_instance_of(value, rb_const_get(mod, rb_intern("View"))))
return parsed;
}
return subextSubtlextFindObjects("_NET_DESKTOP_NAMES", "View",
buf, flags, first);
} /* }}} */
开发者ID:AlexTalker,项目名称:subtle,代码行数:31,代码来源:view.c
示例15: application_initialize
static VALUE application_initialize(VALUE self, VALUE args) {
if (rb_thread_main() != rb_thread_current()) {
rb_raise(rb_eThreadError, "Initializing QML::Application outside the main thread");
}
application_t *data;
TypedData_Get_Struct(self, application_t, &data_type, data);
if (rb_type(args) != T_ARRAY) {
rb_raise(rb_eTypeError, "Expected Array");
}
args = rb_ary_concat(rb_ary_new_from_args(1, rb_argv0), args);
int argc = RARRAY_LEN(args);
char **argv = malloc(argc * sizeof(char *));
for (int i = 0; i < argc; ++i) {
VALUE arg = RARRAY_AREF(args, i);
argv[i] = rb_string_value_cstr(&arg);
}
data->application = qmlbind_application_new(argc, argv);
return self;
}
开发者ID:polamjag,项目名称:ruby-qml,代码行数:26,代码来源:application.c
示例16: rb_grn_value_from_ruby_object
grn_obj *
rb_grn_value_from_ruby_object (VALUE object, grn_ctx *context,
grn_obj *value, grn_id type_id, grn_obj *type)
{
grn_bool string_p, table_type_p;
string_p = rb_type(object) == T_STRING;
table_type_p = (GRN_TABLE_HASH_KEY <= type->header.type &&
type->header.type <= GRN_TABLE_NO_KEY);
if (!string_p) {
return RVAL2GRNBULK_WITH_TYPE(object, context, value, type_id, type);
}
if (table_type_p && RSTRING_LEN(object) == 0) {
if (value) {
if (value->header.domain != type_id) {
grn_obj_reinit(context, value, type_id, 0);
}
} else {
value = grn_obj_open(context, GRN_BULK, 0, type_id);
rb_grn_context_check(context, object);
}
GRN_RECORD_SET(context, value, GRN_ID_NIL);
return value;
}
return RVAL2GRNBULK(object, context, value);
}
开发者ID:rutice,项目名称:rroonga,代码行数:28,代码来源:rb-grn-utils.c
示例17: smatrix_rb_initialize
VALUE smatrix_rb_initialize(VALUE self, VALUE filename) {
smatrix_t* smatrix = NULL;
VALUE smatrix_handle;
switch (rb_type(filename)) {
case RUBY_T_STRING:
smatrix = smatrix_open(RSTRING_PTR(filename));
break;
case RUBY_T_NIL:
smatrix = smatrix_open(NULL);
break;
default:
rb_raise(rb_eTypeError, "first argument (filename) must be nil or a string");
break;
}
if (smatrix) {
smatrix_handle = Data_Wrap_Struct(rb_cObject, NULL, smatrix_rb_free, smatrix);
rb_iv_set(self, "@handle", smatrix_handle);
}
return self;
}
开发者ID:JC5137,项目名称:libsmatrix,代码行数:27,代码来源:smatrix_ruby.c
示例18: MessagePack_Unpacker_initialize
VALUE MessagePack_Unpacker_initialize(int argc, VALUE* argv, VALUE self)
{
VALUE io = Qnil;
VALUE options = Qnil;
if(argc == 0 || (argc == 1 && argv[0] == Qnil)) {
/* Qnil */
} else if(argc == 1) {
VALUE v = argv[0];
if(rb_type(v) == T_HASH) {
options = v;
if(rb_type(options) != T_HASH) {
rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options));
}
} else {
io = v;
}
} else if(argc == 2) {
io = argv[0];
options = argv[1];
if(rb_type(options) != T_HASH) {
rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options));
}
} else {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
}
UNPACKER(self, uk);
MessagePack_Buffer_set_options(UNPACKER_BUFFER_(uk), io, options);
if(options != Qnil) {
VALUE v;
v = rb_hash_aref(options, ID2SYM(rb_intern("symbolize_keys")));
msgpack_unpacker_set_symbolized_keys(uk, RTEST(v));
v = rb_hash_aref(options, ID2SYM(rb_intern("allow_unknown_ext")));
msgpack_unpacker_set_allow_unknown_ext(uk, RTEST(v));
}
return self;
}
开发者ID:okkez,项目名称:msgpack-ruby,代码行数:46,代码来源:unpacker_class.c
示例19: rb_yaram_mbox_mkfifo
/*
* Gives us access to the mkfifo system call so that
* we don't need to rely on exec.
*/
static VALUE
rb_yaram_mbox_mkfifo(VALUE self, VALUE name)
{
if (rb_type(name) != T_STRING)
rb_raise(rb_eArgError, "name must be a string");
if (mkfifo(RSTRING_PTR(name), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
rb_raise(rb_eException, "can't create named pipe");
return name;
}
开发者ID:simulacre,项目名称:Yaram,代码行数:13,代码来源:yaramc.c
示例20: parse_options
static void
parse_options(VALUE ropts, Options copts) {
struct _YesNoOpt ynos[] = {
{ circular_sym, &copts->circular },
{ auto_define_sym, &copts->auto_define },
{ symbol_keys_sym, &copts->sym_key },
{ ascii_only_sym, &copts->ascii_only },
{ Qnil, 0 }
};
YesNoOpt o;
if (rb_cHash == rb_obj_class(ropts)) {
VALUE v;
if (Qnil != (v = rb_hash_lookup(ropts, indent_sym))) {
if (rb_cFixnum != rb_obj_class(v)) {
rb_raise(rb_eArgError, ":indent must be a Fixnum.\n");
}
copts->indent = NUM2INT(v);
}
#ifdef HAVE_RUBY_ENCODING_H
if (Qnil != (v = rb_hash_lookup(ropts, encoding_sym))) {
if (T_STRING == rb_type(v)) {
oj_default_options.encoding = rb_enc_find(StringValuePtr(v));
} else if (rb_cEncoding == rb_obj_class(v)) {
oj_default_options.encoding = rb_to_encoding(v);
} else {
rb_raise(rb_eArgError, ":encoding must be nil, a String, or an Encoding.\n");
}
}
#endif
if (Qnil != (v = rb_hash_lookup(ropts, mode_sym))) {
if (object_sym == v) {
copts->mode = ObjectMode;
} else if (strict_sym == v) {
copts->mode = StrictMode;
} else if (compat_sym == v) {
copts->mode = CompatMode;
} else if (null_sym == v) {
copts->mode = NullMode;
} else {
rb_raise(rb_eArgError, ":mode must be :object, :strict, :compat, or :null.\n");
}
}
for (o = ynos; 0 != o->attr; o++) {
if (Qnil != (v = rb_hash_lookup(ropts, o->sym))) {
if (Qtrue == v) {
*o->attr = Yes;
} else if (Qfalse == v) {
*o->attr = No;
} else {
rb_raise(rb_eArgError, "%s must be true or false.\n", rb_id2name(SYM2ID(o->sym)));
}
}
}
}
}
开发者ID:MSNexploder,项目名称:oj,代码行数:57,代码来源:oj.c
注:本文中的rb_type函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论