本文整理汇总了C++中RARRAY_AREF函数的典型用法代码示例。如果您正苦于以下问题:C++ RARRAY_AREF函数的具体用法?C++ RARRAY_AREF怎么用?C++ RARRAY_AREF使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RARRAY_AREF函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: Check_Type
rgb_color
Convert<rgb_color>::FromValue(VALUE v)
{
int value;
rgb_color c;
Check_Type(v, T_ARRAY);
switch (RARRAY_LEN(v)) {
case 3:
value = 0;
break;
case 4:
value = NUM2INT(RARRAY_AREF(v, 3));
break;
default:
rb_raise(rb_eRangeError, "given array cannot be interpreted as rgb_color (length should be 4)");
}
if (value < 0 || value > 255)
rb_raise(rb_eRangeError, "given array cannot be interpreted as rgb_color (alpha out of range (0..255))");
c. alpha = (uint8) value;
value = NUM2INT(RARRAY_AREF(v, 0));
if (value < 0 || value > 255)
rb_raise(rb_eRangeError, "given array cannot be interpreted as rgb_color (red out of range (0..255))");
c.red = (uint8)value;
value = NUM2INT(RARRAY_AREF(v, 1));
if (value < 0 || value > 255)
rb_raise(rb_eRangeError, "given array cannot be interpreted as rgb_color (green out of range (0..255))");
c.green = (uint8)value;
value = NUM2INT(RARRAY_AREF(v, 2));
if (value < 0 || value > 255)
rb_raise(rb_eRangeError, "given array cannot be interpreted as rgb_color (blue out of range (0..255))");
c.blue = (uint8)value;
return c;
}
开发者ID:nmbits,项目名称:rbe,代码行数:35,代码来源:convert.cpp
示例2: ossl_x509crl_set_revoked
static VALUE
ossl_x509crl_set_revoked(VALUE self, VALUE ary)
{
X509_CRL *crl;
X509_REVOKED *rev;
STACK_OF(X509_REVOKED) *sk;
long i;
Check_Type(ary, T_ARRAY);
/* All ary members should be X509 Revoked */
for (i=0; i<RARRAY_LEN(ary); i++) {
OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Rev);
}
GetX509CRL(self, crl);
if ((sk = X509_CRL_get_REVOKED(crl))) {
while ((rev = sk_X509_REVOKED_pop(sk)))
X509_REVOKED_free(rev);
}
for (i=0; i<RARRAY_LEN(ary); i++) {
rev = DupX509RevokedPtr(RARRAY_AREF(ary, i));
if (!X509_CRL_add0_revoked(crl, rev)) { /* NO DUP - don't free! */
X509_REVOKED_free(rev);
ossl_raise(eX509CRLError, "X509_CRL_add0_revoked");
}
}
X509_CRL_sort(crl);
return ary;
}
开发者ID:gferguson-gd,项目名称:ruby,代码行数:29,代码来源:ossl_x509crl.c
示例3: setClassName
AccessClass::AccessClass(RubyValue className, RubyValue methodInfos, RubyValue signalInfos, RubyValue propertyInfos)
{
setClassName(className.to<QByteArray>());
protect([&] {
rb_check_array_type(methodInfos);
rb_check_array_type(signalInfos);
rb_check_array_type(propertyInfos);
});
for (int i = 0; i < RARRAY_LEN(VALUE(methodInfos)); ++i) {
RubyValue info = RARRAY_AREF(VALUE(methodInfos), i);
auto nameSym = info.send("name");
addMethod(nameSym.to<QByteArray>(),
nameSym.toID(),
info.send("params").to<QList<QByteArray>>());
}
for (int i = 0; i < RARRAY_LEN(VALUE(signalInfos)); ++i) {
RubyValue info = RARRAY_AREF(VALUE(signalInfos), i);
auto nameSym = info.send("name");
addSignal(nameSym.to<QByteArray>(),
nameSym.toID(),
info.send("params").to<QList<QByteArray>>());
}
for (int i = 0; i < RARRAY_LEN(VALUE(propertyInfos)); ++i) {
RubyValue info = RARRAY_AREF(VALUE(propertyInfos), i);
addProperty(info.send("name").to<QByteArray>(),
info.send("getter").toID(),
info.send("setter").toID(),
Property::Flag::Readable | Property::Flag::Writable,
true,
info.send("notifier").toID());
}
}
开发者ID:riocampos,项目名称:ruby-qml,代码行数:32,代码来源:accessclass.cpp
示例4: if
wxSize unwrap< wxSize >(const VALUE &vsize)
{
if(rb_obj_is_kind_of(vsize, rb_cArray) && RARRAY_LEN(vsize) == 2 ){
wxSize size;
size.SetWidth(RB_NUM2INT(RARRAY_AREF(vsize,0)));
size.SetHeight(RB_NUM2INT(RARRAY_AREF(vsize,1)));
return size;
}else if(rb_obj_is_kind_of(vsize, rb_cHash)){
wxSize size;
size.SetWidth(RB_NUM2INT(rb_hash_aref(vsize,RB_ID2SYM(rwxID_width))));
size.SetHeight(RB_NUM2INT(rb_hash_aref(vsize,RB_ID2SYM(rwxID_height))));
return size;
}else if(rb_obj_is_kind_of(vsize, rb_cWXRect)){
return unwrapTypedPtr<wxRect>(vsize, rb_cWXRect)->GetSize();
}else if(!rb_obj_is_kind_of(vsize, rb_cWXSize) &&
rb_respond_to(vsize,rwxID_width) &&
rb_respond_to(vsize,rwxID_height)){
wxSize size;
size.SetWidth(RB_NUM2INT(rb_funcall(vsize,rwxID_width,0)));
size.SetHeight(RB_NUM2INT(rb_funcall(vsize,rwxID_height,0)));
return size;
}else{
return *unwrap<wxSize*>(vsize);
}
}
开发者ID:Hanmac,项目名称:rwx,代码行数:25,代码来源:wxSize.cpp
示例5: iter_nstruct_to_a
static void
iter_nstruct_to_a(na_loop_t *const lp)
{
long i, len;
VALUE opt, types, defs, def;
VALUE elmt, velm, vary;
size_t ofs, pos;
narray_view_t *ne;
opt = lp->option;
types = RARRAY_AREF(opt,0);
defs = RARRAY_AREF(opt,1);
pos = lp->args[0].iter[0].pos;
len = RARRAY_LEN(types);
vary = rb_ary_new2(len);
for (i=0; i<len; i++) {
def = RARRAY_AREF(defs,i);
ofs = NUM2SIZET(RARRAY_AREF(def,2));
//ofs = NUM2SIZET(RARRAY_AREF(ofsts,i));
elmt = RARRAY_AREF(types,i);
GetNArrayView(elmt,ne);
ne->offset = pos + ofs;
if (ne->base.ndim==0) {
velm = rb_funcall(elmt,rb_intern("extract"),0);
} else {
velm = rb_funcall(elmt,rb_intern("to_a"),0);
}
rb_ary_push(vary, velm);
}
rb_ary_push(lp->args[1].value, vary);
}
开发者ID:metanest,项目名称:narray-devel,代码行数:33,代码来源:struct.c
示例6: rb_respond_to
sf::Color unwrap< sf::Color >(const VALUE &vcolor)
{
if(!rb_obj_is_kind_of(vcolor, rb_cSFMLColor) &&
rb_respond_to(vcolor,rbSFML_IDred) &&
rb_respond_to(vcolor,rbSFML_IDgreen) &&
rb_respond_to(vcolor,rbSFML_IDblue) &&
rb_respond_to(vcolor,rbSFML_IDalpha)){
sf::Color color;
set_value(color.r,vcolor,rbSFML_IDred);
set_value(color.g,vcolor,rbSFML_IDgreen);
set_value(color.b,vcolor,rbSFML_IDblue);
set_value(color.a,vcolor,rbSFML_IDalpha);
return color;
}else if(rb_obj_is_kind_of(vcolor,rb_cArray)) {
sf::Color color;
color.r = NUM2INT(RARRAY_AREF(vcolor,0));
color.g = NUM2INT(RARRAY_AREF(vcolor,1));
color.b = NUM2INT(RARRAY_AREF(vcolor,2));
if(RARRAY_LEN(vcolor) > 3) {
VALUE val = RARRAY_AREF(vcolor,3);
if(!NIL_P(val))
color.a = NUM2INT(val);
}
return color;
}else{
return *unwrap<sf::Color*>(vcolor);
}
}
开发者ID:Hanmac,项目名称:sfml-ruby,代码行数:35,代码来源:Color.cpp
示例7: _marshal_load
/*
* call-seq:
* marshal_load(array) -> nil
*
* Provides marshalling support for use by the Marshal library.
*
*
*/
DLL_LOCAL VALUE _marshal_load(VALUE self, VALUE data)
{
data = rb_Array(data);
_setWidth(self, RARRAY_AREF(data,0));
_setHeight(self, RARRAY_AREF(data,1));
return Qnil;
}
开发者ID:Hanmac,项目名称:rwx,代码行数:15,代码来源:wxSize.cpp
示例8: console_cursor_set
static VALUE
console_cursor_set(VALUE io, VALUE cpos)
{
cpos = rb_convert_type(cpos, T_ARRAY, "Array", "to_ary");
if (RARRAY_LEN(cpos) != 2) rb_raise(rb_eArgError, "expected 2D coordinate");
return console_goto(io, RARRAY_AREF(cpos, 0), RARRAY_AREF(cpos, 1));
}
开发者ID:DashYang,项目名称:sim,代码行数:7,代码来源:console.c
示例9: lazy_zip_func
static VALUE
lazy_zip_func(VALUE val, VALUE zip_args, int argc, VALUE *argv)
{
VALUE yielder, ary, arg, v;
long i;
yielder = argv[0];
arg = rb_attr_get(yielder, id_memo);
if (NIL_P(arg)) {
arg = rb_ary_new2(RARRAY_LEN(zip_args));
for (i = 0; i < RARRAY_LEN(zip_args); i++) {
rb_ary_push(arg, rb_funcall(RARRAY_AREF(zip_args, i), id_to_enum, 0));
}
rb_ivar_set(yielder, id_memo, arg);
}
ary = rb_ary_new2(RARRAY_LEN(arg) + 1);
rb_ary_push(ary, argv[1]);
for (i = 0; i < RARRAY_LEN(arg); i++) {
v = rb_rescue2(call_next, RARRAY_AREF(arg, i), next_stopped, 0,
rb_eStopIteration, (VALUE)0);
rb_ary_push(ary, v);
}
rb_funcall(yielder, id_yield, 1, ary);
return Qnil;
}
开发者ID:takuto-h,项目名称:ruby,代码行数:26,代码来源:enumerator.c
示例10: _marshal_load
/*
* call-seq:
* marshal_load(array) -> nil
*
* Provides marshalling support for use by the Marshal library.
*
*
*/
VALUE _marshal_load(VALUE self, VALUE data)
{
_set_r(self, RARRAY_AREF(data,0));
_set_g(self, RARRAY_AREF(data,1));
_set_b(self, RARRAY_AREF(data,2));
_set_a(self, RARRAY_AREF(data,3));
return Qnil;
}
开发者ID:Hanmac,项目名称:sfml-ruby,代码行数:16,代码来源:Color.cpp
示例11: nst_check_compatibility
VALUE
nst_check_compatibility(VALUE nst, VALUE ary)
{
VALUE defs, def, type, item;
long len, i;
narray_t *nt;
if (TYPE(ary) != T_ARRAY) {
if (nst==CLASS_OF(ary)) { // same Struct
return Qtrue;
}
return Qfalse;
}
defs = nst_definitions(nst);
len = RARRAY_LEN(defs);
if (len != RARRAY_LEN(ary)) {
//puts("pass2");
return Qfalse;
}
for (i=0; i<len; i++) {
def = RARRAY_AREF(defs,i);
type = RARRAY_AREF(def,1);
GetNArray(type,nt);
item = RARRAY_AREF(ary,i);
if (nt->ndim == 0) {
if (check_array(item)) {
//puts("pass3");
return Qfalse;
}
} else if (nt->ndim == 1) {
if (!check_array_1d(item, nt->size)) {
//puts("pass4");
return Qfalse;
}
} else {
// multi-dimension member
volatile VALUE vnc;
na_compose_t *nc;
int j;
//rb_p(item);
vnc = na_ary_composition(item);
//puts("pass2");
Data_Get_Struct(vnc, na_compose_t, nc);
if (nt->ndim != nc->ndim) {
return Qfalse;
}
for (j=0; j<nc->ndim; j++) {
if (nc->shape[j] != nt->shape[j]) {
return Qfalse;
}
}
return Qtrue;
}
}
return Qtrue;
}
开发者ID:metanest,项目名称:narray-devel,代码行数:58,代码来源:struct.c
示例12: _marshal_load
/*
* call-seq:
* marshal_load(array) -> nil
*
* Provides marshalling support for use by the Marshal library.
*
*
*/
VALUE _marshal_load( VALUE self, VALUE data )
{
_set_left(self, RARRAY_AREF(data,0));
_set_top(self, RARRAY_AREF(data,1));
_set_width(self, RARRAY_AREF(data,2));
_set_height(self, RARRAY_AREF(data,3));
return Qnil;
}
开发者ID:Hanmac,项目名称:sfml-ruby,代码行数:17,代码来源:Rect.cpp
示例13: nucomp_marshal_load
/* :nodoc: */
static VALUE
nucomp_marshal_load(VALUE self, VALUE a)
{
Check_Type(a, T_ARRAY);
if (RARRAY_LEN(a) != 2)
rb_raise(rb_eArgError, "marshaled complex must have an array whose length is 2 but %ld", RARRAY_LEN(a));
rb_ivar_set(self, id_i_real, RARRAY_AREF(a, 0));
rb_ivar_set(self, id_i_imag, RARRAY_AREF(a, 1));
return self;
}
开发者ID:gogotanaka,项目名称:ruby_svn,代码行数:11,代码来源:complex.c
示例14: Check_Type
OCIInterval *oci8_set_ociinterval_ym(OCIInterval *intvl, VALUE val)
{
sb4 year;
sb4 month;
Check_Type(val, T_ARRAY);
if (RARRAY_LEN(val) != 2) {
rb_raise(rb_eRuntimeError, "invalid array size %ld", RARRAY_LEN(val));
}
year = NUM2INT(RARRAY_AREF(val, 0));
month = NUM2INT(RARRAY_AREF(val, 1));
chkerr(OCIIntervalSetYearMonth(oci8_envhp, oci8_errhp,
year, month, intvl));
return intvl;
}
开发者ID:Captnwalker1,项目名称:ruby-oci8,代码行数:15,代码来源:ocidatetime.c
示例15: nst_field_view
VALUE
nst_field_view(VALUE self, VALUE idx)
{
VALUE def, type, ofs;
def = nst_definition(self, idx);
if (!RTEST(def)) {
idx = rb_funcall(idx, rb_intern("to_s"), 0);
rb_raise(rb_eTypeError, "Invalid field: '%s' for struct %s",
StringValuePtr(idx), rb_class2name(CLASS_OF(self)));
}
type = RARRAY_AREF(def,1);
ofs = RARRAY_AREF(def,2);
return na_make_view_struct(self, type, ofs);
}
开发者ID:metanest,项目名称:narray-devel,代码行数:15,代码来源:struct.c
示例16: rb_construct_expanded_load_path
/* Construct expanded load path and store it to cache.
We rebuild load path partially if the cache is invalid.
We don't cache non string object and expand it every time. We ensure that
string objects in $LOAD_PATH are frozen.
*/
static void
rb_construct_expanded_load_path(int type, int *has_relative, int *has_non_cache)
{
rb_vm_t *vm = GET_VM();
VALUE load_path = vm->load_path;
VALUE expanded_load_path = vm->expanded_load_path;
VALUE ary;
long i;
int level = rb_safe_level();
ary = rb_ary_tmp_new(RARRAY_LEN(load_path));
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
VALUE path, as_str, expanded_path;
int is_string, non_cache;
char *as_cstr;
as_str = path = RARRAY_AREF(load_path, i);
is_string = RB_TYPE_P(path, T_STRING) ? 1 : 0;
non_cache = !is_string ? 1 : 0;
as_str = rb_get_path_check_to_string(path, level);
as_cstr = RSTRING_PTR(as_str);
if (!non_cache) {
if ((type == EXPAND_RELATIVE &&
rb_is_absolute_path(as_cstr)) ||
(type == EXPAND_HOME &&
(!as_cstr[0] || as_cstr[0] != '~')) ||
(type == EXPAND_NON_CACHE)) {
/* Use cached expanded path. */
rb_ary_push(ary, RARRAY_AREF(expanded_load_path, i));
continue;
}
}
if (!*has_relative && !rb_is_absolute_path(as_cstr))
*has_relative = 1;
if (!*has_non_cache && non_cache)
*has_non_cache = 1;
/* Freeze only string object. We expand other objects every time. */
if (is_string)
rb_str_freeze(path);
as_str = rb_get_path_check_convert(path, as_str, level);
expanded_path = rb_file_expand_path_fast(as_str, Qnil);
rb_str_freeze(expanded_path);
rb_ary_push(ary, rb_fstring(expanded_path));
}
rb_obj_freeze(ary);
vm->expanded_load_path = ary;
rb_ary_replace(vm->load_path_snapshot, vm->load_path);
}
开发者ID:scorpion007,项目名称:ruby,代码行数:53,代码来源:load.c
示例17: na_parse_enumerator
static void
na_parse_enumerator(VALUE enum_obj, int orig_dim, ssize_t size, na_index_arg_t *q)
{
int len;
ssize_t step;
struct enumerator *e;
if (!RB_TYPE_P(enum_obj, T_DATA)) {
rb_raise(rb_eTypeError,"wrong argument type (not T_DATA)");
}
e = (struct enumerator *)DATA_PTR(enum_obj);
if (rb_obj_is_kind_of(e->obj, rb_cRange)) {
if (e->meth == id_each) {
na_parse_range(e->obj, 1, orig_dim, size, q);
}
else if (e->meth == id_step) {
if (TYPE(e->args) != T_ARRAY) {
rb_raise(rb_eArgError,"no argument for step");
}
len = RARRAY_LEN(e->args);
if (len != 1) {
rb_raise(rb_eArgError,"invalid number of step argument (1 for %d)",len);
}
step = NUM2SSIZET(RARRAY_AREF(e->args,0));
na_parse_range(e->obj, step, orig_dim, size, q);
} else {
rb_raise(rb_eTypeError,"unknown Range method: %s",rb_id2name(e->meth));
}
} else {
rb_raise(rb_eTypeError,"not Range object");
}
}
开发者ID:kou,项目名称:narray,代码行数:33,代码来源:index.c
示例18: check_array_1d
static size_t
check_array_1d(VALUE item, size_t size) {
narray_t *na;
size_t i, len;
if (TYPE(item) == T_ARRAY) {
len = RARRAY_LEN(item);
if (size != len) {
return 0;
}
for (i=0; i<len; i++) {
if (!check_array(RARRAY_AREF(item,i))) {
return 0;
}
}
return 1;
}
if (RTEST(rb_obj_is_kind_of(item, cNArray))) {
GetNArray(item,na);
if (na->ndim == 1 && na->size == size) {
return 1;
} else {
return 0;
}
}
return 0;
}
开发者ID:metanest,项目名称:narray-devel,代码行数:27,代码来源:struct.c
示例19: nst_s_new
/*
Foo = Numo::Struct.new {
int8 :byte
float64 :float, [2,2]
dcomplex :compl
}
*/
static VALUE
nst_s_new(int argc, VALUE *argv, VALUE klass)
{
VALUE name=Qnil, rest, size;
VALUE st, members;
ID id;
rb_scan_args(argc, argv, "0*", &rest);
if (RARRAY_LEN(rest)>0) {
name = RARRAY_AREF(rest,0);
if (!NIL_P(name)) {
VALUE tmp = rb_check_string_type(name);
if (!NIL_P(tmp)) {
rb_ary_shift(rest);
} else {
name = Qnil;
}
}
}
if (NIL_P(name)) {
st = rb_define_class_id(name, klass);
rb_funcall(klass, rb_intern("inherited"), 1, st);
}
else {
char *cname = StringValuePtr(name);
id = rb_intern(cname);
if (!rb_is_const_id(id)) {
rb_name_error(id, "identifier %s needs to be constant", cname);
}
if (rb_const_defined_at(klass, id)) {
rb_warn("redefining constant Struct::%s", cname);
rb_mod_remove_const(klass, ID2SYM(id));
}
st = rb_define_class_under(klass, rb_id2name(id), klass);
}
rb_iv_set(st, "__members__", rb_ary_new());
rb_iv_set(st, "__offset__", INT2FIX(0));
if (rb_block_given_p()) {
rb_mod_module_eval(0, 0, st);
}
size = rb_iv_get(st, "__offset__");
members = rb_iv_get(st, "__members__");
//printf("size=%d\n",NUM2INT(size));
rb_define_const(st, CONTIGUOUS_STRIDE, size);
rb_define_const(st, ELEMENT_BYTE_SIZE, size);
rb_define_const(st, ELEMENT_BIT_SIZE, rb_funcall(size,'*',1,INT2FIX(8)));
OBJ_FREEZE(members);
rb_define_const(st, "DEFINITIONS", members);
rb_define_singleton_method(st, "new", rb_class_new_instance, -1);
//rb_define_singleton_method(st, "[]", rb_class_new_instance, -1);
rb_define_method(st, "allocate", nst_allocate, 0);
return st;
}
开发者ID:metanest,项目名称:narray-devel,代码行数:67,代码来源:struct.c
示例20: rb_HTTPRequest_response
VALUE
rb_HTTPRequest_response(VALUE self, VALUE argv){
VALUE evhttp_p = rb_funcall(self, rb_intern("magic_request_id"), 0);
VALUE r_code = rb_funcall(argv, rb_intern("code"), 0);
VALUE r_data = rb_funcall(argv, rb_intern("data"), 0);
VALUE r_header = rb_funcall(argv, rb_intern("headers"), 0);
Check_Type(r_code, T_FIXNUM);
Check_Type(r_data, T_STRING);
Check_Type(r_header, T_ARRAY);
long i = 0;
struct evbuffer *buf;
struct evhttp_request* req = (struct evhttp_request*)NUM2ULONG(evhttp_p);
buf = evbuffer_new();
evbuffer_add_printf(buf, "%s", StringValueCStr(r_data));
for(i = 0 ; i < RARRAY_LEN(r_header) ; i++){
VALUE header = RARRAY_AREF(r_header, i);
VALUE key = rb_funcall(header, rb_intern("key"), 0);
VALUE value = rb_funcall(header, rb_intern("value"), 0);
evhttp_add_header(req->output_headers, StringValueCStr(key), StringValueCStr(value));
}
evhttp_send_reply(req, FIX2INT(r_code), "OK", buf);
evbuffer_free(buf);
return self;
}
开发者ID:Passerby,项目名称:fsnet,代码行数:33,代码来源:rb_define.c
注:本文中的RARRAY_AREF函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论