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


C++ rb_type函数代码示例

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


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


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