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


C++ rb_ary_store函数代码示例

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


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

示例1: path_entries

/*
 * Return the entries (files and subdirectories) in the directory, each as a
 * Pathname object.
 *
 * The results contains just the names in the directory, without any trailing
 * slashes or recursive look-up.
 *
 *   pp Pathname.new('/usr/local').entries
 *   #=> [#<Pathname:share>,
 *   #    #<Pathname:lib>,
 *   #    #<Pathname:..>,
 *   #    #<Pathname:include>,
 *   #    #<Pathname:etc>,
 *   #    #<Pathname:bin>,
 *   #    #<Pathname:man>,
 *   #    #<Pathname:games>,
 *   #    #<Pathname:.>,
 *   #    #<Pathname:sbin>,
 *   #    #<Pathname:src>]
 *
 * The result may contain the current directory <code>#<Pathname:.></code> and
 * the parent directory <code>#<Pathname:..></code>.
 *
 * If you don't want +.+ and +..+ and
 * want directories, consider Pathname#children.
 */
static VALUE
path_entries(VALUE self)
{
    VALUE klass, str, ary;
    long i;
    klass = rb_obj_class(self);
    str = get_strpath(self);
    ary = rb_funcall(rb_cDir, rb_intern("entries"), 1, str);
    ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
    for (i = 0; i < RARRAY_LEN(ary); i++) {
        VALUE elt = RARRAY_PTR(ary)[i];
        elt = rb_class_new_instance(1, &elt, klass);
        rb_ary_store(ary, i, elt);
    }
    return ary;
}
开发者ID:takuto-h,项目名称:ruby,代码行数:42,代码来源:pathname.c

示例2: rb_gsl_function_fdf_set_fdf

static VALUE rb_gsl_function_fdf_set_fdf(VALUE obj, VALUE procfdf)
{
  gsl_function_fdf *F = NULL;
  VALUE ary;
  CHECK_PROC(procfdf);
  Data_Get_Struct(obj, gsl_function_fdf, F);
  if (F->params == NULL) {
    ary = rb_ary_new2(4);
    /*    (VALUE) F->params = ary;*/
    F->params = (void *) ary;
  } else {
    ary = (VALUE) F->params;
  }
  rb_ary_store(ary, 2, procfdf);
  return obj;
}
开发者ID:davidrichards,项目名称:rb-gsl,代码行数:16,代码来源:function.c

示例3: pgresult_fields

/*
 * call-seq:
 *    res.fields() -> Array
 *
 * Returns an array of Strings representing the names of the fields in the result.
 */
static VALUE
pgresult_fields(VALUE self)
{
	PGresult *result = pgresult_get( self );
	int n = PQnfields( result );
	VALUE fields = rb_ary_new2( n );
	int i;

	for ( i = 0; i < n; i++ ) {
		VALUE val = rb_tainted_str_new2(PQfname(result, i));
		ASSOCIATE_INDEX(val, self);
		rb_ary_store( fields, i, val );
	}

	return fields;
}
开发者ID:danielcode,项目名称:ruby-pg,代码行数:22,代码来源:pg_result.c

示例4: fetch_fields

/*	fetch_fields()	*/
static VALUE fetch_fields(VALUE obj)
{
    MYSQL_RES* res;
    MYSQL_FIELD* f;
    unsigned int n;
    VALUE ret;
    unsigned int i;
    check_free(obj);
    res = GetMysqlRes(obj);
    f = mysql_fetch_fields(res);
    n = mysql_num_fields(res);
    ret = rb_ary_new2(n);
    for (i=0; i<n; i++)
	rb_ary_store(ret, i, make_field_obj(&f[i]));
    return ret;
}
开发者ID:BackupTheBerlios,项目名称:dryon-svn,代码行数:17,代码来源:mysql.c

示例5: type_interfaces

static VALUE
type_interfaces(VALUE self)
{
    guint n_interfaces;
    GType* types;
    VALUE result;
    int i;

    types = g_type_interfaces(rbgobj_gtype_get(self), &n_interfaces);
    result = rb_ary_new2(n_interfaces);
    for (i = 0; i < n_interfaces; i++)
        rb_ary_store(result, i, rbgobj_gtype_new(types[i]));
    g_free(types);

    return result;
}
开发者ID:benolee,项目名称:ruby-gnome2,代码行数:16,代码来源:rbgobj_type.c

示例6: read_large_tuple

VALUE read_large_tuple(unsigned char **pData) {
  if(read_1(pData) != ERL_LARGE_TUPLE) {
    rb_raise(rb_eStandardError, "Invalid Type, not a large tuple");
  }

  int arity = read_4(pData);

  VALUE array = rb_ary_new2(arity);

  int i;
  for(i = 0; i < arity; ++i) {
    rb_ary_store(array, i, read_any_raw(pData));
  }

  return array;
}
开发者ID:auser,项目名称:erlectricity,代码行数:16,代码来源:decoder.c

示例7: Message_to_h

/*
 * call-seq:
 *     Message.to_h => {}
 *
 * Returns the message as a Ruby Hash object, with keys as symbols.
 */
VALUE Message_to_h(VALUE _self) {
  MessageHeader* self;
  VALUE hash;
  upb_msg_field_iter it;
  TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);

  hash = rb_hash_new();

  for (upb_msg_field_begin(&it, self->descriptor->msgdef);
       !upb_msg_field_done(&it);
       upb_msg_field_next(&it)) {
    const upb_fielddef* field = upb_msg_iter_field(&it);

    // For proto2, do not include fields which are not set.
    if (upb_msgdef_syntax(self->descriptor->msgdef) == UPB_SYNTAX_PROTO2 &&
	field_contains_hasbit(self->descriptor->layout, field) &&
	!layout_has(self->descriptor->layout, Message_data(self), field)) {
      continue;
    }

    VALUE msg_value = layout_get(self->descriptor->layout, Message_data(self),
                                 field);
    VALUE msg_key   = ID2SYM(rb_intern(upb_fielddef_name(field)));
    if (is_map_field(field)) {
      msg_value = Map_to_h(msg_value);
    } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
      msg_value = RepeatedField_to_ary(msg_value);
      if (upb_msgdef_syntax(self->descriptor->msgdef) == UPB_SYNTAX_PROTO2 &&
          RARRAY_LEN(msg_value) == 0) {
        continue;
      }

      if (upb_fielddef_type(field) == UPB_TYPE_MESSAGE) {
        for (int i = 0; i < RARRAY_LEN(msg_value); i++) {
          VALUE elem = rb_ary_entry(msg_value, i);
          rb_ary_store(msg_value, i, Message_to_h(elem));
        }
      }

    } else if (msg_value != Qnil &&
               upb_fielddef_type(field) == UPB_TYPE_MESSAGE) {
      msg_value = Message_to_h(msg_value);
    }
    rb_hash_aset(hash, msg_key, msg_value);
  }
  return hash;
}
开发者ID:hack0303,项目名称:protobuf,代码行数:53,代码来源:message.c

示例8: objectid_from_string

static VALUE objectid_from_string(VALUE self, VALUE str)
{
    VALUE oid;
    int i;

    if (!legal_objectid_str(str)) {
        rb_raise(InvalidObjectId, "illegal ObjectId format: %s", RSTRING_PTR(str));
    }

    oid = rb_ary_new2(12);

    for(i = 0; i < 12; i++) {
        rb_ary_store(oid, i, INT2FIX( (unsigned)(hexbyte( RSTRING_PTR(str)[2*i] ) << 4 ) | hexbyte( RSTRING_PTR(str)[2*i + 1] )));
    }

    return rb_class_new_instance(1, &oid, ObjectId);
}
开发者ID:DanPatey,项目名称:TeleSign-QA,代码行数:17,代码来源:cbson.c

示例9: rb_mysql_result_fetch_field

static VALUE rb_mysql_result_fetch_field(VALUE self, unsigned int idx, short int symbolize_keys) {
  mysql2_result_wrapper * wrapper;
  VALUE rb_field;
  GetMysql2Result(self, wrapper);

  if (wrapper->fields == Qnil) {
    wrapper->numberOfFields = mysql_num_fields(wrapper->result);
    wrapper->fields = rb_ary_new2(wrapper->numberOfFields);
  }

  rb_field = rb_ary_entry(wrapper->fields, idx);
  if (rb_field == Qnil) {
    MYSQL_FIELD *field = NULL;
#ifdef HAVE_RUBY_ENCODING_H
    rb_encoding *default_internal_enc = rb_default_internal_encoding();
    rb_encoding *conn_enc = rb_to_encoding(wrapper->encoding);
#endif

    field = mysql_fetch_field_direct(wrapper->result, idx);
    if (symbolize_keys) {
      char buf[field->name_length+1];
      memcpy(buf, field->name, field->name_length);
      buf[field->name_length] = 0;

#ifdef HAVE_RB_INTERN3
      rb_field = rb_intern3(buf, field->name_length, rb_utf8_encoding());
      rb_field = ID2SYM(rb_field);
#else
      VALUE colStr;
      colStr = rb_str_new2(buf);
      rb_field = ID2SYM(rb_to_id(colStr));
#endif
    } else {
      rb_field = rb_str_new(field->name, field->name_length);
#ifdef HAVE_RUBY_ENCODING_H
      rb_enc_associate(rb_field, conn_enc);
      if (default_internal_enc) {
        rb_field = rb_str_export_to_enc(rb_field, default_internal_enc);
      }
#endif
    }
    rb_ary_store(wrapper->fields, idx, rb_field);
  }

  return rb_field;
}
开发者ID:GromBacher,项目名称:mysql2,代码行数:46,代码来源:result.c

示例10: read_string

VALUE read_string(unsigned char **pData) {
  if(read_1(pData) != ERL_STRING) {
    rb_raise(rb_eStandardError, "Invalid Type, not an erlang string");
  }

  int length = read_2(pData);
  VALUE newref_class = rb_const_get(mErlectricity, rb_intern("List"));
  VALUE array = rb_funcall(newref_class, rb_intern("new"), 1, INT2NUM(length));

  int i = 0;
  for(i; i < length; ++i) {
    rb_ary_store(array, i, INT2NUM(**pData));
    *pData += 1;
  }

  return array;
}
开发者ID:irvingpop,项目名称:erlectricity,代码行数:17,代码来源:decoder.c

示例11: ta_func_setup_out_integer

static VALUE ta_func_setup_out_integer(VALUE self, VALUE param_index, VALUE out_array)
{
  TA_RetCode ret_code;
  ParamHolder *param_holder;
  long idx = FIX2INT(param_index);
  if (idx > 2)
    rb_raise(rb_eRuntimeError, "param_index must be 0..2");
  Data_Get_Struct(self, ParamHolder, param_holder);
  rb_ary_store(rb_iv_get(self, "@result"), idx, out_array);
  // FIXME: malloc w/o free FIXED: [email protected]
  int **ip = &(param_holder->out_int[idx]);
  if (*ip) free(*ip); // not true only very 1st time in
  *ip = (int*)malloc(RARRAY_LEN(out_array) * sizeof(int));
  ret_code=TA_SetOutputParamIntegerPtr( param_holder->p, idx, *ip);
  if ( ret_code != TA_SUCCESS )
    rb_raise(rb_eRuntimeError, "unsuccess return code TA_SetOutputParamIntegerPtr");
}
开发者ID:edbond,项目名称:talib-ruby,代码行数:17,代码来源:talib.c

示例12: r_mpfi_matrix_str_ary_for_inspect

/* Return one dimensinal array which has strings converted elements to. */
static VALUE r_mpfi_matrix_str_ary_for_inspect (VALUE self) {
  MPFIMatrix *ptr_self;
  char *tmp_str;
  VALUE ret_ary;
  int i;
  r_mpfi_get_matrix_struct(ptr_self, self);
  ret_ary = rb_ary_new2(ptr_self->size);
  for (i = 0; i < ptr_self->size; i++) {
    if (!mpfr_asprintf(&tmp_str, "%.Re %.Re",
                       r_mpfi_left_ptr((ptr_self->data + i)), r_mpfi_right_ptr(ptr_self->data + i))) {
      rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
    }
    rb_ary_store(ret_ary, i, rb_str_new2(tmp_str));
    mpfr_free_str(tmp_str);
  }
  return ret_ary;
}
开发者ID:ytaka,项目名称:ruby-mpfi,代码行数:18,代码来源:ruby_mpfi_matrix.c

示例13: shoes_menu_append

// Add menuitem to the menu at the end
VALUE shoes_menu_append(VALUE self, VALUE miv) {
  shoes_menu *mn;
  shoes_menuitem *mi;
  Data_Get_Struct(self, shoes_menu, mn);
  if (rb_obj_is_kind_of(miv, cShoesMenuitem)) {
    Data_Get_Struct(miv, shoes_menuitem, mi);
    mi->parent = mn;
    shoes_native_menu_append(mn, mi);
    int cnt = RARRAY_LEN(mn->items);
    rb_ary_store(mn->items, cnt, miv);
  } else if (rb_obj_is_kind_of(miv, cShoesMenu)) {
    rb_raise(rb_eArgError, "menu cannot be appended to menu");
  } else {
    rb_raise(rb_eArgError, "not a menuitem");
  }
  return self;
}
开发者ID:Shoes3,项目名称:shoes3,代码行数:18,代码来源:menu.c

示例14: bert_read_string

static VALUE bert_read_string(struct bert_buf *buf)
{
	uint16_t i, length;
	VALUE rb_string;

	bert_buf_ensure(buf, 2);
	length = bert_buf_read16(buf);

	bert_buf_ensure(buf, length);
	rb_string = rb_ary_new2(length);

	for (i = 0; i < length; ++i)
		rb_ary_store(rb_string, i, INT2FIX(buf->data[i]));

	buf->data += length;
	return rb_string;
}
开发者ID:HumbleRepose,项目名称:bert,代码行数:17,代码来源:decode.c

示例15: ta_func_setup_out_real

/*
 * call-seq: out_real(index, array)
 *
 * Set output parameter (array of real) for the given parameter index.
 */
static VALUE ta_func_setup_out_real(VALUE self, VALUE param_index, VALUE out_array)
{
  TA_RetCode ret_code;
  ParamHolder *param_holder;
  long idx = FIX2INT(param_index);
  if (idx > 2)
    rb_raise(rb_eRuntimeError, "param_index must be 0..2");
  Data_Get_Struct(self, ParamHolder, param_holder);
  rb_ary_store(rb_iv_get(self, "@result"), idx, out_array);
  // FIXME: malloc w/o free: [email protected] fixed
  double **dp = &(param_holder->out[idx]);
  if (*dp) free(*dp); // not true only 1st time called (reusing same ptrs)
  *dp = (double*)malloc(RARRAY_LEN(out_array) * sizeof(double));
  ret_code = TA_SetOutputParamRealPtr(param_holder->p, idx, *dp);
  if ( ret_code != TA_SUCCESS )
    rb_raise(rb_eRuntimeError, "unsuccess return code TA_SetOutputParamRealPtr");
}
开发者ID:edbond,项目名称:talib-ruby,代码行数:22,代码来源:talib.c


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