本文整理汇总了C++中rb_iv_set函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_iv_set函数的具体用法?C++ rb_iv_set怎么用?C++ rb_iv_set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_iv_set函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RDATA
VALUE Field::init_copy(VALUE copy, VALUE orig) {
//Copy this object to a new one. Open the cap file again
Field* FieldCopy = NULL;
Field* FieldOrig = NULL;
if (copy == orig) {
return copy;
}
if(TYPE(orig)!=T_DATA ||
RDATA(orig)->dfree!=(RUBY_DATA_FUNC)Field::free) {
rb_raise(rb_eTypeError, "Wrong argument type");
}
Data_Get_Struct(copy, Field, FieldCopy);
Data_Get_Struct(orig, Field, FieldOrig);
//Copy the Ruby property @packet, then copy the native Field objects too
rb_iv_set(copy, "@packet", rb_iv_get(orig, "@packet"));
*FieldCopy = *FieldOrig;
return copy;
}
示例2: cSedna_initialize
/* :nodoc:
*
* Initialize a new instance of Sedna. Undocumented, because Sedna.connect should
* be used instead.
*/
static VALUE cSedna_initialize(VALUE self, VALUE options)
{
VALUE host_k, db_k, user_k, pw_k,
host_v, db_v, user_v, pw_v;
char *host, *db, *user, *pw;
// Ensure the argument is a Hash.
Check_Type(options, T_HASH);
// Store the symbols of the valid hash keys.
host_k = ID2SYM(rb_intern("host"));
db_k = ID2SYM(rb_intern("database"));
user_k = ID2SYM(rb_intern("username"));
pw_k = ID2SYM(rb_intern("password"));
// Get the connection details or set them to the default values if not given.
if(NIL_P(host_v = rb_hash_aref(options, host_k))) host = strdup(DEFAULT_HOST); else host = StringValuePtr(host_v);
if(NIL_P(db_v = rb_hash_aref(options, db_k ))) db = strdup(DEFAULT_DB); else db = StringValuePtr(db_v);
if(NIL_P(user_v = rb_hash_aref(options, user_k))) user = strdup(DEFAULT_USER); else user = StringValuePtr(user_v);
if(NIL_P(pw_v = rb_hash_aref(options, pw_k ))) pw = strdup(DEFAULT_PW); else pw = StringValuePtr(pw_v);
// Save all connection details to instance variables.
rb_iv_set(self, IV_HOST, rb_str_new2(host));
rb_iv_set(self, IV_DB, rb_str_new2(db));
rb_iv_set(self, IV_USER, rb_str_new2(user));
rb_iv_set(self, IV_PW, rb_str_new2(pw));
#ifdef NON_BLOCKING
// Create a mutex if this build supports non-blocking queries.
rb_iv_set(self, IV_MUTEX, rb_mutex_new());
#endif
// Connect to the database.
SCA c = { sedna_struct(self), host, db, user, pw };
sedna_connect(self, &c);
// Initialize @autocommit to true.
rb_iv_set(self, IV_AUTOCOMMIT, Qtrue);
return self;
}
示例3: ossl_x509store_initialize
/*
* call-seq:
* X509::Store.new => store
*
*/
static VALUE
ossl_x509store_initialize(int argc, VALUE *argv, VALUE self)
{
X509_STORE *store;
/* BUG: This method takes any number of arguments but appears to ignore them. */
GetX509Store(self, store);
X509_STORE_set_verify_cb_func(store, ossl_verify_cb);
ossl_x509store_set_vfy_cb(self, Qnil);
#if (OPENSSL_VERSION_NUMBER < 0x00907000L)
rb_iv_set(self, "@flags", INT2NUM(0));
rb_iv_set(self, "@purpose", INT2NUM(0));
rb_iv_set(self, "@trust", INT2NUM(0));
#endif
/* last verification status */
rb_iv_set(self, "@error", Qnil);
rb_iv_set(self, "@error_string", Qnil);
rb_iv_set(self, "@chain", Qnil);
rb_iv_set(self, "@time", Qnil);
return self;
}
示例4: birch_initialize
/*
* Initialize the node with its value and id.
* Setup containers for the children, features
* and dependencies of this node.
*/
static VALUE birch_initialize(VALUE self, VALUE value, VALUE id)
{
VALUE parent;
VALUE children;
VALUE children_hash;
VALUE features;
VALUE edges;
parent = Qnil;
children = rb_ary_new();
children_hash = rb_hash_new();
features = rb_hash_new();
edges = rb_ary_new();
rb_iv_set(self, "@value", value);
rb_iv_set(self, "@id", id);
rb_iv_set(self, "@parent", parent);
rb_iv_set(self, "@children", children);
rb_iv_set(self, "@children_hash", children_hash);
rb_iv_set(self, "@features", features);
rb_iv_set(self, "@edges", edges);
return self;
}
示例5: rb_iv_set
// RenderStates#initialize_copy(state)
VALUE rbRenderStates::InitializeCopy( VALUE aSelf, VALUE aState )
{
sf::RenderStates* states = rbRenderStates::ToSFML( aSelf );
*states = *rbRenderStates::ToSFML( aState );
VALUE transform = rbMacros::ToRubyNoGC( &states->transform, rbTransform::Class );
rb_iv_set( aSelf, "@__ref__transform", transform );
rb_iv_set( transform, "@__ref__state_owner", aSelf );
rb_obj_freeze( transform );
VALUE texture = rbMacros::ToRubyNoGC( const_cast< sf::Texture* >( states->texture ), rbTexture::Class );
rb_iv_set( aSelf, "@__ref__texture", texture );
rb_iv_set( texture, "@__ref__state_owner", aSelf );
rb_obj_freeze( texture );
VALUE shader = rbMacros::ToRubyNoGC( const_cast< sf::Shader* >( states->shader ), rbShader::Class );
rb_iv_set( aSelf, "@__ref__shader", shader );
rb_iv_set( shader, "@__ref__state_owner", aSelf );
rb_obj_freeze( shader );
return aSelf;
}
示例6: nstruct_add_type
static VALUE
nstruct_add_type(VALUE type, int argc, VALUE *argv, VALUE nst)
{
VALUE ofs, size;
ID id;
int i;
VALUE name=Qnil;
size_t *shape=NULL;
int ndim=0;
ssize_t stride;
narray_view_t *nt;
int j;
for (i=0; i<argc; i++) {
switch(TYPE(argv[i])) {
case T_STRING:
case T_SYMBOL:
if (NIL_P(name)) {
name = argv[i];
break;
}
rb_raise(rb_eArgError,"multiple name in struct definition");
case T_ARRAY:
if (shape) {
rb_raise(rb_eArgError,"multiple shape in struct definition");
}
ndim = RARRAY_LEN(argv[i]);
if (ndim > NA_MAX_DIMENSION) {
rb_raise(rb_eArgError,"too large number of dimensions");
}
if (ndim == 0) {
rb_raise(rb_eArgError,"array is empty");
}
shape = ALLOCA_N(size_t, ndim);
na_array_to_internal_shape(Qnil, argv[i], shape);
break;
}
}
id = rb_to_id(name);
name = ID2SYM(id);
if (rb_obj_is_kind_of(type,cNArray)) {
narray_t *na;
GetNArray(type,na);
type = CLASS_OF(type);
ndim = na->ndim;
shape = na->shape;
}
type = rb_narray_view_new(type,ndim,shape);
GetNArrayView(type,nt);
nt->stridx = ALLOC_N(stridx_t,ndim);
stride = na_dtype_elmsz(CLASS_OF(type));
for (j=ndim; j--; ) {
SDX_SET_STRIDE(nt->stridx[j], stride);
stride *= shape[j];
}
ofs = rb_iv_get(nst, "__offset__");
nt->offset = NUM2SIZET(ofs);
size = rb_funcall(type, rb_intern("byte_size"), 0);
rb_iv_set(nst, "__offset__", rb_funcall(ofs,'+',1,size));
rb_ary_push(rb_iv_get(nst,"__members__"),
rb_ary_new3(4,name,type,ofs,size)); // <- field definition
return Qnil;
}
示例7: ossl_asn1_decode0
static VALUE
ossl_asn1_decode0(unsigned char **pp, long length, long *offset, long depth,
int once, int yield)
{
unsigned char *start, *p;
const unsigned char *p0;
long len, off = *offset;
int hlen, tag, tc, j;
VALUE ary, asn1data, value, tag_class;
ary = rb_ary_new();
p = *pp;
while(length > 0){
start = p;
p0 = p;
j = ASN1_get_object(&p0, &len, &tag, &tc, length);
p = (unsigned char *)p0;
if(j & 0x80) ossl_raise(eASN1Error, NULL);
hlen = p - start;
if(yield){
VALUE arg = rb_ary_new();
rb_ary_push(arg, LONG2NUM(depth));
rb_ary_push(arg, LONG2NUM(off));
rb_ary_push(arg, LONG2NUM(hlen));
rb_ary_push(arg, LONG2NUM(len));
rb_ary_push(arg, (j & V_ASN1_CONSTRUCTED) ? Qtrue : Qfalse);
rb_ary_push(arg, ossl_asn1_class2sym(tc));
rb_ary_push(arg, INT2NUM(tag));
rb_yield(arg);
}
length -= hlen;
off += hlen;
if(len > length) ossl_raise(eASN1Error, "value is too short");
if((tc & V_ASN1_PRIVATE) == V_ASN1_PRIVATE)
tag_class = sPRIVATE;
else if((tc & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC)
tag_class = sCONTEXT_SPECIFIC;
else if((tc & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)
tag_class = sAPPLICATION;
else
tag_class = sUNIVERSAL;
if(j & V_ASN1_CONSTRUCTED){
/* TODO: if j == 0x21 it is indefinite length object. */
if((j == 0x21) && (len == 0)){
long lastoff = off;
value = ossl_asn1_decode0(&p, length, &off, depth+1, 0, yield);
len = off - lastoff;
}
else value = ossl_asn1_decode0(&p, len, &off, depth+1, 0, yield);
}
else{
value = rb_str_new((const char *)p, len);
p += len;
off += len;
}
if(tag_class == sUNIVERSAL &&
tag < ossl_asn1_info_size && ossl_asn1_info[tag].klass){
VALUE klass = *ossl_asn1_info[tag].klass;
long flag = 0;
if(!rb_obj_is_kind_of(value, rb_cArray)){
switch(tag){
case V_ASN1_BOOLEAN:
value = decode_bool(start, hlen+len);
break;
case V_ASN1_INTEGER:
value = decode_int(start, hlen+len);
break;
case V_ASN1_BIT_STRING:
value = decode_bstr(start, hlen+len, &flag);
break;
case V_ASN1_NULL:
value = decode_null(start, hlen+len);
break;
case V_ASN1_ENUMERATED:
value = decode_enum(start, hlen+len);
break;
case V_ASN1_OBJECT:
value = decode_obj(start, hlen+len);
break;
case V_ASN1_UTCTIME: /* FALLTHROUGH */
case V_ASN1_GENERALIZEDTIME:
value = decode_time(start, hlen+len);
break;
default:
/* use original value */
break;
}
}
asn1data = rb_funcall(klass, rb_intern("new"), 1, value);
if(tag == V_ASN1_BIT_STRING){
rb_iv_set(asn1data, "@unused_bits", LONG2NUM(flag));
}
}
else{
asn1data = rb_funcall(cASN1Data, rb_intern("new"), 3,
value, INT2NUM(tag), ID2SYM(tag_class));
}
rb_ary_push(ary, asn1data);
length -= len;
if(once) break;
//.........这里部分代码省略.........
示例8: query_initialize
//
// def initialize(query_id, query, client)
//
static VALUE query_initialize(VALUE self, VALUE query_id, VALUE query, VALUE client) {
rb_iv_set(self, "@query_id", query_id);
rb_iv_set(self, "@query", query);
rb_iv_set(self, "@client", client);
rb_iv_set(self, "@done", Qfalse);
}
示例9: display_initialize
static VALUE display_initialize(int argc, VALUE* argv, VALUE self)
{
caca_display_t *display;
caca_canvas_t *canvas = NULL;
const char *driver = NULL;
VALUE cv = Qnil;
VALUE arg1, arg2;
rb_scan_args(argc, argv, "02", &arg1, &arg2);
if(CLASS_OF(arg1) == cCanvas)
{
cv = arg1;
if(CLASS_OF(arg2) == cCanvas)
{
rb_raise(rb_eArgError, "Only one argument can be a Caca::Canvas");
}
}
else if(CLASS_OF(arg2) == cCanvas)
{
cv = arg2;
}
if(TYPE(arg1) == T_STRING)
{
driver = StringValuePtr(arg1);
if(TYPE(arg2) == T_STRING)
{
rb_raise(rb_eArgError, "Only one argument can be a string");
}
}
else if(TYPE(arg2) == T_STRING)
{
driver = StringValuePtr(arg2);
}
if(cv != Qnil)
canvas = DATA_PTR(cv);
if(driver == NULL)
{
display = caca_create_display(canvas);
if(display && NIL_P(cv))
{
cv = canvas_create(caca_get_canvas(display));
}
}
else
{
display = caca_create_display_with_driver(canvas, driver);
}
if(display == NULL)
{
rb_raise(rb_eRuntimeError, "%s", strerror(errno));
}
_SELF = display;
rb_iv_set(self, "@canvas", cv);
return self;
}
示例10: rb_grn_column_select
//.........这里部分代码省略.........
* [+:allow_pragma+]
* query構文時にプラグマを利用するかどうか。省略した場合は
* 利用する。
*
* 参考: Groonga::Expression#parse.
*
* [+:allow_column+]
* query構文時にカラム指定を利用するかどうか。省略した場合
* は利用する。
*
* 参考: Groonga::Expression#parse.
*
* [+:allow_update+]
* script構文時に更新操作を利用するかどうか。省略した場合
* は利用する。
*
* 参考: Groonga::Expression#parse.
*/
static VALUE
rb_grn_column_select (int argc, VALUE *argv, VALUE self)
{
grn_ctx *context;
grn_obj *table, *column, *result, *expression;
grn_operator operator = GRN_OP_OR;
VALUE options;
VALUE rb_query, condition_or_options;
VALUE rb_name, rb_operator, rb_result, rb_syntax;
VALUE rb_allow_pragma, rb_allow_column, rb_allow_update;
VALUE builder;
VALUE rb_expression = Qnil;
rb_query = Qnil;
rb_scan_args(argc, argv, "02", &condition_or_options, &options);
rb_grn_column_deconstruct(SELF(self), &column, &context,
NULL, NULL,
NULL, NULL, NULL);
table = grn_column_table(context, column);
if (RVAL2CBOOL(rb_obj_is_kind_of(condition_or_options, rb_cString))) {
rb_query = condition_or_options;
} else if (RVAL2CBOOL(rb_obj_is_kind_of(condition_or_options,
rb_cGrnExpression))) {
rb_expression = condition_or_options;
} else {
if (!NIL_P(options))
rb_raise(rb_eArgError,
"should be [query_string, option_hash], "
"[expression, option_hash] "
"or [option_hash]: %s",
rb_grn_inspect(rb_ary_new4(argc, argv)));
options = condition_or_options;
}
rb_grn_scan_options(options,
"operator", &rb_operator,
"result", &rb_result,
"name", &rb_name,
"syntax", &rb_syntax,
"allow_pragma", &rb_allow_pragma,
"allow_column", &rb_allow_column,
"allow_update", &rb_allow_update,
NULL);
if (!NIL_P(rb_operator))
operator = NUM2INT(rb_operator);
if (NIL_P(rb_result)) {
result = grn_table_create(context, NULL, 0, NULL,
GRN_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC,
table,
0);
rb_result = GRNTABLE2RVAL(context, result, RB_GRN_TRUE);
} else {
result = RVAL2GRNTABLE(rb_result, &context);
}
if (NIL_P(rb_expression)) {
builder = rb_grn_column_expression_builder_new(self, rb_name, rb_query);
rb_funcall(builder, rb_intern("syntax="), 1, rb_syntax);
rb_funcall(builder, rb_intern("allow_pragma="), 1, rb_allow_pragma);
rb_funcall(builder, rb_intern("allow_column="), 1, rb_allow_column);
rb_funcall(builder, rb_intern("allow_update="), 1, rb_allow_update);
rb_expression = rb_grn_column_expression_builder_build(builder);
}
rb_grn_object_deconstruct(RB_GRN_OBJECT(DATA_PTR(rb_expression)),
&expression, NULL,
NULL, NULL, NULL, NULL);
grn_table_select(context, table, expression, result, operator);
rb_grn_context_check(context, self);
rb_attr(rb_singleton_class(rb_result),
rb_intern("expression"),
RB_GRN_TRUE, RB_GRN_FALSE, RB_GRN_FALSE);
rb_iv_set(rb_result, "@expression", rb_expression);
return rb_result;
}
示例11: rbhtp_file_initialize
// ---- File ----
VALUE rbhtp_file_initialize( VALUE self, VALUE raw_file )
{
rb_iv_set( self, "@file", raw_file );
return Qnil;
}
示例12: counter_start
/*
:nodoc:
*/
static VALUE counter_start(VALUE self)
{
rb_iv_set(self, "@st", rb_funcall(mSDL, rb_intern("getTicks"), 0));
rb_iv_set(self, "@counting", Qtrue);
return self;
}
示例13: statement_Execute
static VALUE statement_Execute(VALUE self) {
int i;
CS_DATAFMT col;
CS_DATAFMT *cols;
EX_COLUMN_DATA *col_data;
CS_INT rc;
CS_INT resulttype;
CS_INT num_cols;
CS_INT col_len;
CS_INT row_count = 0;
CS_INT rows_read;
CS_INT num_errors = 0;
CS_SERVERMSG servermsg;
VALUE err;
char *error_msg;
struct timeval start, stop;
int print_rows = 1;
char message[128];
char* buf;
CS_DATEREC date_rec;
char output[200];
CS_INT output_len;
int tempInt;
CS_BIGINT tempBigInt;
double tempDouble;
CS_NUMERIC tempNumeric;
char* tempText;
char* newTempText;
int tempTextLen;
CS_INT data_rc;
int isNull = 0;
CS_DATE tempDate;
CS_DATETIME tempDateTime;
TDS_Connection* conn;
CS_COMMAND * cmd;
VALUE connection;
VALUE query;
VALUE columns;
VALUE rows;
VALUE status;
VALUE errors;
VALUE date_parts[8];
VALUE column;
VALUE row;
VALUE column_name = rb_str_new2("name");
VALUE column_type = rb_str_new2("type");
VALUE column_size = rb_str_new2("size");
VALUE column_scale = rb_str_new2("scale");
VALUE column_precision = rb_str_new2("precision");
VALUE column_value;
connection = rb_iv_get(self, "@connection");
query = rb_iv_get(self, "@query");
columns = rb_ary_new();
rb_iv_set(self, "@columns", columns);
rows = rb_ary_new();
rb_iv_set(self, "@rows", rows);
Data_Get_Struct(connection, TDS_Connection, conn);
buf = value_to_cstr(query);
rb_iv_set(self, "@status", Qnil);
rb_iv_set(self, "@messages", rb_ary_new());
errors = rb_ary_new();
rb_iv_set(self, "@errors", errors);
ct_diag(conn->connection, CS_INIT, CS_UNUSED, CS_UNUSED, NULL);
// if ( ct_callback(conn->context, NULL, CS_SET, CS_CLIENTMSG_CB, (CS_VOID *)clientmsg_cb) != CS_SUCCEED ) {
// error_message("ct_callback CS_CLIENTMSG_CB failed\n");
// }
// if ( ct_callback(conn->context, NULL, CS_SET, CS_SERVERMSG_CB, (CS_VOID *)servermsg_cb) != CS_SUCCEED ) {
// error_message("ct_callback CS_SERVERMSG_CB failed\n");
// }
ct_cmd_alloc(conn->connection, &cmd);
ct_command(cmd, CS_LANG_CMD, buf, CS_NULLTERM, CS_UNUSED);
ct_send(cmd);
if ( ct_diag(conn->connection, CS_STATUS, CS_SERVERMSG_TYPE, CS_UNUSED, &num_errors) != CS_SUCCEED ) {
error_message("ct_diag CS_STATUS CS_SERVERMSG_TYPE failed");
}
if (num_errors > 0) {
// fprintf(stderr, "%d errors found\n", num_errors);
for (i = 0; i < num_errors; i++) {
if ( ct_diag(conn->connection, CS_GET, CS_SERVERMSG_TYPE, i+1, &servermsg) != CS_SUCCEED ) {
error_message("ct_diag CS_GET CS_SERVERMSG_TYPE failed");
}
if (servermsg.severity > 0) {
// error_message(servermsg.text);
rb_ary_push(errors, rb_str_new2(servermsg.text));
//.........这里部分代码省略.........
示例14: connection_Initialize
static VALUE connection_Initialize(VALUE self, VALUE connection_hash) {
TDS_Connection* conn;
char *servername = NULL;
char *username = NULL;
char *password = NULL;
char *confile = NULL;
char *charset = NULL;
VALUE temp;
VALUE errors;
CS_RETCODE ret;
Data_Get_Struct(self, TDS_Connection, conn);
cs_ctx_alloc(CS_VERSION_100, &conn->context);
ct_init(conn->context, CS_VERSION_100);
ct_con_alloc(conn->context, &conn->connection);
// conn->context->msg_handler = connection_handle_message;
// conn->context->err_handler = connection_handle_message;
/* now let's get the connection parameters */
temp = rb_hash_aref(connection_hash, ID2SYM(rb_intern("username")));
username = value_to_cstr(temp);
temp = rb_hash_aref(connection_hash, ID2SYM(rb_intern("password")));
password = value_to_cstr(temp);
temp = rb_hash_aref(connection_hash, ID2SYM(rb_intern("servername")));
servername = value_to_cstr(temp);
temp = rb_hash_aref(connection_hash, ID2SYM(rb_intern("charset")));
charset = value_to_cstr(temp);
if(charset==NULL) {
charset = strdup("ISO-8859-1");
}
/* validate parameters */
if (!servername) {
rb_raise(rb_eArgError, "You must specify a servername");
return Qnil;
}
if (!username) {
rb_raise(rb_eArgError, "No username specified");
return Qnil;
}
if (!password) {
password = strdup("");
}
// printf("*** servername='%s', username='%s' password='%s'\n", servername, username, password);
ct_con_props(conn->connection, CS_SET, CS_USERNAME, username, CS_NULLTERM, NULL);
ct_con_props(conn->connection, CS_SET, CS_PASSWORD, password, CS_NULLTERM, NULL);
/* Try to open a connection */
ret = ct_connect(conn->connection, servername, CS_NULLTERM);
/* free up all the memory */
if (username) {
free(username);
username = NULL;
}
if (password) {
free(password);
password = NULL;
}
if (servername) {
free(servername);
}
if(ret!=CS_SUCCEED) {
rb_raise(rb_eIOError, "Connection failed");
return Qnil;
}
rb_iv_set(self, "@messages", rb_ary_new());
errors = rb_ary_new();
rb_iv_set(self, "@errors", errors);
return Qnil;
}
示例15: Extension1_initialize
VALUE Extension1_initialize(VALUE self)
{
rb_iv_set(self,"@test",1);
rb_iv_set(self,"@test2",2);
return self;
}