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


C++ RARRAY函数代码示例

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


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

示例1: rb2GimpParamDefs

GimpParamDef *
rb2GimpParamDefs (VALUE rbparamdefs,
                  gint  *count)
{
  if (rbparamdefs == Qnil)
    {
      *count = 0;
      return NULL;
    }
  else
    {
        Check_Type(rbparamdefs, T_ARRAY);

      int num = RARRAY_LEN(RARRAY(rbparamdefs));
      VALUE *arr = RARRAY_PTR(RARRAY(rbparamdefs));

      GimpParamDef *gimpparamdefs = g_new(GimpParamDef, num);

      int i;
      for(i=0; i<num; i++)
        gimpparamdefs[i] = rb2GimpParamDef(arr[i]);

      *count = (gint)num;
      return gimpparamdefs;
    }
}
开发者ID:antono,项目名称:gimp-ruby,代码行数:26,代码来源:conversion.c

示例2: mrb_ary_cmp

/*
 *  call-seq:
 *     ary <=> other_ary   ->  -1, 0, +1 or nil
 *
 *  Comparison---Returns an integer (-1, 0, or +1)
 *  if this array is less than, equal to, or greater than <i>other_ary</i>.
 *  Each object in each array is compared (using <=>). If any value isn't
 *  equal, then that inequality is the return value. If all the
 *  values found are equal, then the return is based on a
 *  comparison of the array lengths.  Thus, two arrays are
 *  ``equal'' according to <code>Array#<=></code> if and only if they have
 *  the same length and the value of each element is equal to the
 *  value of the corresponding element in the other array.
 *
 *     [ "a", "a", "c" ]    <=> [ "a", "b", "c" ]   #=> -1
 *     [ 1, 2, 3, 4, 5, 6 ] <=> [ 1, 2 ]            #=> +1
 *
 */
mrb_value
mrb_ary_cmp(mrb_state *mrb, mrb_value ary1)
{
  mrb_value ary2;
  struct RArray *a1, *a2;
  mrb_value r = mrb_nil_value();
  int i, len;

  mrb_get_args(mrb, "o", &ary2);
  if (mrb_type(ary2) != MRB_TT_ARRAY) return mrb_nil_value();
  a1 = RARRAY(ary1); a2 = RARRAY(ary2);
  if (a1->len == a2->len && a1->ptr == a2->ptr) return mrb_fixnum_value(0);
  else {
    len = RARRAY_LEN(ary1);
    if (len > RARRAY_LEN(ary2)) {
      len = RARRAY_LEN(ary2);
    }
    for (i=0; i<len; i++) {
      r = mrb_funcall(mrb, ary_elt(ary1, i), "<=>", 1, ary_elt(ary2, i));
      if (mrb_type(r) != MRB_TT_FIXNUM || mrb_fixnum(r) != 0) return r;
    }
  }
  len = a1->len - a2->len;
  return mrb_fixnum_value((len == 0)? 0: (len > 0)? 1: -1);
}
开发者ID:galois17,项目名称:mruby,代码行数:43,代码来源:array.c

示例3: ossl_x509crl_set_extensions

/*
 * Sets X509_EXTENSIONs
 */
static VALUE 
ossl_x509crl_set_extensions(VALUE self, VALUE ary)
{
    X509_CRL *crl;
    X509_EXTENSION *ext;
    int i;
	
    Check_Type(ary, T_ARRAY);
    /* All ary members should be X509 Extensions */
    for (i=0; i<RARRAY(ary)->len; i++) {
	OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext);
    }
    GetX509CRL(self, crl);
    sk_X509_EXTENSION_pop_free(crl->crl->extensions, X509_EXTENSION_free);
    crl->crl->extensions = NULL;
    for (i=0; i<RARRAY(ary)->len; i++) {
	ext = DupX509ExtPtr(RARRAY(ary)->ptr[i]);
	if(!X509_CRL_add_ext(crl, ext, -1)) { /* DUPs ext - FREE it */
	    X509_EXTENSION_free(ext);
	    ossl_raise(eX509CRLError, NULL);
	}
	X509_EXTENSION_free(ext);
    }

    return ary;
}
开发者ID:FooBarWidget,项目名称:rubyenterpriseedition,代码行数:29,代码来源:ossl_x509crl.c

示例4: rbosa_elementlist_new

static VALUE
rbosa_elementlist_new (int argc, VALUE *argv, VALUE self)
{
    OSErr           error;
    AEDescList      list;
    VALUE           ary;
    int             i;

    rb_scan_args (argc, argv, "01", &ary);

    if (!NIL_P (ary))
        Check_Type (ary, T_ARRAY);

    error = AECreateList (NULL, 0, false, &list);
    if (error != noErr) 
        rb_raise (rb_eRuntimeError, "Cannot create Apple Event descriptor list : %s (%d)", 
                  error_code_to_string (error), error);

    if (!NIL_P (ary)) {
        for (i = 0; i < RARRAY (ary)->len; i++)
            __rbosa_elementlist_add (&list, RARRAY (ary)->ptr[i], i + 1); 
    }
    
    return rbosa_element_make (self, &list, Qnil);
}
开发者ID:bmorton,项目名称:rubyosa,代码行数:25,代码来源:rbosa.c

示例5: ossl_x509crl_set_revoked

static VALUE 
ossl_x509crl_set_revoked(VALUE self, VALUE ary)
{
    X509_CRL *crl;
    X509_REVOKED *rev;
    int i;

    Check_Type(ary, T_ARRAY);
    /* All ary members should be X509 Revoked */
    for (i=0; i<RARRAY(ary)->len; i++) {
	OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Rev);
    }
    GetX509CRL(self, crl);
    sk_X509_REVOKED_pop_free(crl->crl->revoked, X509_REVOKED_free);
    crl->crl->revoked = NULL;
    for (i=0; i<RARRAY(ary)->len; i++) {
	rev = DupX509RevokedPtr(RARRAY(ary)->ptr[i]);
	if (!X509_CRL_add0_revoked(crl, rev)) { /* NO DUP - don't free! */
	    ossl_raise(eX509CRLError, NULL);
	}
    }
    X509_CRL_sort(crl);

    return ary;
}
开发者ID:FooBarWidget,项目名称:rubyenterpriseedition,代码行数:25,代码来源:ossl_x509crl.c

示例6: munge_xpath_namespace

VALUE munge_xpath_namespace( VALUE orig_expr, xmlChar *root_ns )
{
	VALUE path_bits = rb_str_split( orig_expr, "/" );
	VALUE ns_prefix = rb_str_new2( (const char*)root_ns );
	VALUE ns_indic = rb_str_new2( ":" );
	VALUE slash = rb_str_new2( "/" );
	VALUE path_bit, str_idx;
	VALUE ret_ary = rb_ary_new();
	long i;
	
	rb_str_append( ns_prefix, ns_indic );
    for (i=0; i<RARRAY(path_bits)->len; i++) {
        path_bit = RARRAY(path_bits)->ptr[i];
		
		if (RSTRING_LEN(path_bit) > 0) {
			str_idx = rb_funcall( path_bit, rb_intern( "index" ), 1, ns_indic );
			if (str_idx == Qnil || str_idx == Qfalse) // didn't find the :, so it looks like we don't have a namespace
				path_bit = rb_str_plus( ns_prefix, path_bit );
		}	
		
		rb_ary_push( ret_ary, path_bit );
    }
	
	return rb_ary_join( ret_ary, slash );
}
开发者ID:segfault,项目名称:fastxml,代码行数:25,代码来源:fastxml.c

示例7: rb_gsl_blas_drotm2

static VALUE rb_gsl_blas_drotm2(VALUE obj, VALUE xx, VALUE yy, VALUE PP)
{
  gsl_vector *x = NULL, *y = NULL, *p = NULL, *xnew = NULL, *ynew = NULL;
  int flag = 0, i;
  CHECK_VECTOR(xx);
  CHECK_VECTOR(yy);
  Data_Get_Struct(xx, gsl_vector, x);
  Data_Get_Struct(yy, gsl_vector, y);
  if (rb_obj_is_kind_of(PP, cgsl_vector)) {
    Data_Get_Struct(PP, gsl_vector, p);
  } else {
    if (TYPE(PP) != T_ARRAY) rb_raise(rb_eTypeError, "wrong argument type %s (Array of Vector expected", rb_class2name(CLASS_OF(PP)));
    p = gsl_vector_alloc(RARRAY(PP)->len);
    for (i = 0; i < RARRAY(PP)->len; i++) {
      gsl_vector_set(p, i, rb_ary_entry(PP, i));
    }
    flag = 1;
  }
  xnew = gsl_vector_alloc(x->size);
  ynew = gsl_vector_alloc(y->size);
  gsl_vector_memcpy(xnew, x);
  gsl_vector_memcpy(ynew, y);
  gsl_blas_drotm(xnew, ynew, p->data);
  if (flag == 1) gsl_vector_free(p);
  return rb_ary_new3(2, Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, xnew),
		     Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, ynew));
}
开发者ID:davidrichards,项目名称:rb-gsl,代码行数:27,代码来源:blas1.c

示例8: dnssd_tr_encode

static VALUE
dnssd_tr_encode(VALUE self)
{
	long i;
	VALUE buf;
	/* Declare ary volatile to prevent it from being reclaimed when:
	 * buf is allocated later, key/values are converted to strings */
	volatile VALUE ary = rb_funcall2(self, rb_intern("to_a"), 0, 0);
	/* array of key, value pairs */
	VALUE *ptr = RARRAY(ary)->ptr;
	
	buf = rb_str_buf_new(dnssd_tr_convert_pairs(ary));
	for(i=0; i<RARRAY(ary)->len; i++) {
		uint8_t len;
		VALUE key = RARRAY(ptr[i])->ptr[0];
		VALUE value = RARRAY(ptr[i])->ptr[1];
		if (!NIL_P(value)) {
			len = (uint8_t)(RSTRING(key)->len + RSTRING(value)->len + 1);
			rb_str_buf_cat(buf, &len, 1);
			rb_str_buf_append(buf, key);
			rb_str_buf_cat(buf, "=", 1);
			rb_str_buf_append(buf, value);	
		} else {
			len = (uint8_t)RSTRING(key)->len;
			rb_str_buf_cat(buf, &len, 1);
			rb_str_buf_append(buf, key);
		}
	}
	return buf;
}
开发者ID:lachie,项目名称:zeroconf,代码行数:30,代码来源:rdnssd_tr.c

示例9: og_oniguruma_match_offset

/*
 * Document-method: offset
 *
 * call-seq:
 *    mtch.offset(n)      => array
 *    mtch.offset         => array
 *    mtch.offset(symbol) => array
 *
 * Returns a two-element array containing the beginning and ending offsets of
 * the <em>n</em>th match.
 *
 *    m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
 *    m.offset(0)   #=> [1, 7]
 *    m.offset(4)   #=> [6, 7]
 *
 * If no arguments are given, the offsets of the entire
 * sequence are returned.
 *
 *    m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
 *    m.offset      #=> [1, 7]
 *
 * If the argument is a symbol, then the offsets of the
 * corresponding named group are returned, or <code>nil</code>
 * if the group does not exist.
 *
 *    m = ORegexp.new( '(?<begin>^.*?)(?<middle>\d)(?<end>.*)' ).match("THX1138")
 *    m.end(:middle) #=> [3, 4]
 */
static VALUE
og_oniguruma_match_offset(int argc, VALUE *argv, VALUE self)
{
  VALUE idx, first, k, nargv[2];
  
  rb_scan_args(argc, argv, "0*", &idx);
  
  first = rb_ary_entry(idx, 0);
  if (SYMBOL_P(first)) {
    k = og_oniguruma_match_to_index(self, first);
    if (!NIL_P(k)) {
      nargv[0] = k;
      nargv[1] = (VALUE)NULL;
      
      return rb_funcall3(self, rb_intern("offset_without_oniguruma"), 1, nargv);
    } else
      return Qnil;
  } else if (RARRAY(idx)->len == 0) {
    nargv[0] = INT2FIX(0);
    nargv[1] = (VALUE)NULL;
    
    return rb_funcall3(self, rb_intern("offset_without_oniguruma"), 1, nargv);
  }
  
  return rb_funcall3(self, rb_intern("offset_without_oniguruma"), RARRAY(idx)->len, RARRAY(idx)->ptr);
}
开发者ID:Smily1984,项目名称:oniguruma,代码行数:54,代码来源:rb_oniguruma_ext_match.c

示例10: ruby_to_value

static value_t* ruby_to_value(VALUE v)
{
  switch (TYPE(v)) {
    case T_NIL:
      return value_new_void();
    case T_BIGNUM:
    case T_FIXNUM:
      return value_new_int32(NUM2INT(v));
    case T_TRUE:
      return value_new_boolean(true);
    case T_FALSE:
      return value_new_boolean(false);
    case T_FLOAT:
      return value_new_float32(NUM2DBL(v));
    case T_SYMBOL:
      return value_new_string(rb_id2name(SYM2ID(v)));
    case T_STRING:
      return value_new_string(StringValuePtr(v));
    case T_ARRAY: {
      /* process Array */
      value_t*array = array_new();
      int len = RARRAY(v)->len;
      int i;
      for(i=0;i<len;i++) {
          volatile VALUE item = RARRAY(v)->ptr[i];
          array_append(array, ruby_to_value(item));
      }
      return array;
    }
    default:
      /* raise exception */
      rb_raise(rb_eTypeError, "not valid value");
  }
}
开发者ID:luiseduardohdbackup,项目名称:cagekeeper,代码行数:34,代码来源:language_rb.c

示例11: compare_arrays

static VALUE compare_arrays(VALUE a, VALUE b, fun_array_cmp cmp) {
  struct array_comparison result = { 0, 0, RARRAY(a)->len, RARRAY(b)->len };
  long * long_a;
  long * long_b;
  int i, j;
  
  result.union_size = result.a_size + result.b_size;
  
  if((result.a_size > 0) && (result.b_size > 0))
  {
    COPYRUBYHASHARRAY(a, long_a);
    COPYRUBYHASHARRAY(b, long_b);
    
    for(i = 0; i < result.a_size; ++i)
    {
      for(j = 0; j < result.b_size; ++j)
      {
        if(long_a[i] == long_b[j])
        {
          result.intersection_size++;
        }
      }
    }
    
  }
  
  return rb_float_new((*cmp)(result));
}
开发者ID:codahale,项目名称:ruby-gsl,代码行数:28,代码来源:Similarity.c

示例12: parse

static void
parse(pairmatcher_t *pm, VALUE tokenizer, VALUE reporter)
{
  VALUE token_info;
  while ((token_info = get_token(tokenizer)) != Qnil) {
    VALUE token_type, token_text, token_lineno, token_byteno;
    VALUE token;
    Check_Type(token_info, T_ARRAY);
    if (RARRAY(token_info)->len != 8) {
      rb_raise(rb_eArgError, "unexpected token");
    }
    token_type = RARRAY(token_info)->ptr[0];
    token_text = RARRAY(token_info)->ptr[1];
    token_lineno = RARRAY(token_info)->ptr[2];
    token_byteno = RARRAY(token_info)->ptr[4];
    token = rb_funcall(Fragment, id_new, 4, token_type, token_text, token_lineno, token_byteno);
    if (intertoken_p(pm, token_type)) {
      rb_funcall(reporter, id_call, 1, token);
    }
    else {
      put_token(pm, token, reporter);
    }
  }
  finish(pm, reporter);
}
开发者ID:sonsongithub,项目名称:sonson,代码行数:25,代码来源:pairmatcher.c

示例13: coverage_increase_counter_uncached

static struct cov_array * coverage_increase_counter_uncached(char *sourcefile, unsigned int sourceline, char mark_only) {
  struct cov_array *carray = NULL;
 
  if(sourcefile == NULL) {
    /* "can't happen", just ignore and avoid segfault */
    return NULL;
  } 
  else if(!st_lookup(coverinfo, (st_data_t)sourcefile, (st_data_t*)&carray)) {
    VALUE arr;
    
    arr = rb_hash_aref(oSCRIPT_LINES__, rb_str_new2(sourcefile));
    if(NIL_P(arr)) 
      return 0;
    rb_check_type(arr, T_ARRAY);
    carray = calloc(1, sizeof(struct cov_array));
    carray->ptr = calloc(RARRAY(arr)->len, sizeof(unsigned int));
    carray->len = RARRAY(arr)->len;
    st_insert(coverinfo, (st_data_t)strdup(sourcefile), (st_data_t) carray);
  } 
  else {
    /* recovered carray, sanity check */
    assert(carray && "failed to create valid carray");
  }

  if(mark_only) {
    if(!carray->ptr[sourceline])
      carray->ptr[sourceline] = 1;
  } else {
    if (carray && carray->len > sourceline) {
      carray->ptr[sourceline]++;
    }
  }

  return carray;
}
开发者ID:CoralineAda,项目名称:rcov,代码行数:35,代码来源:rcovrt.c

示例14: rb_iv_get

octave_value OR_StructMatrix::to_octave()
{
  int i, row_index, column_index;
  VALUE row, cell;
  VALUE cells = rb_iv_get(ruby_val, "@cells");
  VALUE names = rb_iv_get(ruby_val, "@names");
  int number_of_keys = RARRAY(names)->len;
  int number_of_rows = FIX2INT(rb_iv_get(ruby_val, "@m"));
  int number_of_columns = FIX2INT(rb_iv_get(ruby_val, "@n"));

  string_vector keys = string_vector();
  for (i = 0; i < number_of_keys; i++) {
    keys.append(std::string(RSTRING(RARRAY(names)->ptr[i])->ptr));
  }
  
  Octave_map struct_matrix = Octave_map(dim_vector(number_of_rows, number_of_columns), Cell(keys));
  for (row_index = 0; row_index < number_of_rows; row_index++) {
    row = RARRAY(cells)->ptr[row_index];
  
    for (column_index = 0; column_index < number_of_columns; column_index++) {
      cell = RARRAY(row)->ptr[column_index];
      
      for (i = 0; i < number_of_keys; i++) {
        struct_matrix.contents(std::string(RSTRING(RARRAY(names)->ptr[i])->ptr))(row_index, column_index) = OR_Variable(rb_hash_aref(cell, rb_str_new2(RSTRING(RARRAY(names)->ptr[i])->ptr))).to_octave();
      }
    }
  }
  
  return struct_matrix;
}
开发者ID:apohllo,项目名称:octave-ruby,代码行数:30,代码来源:or-struct_matrix.cpp

示例15: union_list

/**
@method union_list( array_of_rects )
Returns a new array representing a rectangle covering all rectangles
in @array_of_rects.
*/
static VALUE rb_array_union_list(VALUE self, VALUE other_rects)
{
	int i;
	double left;
	double right;
	double top;
	double bottom;
	double l,r,t,b;
	VALUE rect;

	if(RARRAY(other_rects)->len==0){
		return Qnil;
	}

	rect=rb_ary_entry(other_rects, 0);
	left=array_get_x(rect);
	right=array_get_w(rect)+left;
	top=array_get_y(rect);
	bottom=array_get_h(rect)+top;

	for(i=1; i<RARRAY(other_rects)->len; i++){
		rect=rb_ary_entry(other_rects, i);
		l=array_get_x(rect);
		r=array_get_w(rect)+l;
		t=array_get_y(rect);
		b=array_get_h(rect)+t;
		left=RUDL_MIN(left, l);
		right=RUDL_MAX(right, r);
		top=RUDL_MIN(top, t);
		bottom=RUDL_MAX(bottom, b);
	}

	return new_rect(left, top, right-left, bottom-top);
}
开发者ID:matozoid,项目名称:rudl,代码行数:39,代码来源:rudl_video_rect.c


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