本文整理汇总了C++中rb_block_given_p函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_block_given_p函数的具体用法?C++ rb_block_given_p怎么用?C++ rb_block_given_p使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_block_given_p函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: krypt_pem_decode
/*
* call-seq:
* Krypt::PEM.decode(data) { |der, name, i| block } -> Array
*
* +data+ can be either a PEM-encoded String, an IO-like object that features
* a +read+ method or any arbitrary object that has a +to_pem+ method returning
* either a String or an IO-like object.
*
* Returns an Array that contains the DER-encoded results in the order they
* were decoded. PEM data can potentially consist of multiple elements, a
* common example being 'trusted certificate bundles' that contain a set of
* to-be-trusted certificates.
*
* If additionally a block is given, +block+ is called for each element that is
* decoded, where +der+ contains the decoded element, +name+ the identifier of
* the current element (e.g. 'CERTIFICATE') and +i+ the index of the current
* element starting with 0.
*
* === Example: Decoding a simple certificate file
*
* File.open("certificate.pem", "rb") do |f|
* cert = Krypt::PEM.decode(f)[0]
* # process the certificate
* end
*
* === Example: Decoding multiple elements contained in one file
*
* File.open("trusted-certs.pem", "rb") do |f|
* Krypt::PEM.decode(f) do |der, name, i|
* puts "Element #{i}: #{name}"
* File.open("cert-#{i}.der", "wb") do |g|
* g.print der
* end
* end
* end
*/
static VALUE
krypt_pem_decode(VALUE self, VALUE pem)
{
VALUE ary, der;
size_t i = 0;
int result;
binyo_instream *in = krypt_instream_new_pem(krypt_instream_new_value_pem(pem));
ary = rb_ary_new();
while ((result = int_consume_stream(in, &der)) == KRYPT_OK) {
if (NIL_P(der))
break;
rb_ary_push(ary, der);
if(rb_block_given_p()) {
uint8_t *name;
size_t len;
VALUE vname;
if (krypt_pem_get_last_name(in, &name, &len) == BINYO_ERR) goto error;
vname = rb_str_new((const char *) name, len);
xfree(name);
rb_yield_values(3, der, vname, SIZET2NUM(i++));
}
krypt_pem_continue_stream(in);
}
if (result == KRYPT_ERR) goto error;
binyo_instream_free(in);
return ary;
error:
binyo_instream_free(in);
krypt_error_raise(eKryptPEMError, "Error while decoding PEM data");
return Qnil;
}
开发者ID:LarsWestergren,项目名称:krypt-core-c,代码行数:72,代码来源:krypt_pem.c
示例2: cSedna_s_connect
/*
* call-seq:
* Sedna.connect(details) -> Sedna instance
* Sedna.connect(details) {|sedna| ... } -> nil
*
* Establishes a new connection to a \Sedna XML database. Accepts a hash that
* describes which database to connect to.
*
* If a block is given, the block is executed if a connection was successfully
* established. The connection is closed at the end of the block or if the
* stack is unwinded (if an exception is raised, for example). If called
* without a block, a Sedna object that represents the connection is returned.
* The connection should be closed by calling Sedna#close.
*
* If a connection cannot be initiated, a Sedna::ConnectionError is raised.
* If the authentication fails, a Sedna::AuthenticationError is raised.
*
* This method does not block other threads in Ruby 1.9.1+ -- connections that
* are initiated in different threads will be created concurrently. You can
* use Sedna.blocking? to verify if the extension supports non-blocking
* behaviour.
*
* ==== Valid connection details keys
*
* * <tt>:host</tt> - Host name or IP address to which to connect to (defaults to +localhost+).
* * <tt>:database</tt> - Name of the database to connect to (defaults to +test+).
* * <tt>:username</tt> - User name to authenticate with (defaults to +SYSTEM+).
* * <tt>:password</tt> - Password to authenticate with (defaults to +MANAGER+).
*
* ==== Examples
*
* Call without a block and close the connection afterwards.
*
* sedna = Sedna.connect :database => "my_db", :host => "my_host"
* # Query the database and close afterwards.
* sedna.close
*
* Call with a block. The connection is closed automatically.
*
* Sedna.connect :database => "my_db", :host => "my_host" do |sedna|
* # Query the database.
* # The connection is closed automatically.
* end
*/
static VALUE cSedna_s_connect(VALUE klass, VALUE options)
{
int status;
// Create a new instance.
VALUE obj = rb_funcall(klass, rb_intern("new"), 1, options);
if(rb_block_given_p()) {
// If a block is given, yield the instance, and make sure we always return...
rb_protect(rb_yield, obj, &status);
// ...to ensure that the connection is closed afterwards.
cSedna_close(obj);
// Re-raise any exception.
if(status != 0) rb_jump_tag(status);
// Always return nil if successful.
return Qnil;
} else {
// If no block is given, simply return the instance.
return obj;
}
}
开发者ID:rolftimmermans,项目名称:sedna-ruby,代码行数:68,代码来源:sedna.c
示例3: rb_struct_s_def
static VALUE
rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
{
VALUE name, rest;
long i;
VALUE st;
ID id;
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
name = argv[0];
if (SYMBOL_P(name)) {
name = Qnil;
}
else {
--argc;
++argv;
}
rest = rb_ary_tmp_new(argc);
for (i=0; i<argc; i++) {
id = rb_to_id(argv[i]);
RARRAY_ASET(rest, i, ID2SYM(id));
rb_ary_set_len(rest, i+1);
}
if (NIL_P(name)) {
st = anonymous_struct(klass);
}
else {
st = new_struct(name, klass);
}
setup_struct(st, rest);
if (rb_block_given_p()) {
rb_mod_module_eval(0, 0, st);
}
return st;
}
开发者ID:charneykaye,项目名称:learning-ruby-on-rails,代码行数:36,代码来源:struct.c
示例4: rb_git_remote_collection_rename
/*
* call-seq:
* remotes.rename(remote, new_name) { |str| } -> remote
* remotes.rename(name, new_name) { |str| } -> remote
*
* Renames a remote.
*
* All remote-tracking branches and configuration settings
* for the remote are updated.
*
* Non-default refspecs cannot be renamed automatically and will be
* yielded to the given block.
*
* Anonymous, in-memory remotes created through
* +ReferenceCollection#create_anonymous+ can not be given a name through
* this method.
*
* Returns a new Rugged::Remote object with the new name.
*/
static VALUE rb_git_remote_collection_rename(VALUE self, VALUE rb_name_or_remote, VALUE rb_new_name)
{
VALUE rb_repo = rugged_owner(self);
git_repository *repo;
size_t i;
int error, exception;
git_strarray problems;
if (!rb_block_given_p())
rb_raise(rb_eArgError, "Rugged::RemoteCollection#rename must be called with a block");
Check_Type(rb_new_name, T_STRING);
if (rb_obj_is_kind_of(rb_name_or_remote, rb_cRuggedRemote))
rb_name_or_remote = rb_funcall(rb_name_or_remote, rb_intern("name"), 0);
if (TYPE(rb_name_or_remote) != T_STRING)
rb_raise(rb_eTypeError, "Expecting a String or Rugged::Remote instance");
rugged_check_repo(rb_repo);
Data_Get_Struct(rb_repo, git_repository, repo);
error = git_remote_rename(&problems, repo, StringValueCStr(rb_name_or_remote), StringValueCStr(rb_new_name));
rugged_exception_check(error);
for (i = exception = 0; !exception && i < problems.count; ++i) {
rb_protect(rb_yield, rb_str_new_utf8(problems.strings[i]), &exception);
}
git_strarray_free(&problems);
if (exception)
rb_jump_tag(exception);
return rb_git_remote_collection_aref(self, rb_new_name);
}
开发者ID:CODECOMMUNITY,项目名称:rugged,代码行数:55,代码来源:rugged_remote_collection.c
示例5: ossl_pem_passwd_cb
int
ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd)
{
int len, status = 0;
VALUE rflag, pass;
if (pwd || !rb_block_given_p())
return PEM_def_callback(buf, max_len, flag, pwd);
while (1) {
/*
* when the flag is nonzero, this passphrase
* will be used to perform encryption; otherwise it will
* be used to perform decryption.
*/
rflag = flag ? Qtrue : Qfalse;
pass = rb_protect(ossl_pem_passwd_cb0, rflag, &status);
if (status) {
/* ignore an exception raised. */
rb_set_errinfo(Qnil);
return -1;
}
len = RSTRING_LENINT(pass);
if (len < 4) { /* 4 is OpenSSL hardcoded limit */
rb_warning("password must be longer than 4 bytes");
continue;
}
if (len > max_len) {
rb_warning("password must be shorter then %d bytes", max_len-1);
continue;
}
memcpy(buf, RSTRING_PTR(pass), len);
break;
}
return len;
}
开发者ID:DashYang,项目名称:sim,代码行数:36,代码来源:ossl.c
示例6: rb_struct_s_def
static VALUE
rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
{
VALUE name, rest;
long i;
VALUE st;
ID id;
rb_scan_args(argc, argv, "1*", &name, &rest);
if (!NIL_P(name) && SYMBOL_P(name)) {
rb_ary_unshift(rest, name);
name = Qnil;
}
for (i=0; i<RARRAY_LEN(rest); i++) {
id = rb_to_id(RARRAY_PTR(rest)[i]);
RARRAY_PTR(rest)[i] = ID2SYM(id);
}
st = make_struct(name, rest, klass);
if (rb_block_given_p()) {
rb_mod_module_eval(0, 0, st);
}
return st;
}
开发者ID:Chatto,项目名称:VGdesk,代码行数:24,代码来源:struct.c
示例7: shoes_canvas_shape
VALUE
shoes_canvas_shape(int argc, VALUE *argv, VALUE self)
{
int x;
double x1, y1, x2, y2;
cairo_t *shape = NULL;
cairo_path_t *line = NULL;
SETUP_SHAPE();
shape = canvas->shape;
attr = shoes_shape_attr(argc, argv, 2, s_left, s_top);
canvas->shape = cairo_create(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1));
cairo_move_to(canvas->shape, 0, 0);
if (rb_block_given_p()) rb_yield(Qnil);
cairo_path_extents(canvas->shape, &x1, &y1, &x2, &y2);
x = x2 - x1;
ATTRSET(attr, width, INT2NUM(x));
x = y2 - y1;
ATTRSET(attr, height, INT2NUM(x));
line = cairo_copy_path(canvas->shape);
canvas->shape = shape;
return shoes_add_shape(self, s_shape, attr, line);
}
开发者ID:Sitekurfer,项目名称:shoes,代码行数:24,代码来源:canvas.c
示例8: fdbm_fetch
static VALUE
fdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
{
datum key, value;
struct dbmdata *dbmp;
DBM *dbm;
long len;
ExportStringValue(keystr);
len = RSTRING_LEN(keystr);
if (TOO_LONG(len)) goto not_found;
key.dptr = RSTRING_PTR(keystr);
key.dsize = (DSIZE_TYPE)len;
GetDBM2(obj, dbmp, dbm);
value = dbm_fetch(dbm, key);
if (value.dptr == 0) {
not_found:
if (ifnone == Qnil && rb_block_given_p())
return rb_yield(rb_tainted_str_new(key.dptr, key.dsize));
return ifnone;
}
return rb_tainted_str_new(value.dptr, value.dsize);
}
开发者ID:Shopify,项目名称:ruby,代码行数:24,代码来源:dbm.c
示例9: rb_git_remote_each
/* :nodoc: */
static VALUE rb_git_remote_each(VALUE klass, VALUE rb_repo)
{
git_repository *repo;
git_strarray remotes;
size_t i;
int error = 0;
int exception = 0;
if (!rb_block_given_p())
return rb_funcall(klass, rb_intern("to_enum"), 2, CSTR2SYM("each"), rb_repo);
rugged_check_repo(rb_repo);
Data_Get_Struct(rb_repo, git_repository, repo);
error = git_remote_list(&remotes, repo);
rugged_exception_check(error);
for (i = 0; !exception && !error && i < remotes.count; ++i) {
git_remote *remote;
error = git_remote_load(&remote, repo, remotes.strings[i]);
if (!error) {
rb_protect(
rb_yield, rugged_remote_new(klass, rb_repo, remote),
&exception);
}
}
git_strarray_free(&remotes);
if (exception)
rb_jump_tag(exception);
rugged_exception_check(error);
return Qnil;
}
开发者ID:RSMP-others,项目名称:sonic-pi,代码行数:37,代码来源:rugged_remote.c
示例10: rbffi_SetupCallParams
void
rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
FFIStorage* paramStorage, void** ffiValues,
VALUE* callbackParameters, int callbackCount, VALUE enums)
{
VALUE callbackProc = Qnil;
FFIStorage* param = ¶mStorage[0];
int i, argidx, cbidx, argCount;
if (unlikely(paramCount != -1 && paramCount != argc)) {
if (argc == (paramCount - 1) && callbackCount == 1 && rb_block_given_p()) {
callbackProc = rb_block_proc();
} else {
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, paramCount);
}
}
argCount = paramCount != -1 ? paramCount : argc;
for (i = 0, argidx = 0, cbidx = 0; i < argCount; ++i) {
Type* paramType = paramTypes[i];
int type;
if (unlikely(paramType->nativeType == NATIVE_MAPPED)) {
VALUE values[] = { argv[argidx], Qnil };
argv[argidx] = rb_funcall2(((MappedType *) paramType)->rbConverter, id_to_native, 2, values);
paramType = ((MappedType *) paramType)->type;
}
type = argidx < argc ? TYPE(argv[argidx]) : T_NONE;
ffiValues[i] = param;
switch (paramType->nativeType) {
case NATIVE_INT8:
param->s8 = NUM2INT(argv[argidx]);
++argidx;
ADJ(param, INT8);
break;
case NATIVE_INT16:
param->s16 = NUM2INT(argv[argidx]);
++argidx;
ADJ(param, INT16);
break;
case NATIVE_INT32:
if (unlikely(type == T_SYMBOL && enums != Qnil)) {
VALUE value = rb_funcall(enums, id_map_symbol, 1, argv[argidx]);
param->s32 = NUM2INT(value);
} else {
param->s32 = NUM2INT(argv[argidx]);
}
++argidx;
ADJ(param, INT32);
break;
case NATIVE_BOOL:
if (type != T_TRUE && type != T_FALSE) {
rb_raise(rb_eTypeError, "wrong argument type (expected a boolean parameter)");
}
param->s8 = argv[argidx++] == Qtrue;
ADJ(param, INT8);
break;
case NATIVE_UINT8:
param->u8 = NUM2UINT(argv[argidx]);
ADJ(param, INT8);
++argidx;
break;
case NATIVE_UINT16:
param->u16 = NUM2UINT(argv[argidx]);
ADJ(param, INT16);
++argidx;
break;
case NATIVE_UINT32:
param->u32 = NUM2UINT(argv[argidx]);
ADJ(param, INT32);
++argidx;
break;
case NATIVE_INT64:
param->i64 = NUM2LL(argv[argidx]);
ADJ(param, INT64);
++argidx;
break;
//.........这里部分代码省略.........
开发者ID:JackCameo,项目名称:sample_app,代码行数:101,代码来源:Call.c
示例11: rb_ldap_conn_sasl_bind
//.........这里部分代码省略.........
char *sasl_realm = NULL;
char *sasl_authc_id = NULL;
char *sasl_authz_id = NULL;
char *sasl_secprops = NULL;
struct berval passwd = { 0, NULL };
*/
unsigned sasl_flags = LDAP_SASL_AUTOMATIC;
Data_Get_Struct (self, RB_LDAP_DATA, ldapdata);
if (!ldapdata->ldap)
{
if (rb_iv_get (self, "@args") != Qnil)
{
rb_ldap_conn_rebind (self);
GET_LDAP_DATA (self, ldapdata);
}
else
{
rb_raise (rb_eLDAP_InvalidDataError,
"The LDAP handler has already unbound.");
}
}
if (ldapdata->bind)
{
rb_raise (rb_eLDAP_Error, "already bound.");
};
switch (rb_scan_args (argc, argv, "24", &arg1, &arg2, &arg3, &arg4, &arg5, &sasl_options))
{
case 6:
/* nothing. this requires credentials to be parsed first. we'll get defaults after arg-scanning */
case 5:
if(!NIL_P(arg5))
clientctrls = rb_ldap_get_controls (arg5);
/* down seems more likely */
case 4:
if(!NIL_P(arg4))
serverctrls = rb_ldap_get_controls (arg4);
/* down seems more likely */
case 3:
if(!NIL_P(arg3))
{
cred->bv_val = StringValueCStr (arg3);
cred->bv_len = RSTRING_LEN (arg3);
}
/* down seems more likely */
case 2: /* don't need the cred for GSSAPI */
dn = StringValuePtr (arg1);
mechanism = StringValuePtr (arg2);
if (rb_iv_get (self, "@sasl_quiet") == Qtrue)
sasl_flags = LDAP_SASL_QUIET;
break;
default:
rb_bug ("rb_ldap_conn_bind_s");
}
ldap_get_option (ldapdata->ldap, LDAP_OPT_PROTOCOL_VERSION, &version);
if (version < LDAP_VERSION3)
{
version = LDAP_VERSION3;
ldapdata->err =
ldap_set_option (ldapdata->ldap, LDAP_OPT_PROTOCOL_VERSION, &version);
Check_LDAP_Result (ldapdata->err);
}
/* the following works for GSSAPI, at least */
ldapdata->err =
ldap_sasl_interactive_bind_s (ldapdata->ldap, dn, mechanism,
serverctrls, clientctrls, sasl_flags,
rb_ldap_sasl_interaction, (void*)sasl_options);
if (ldapdata->err == LDAP_SASL_BIND_IN_PROGRESS)
{
rb_raise (rb_eNotImpError,
"SASL authentication is not fully supported.");
/* How can I implement this with portability? */
/*
VALUE scred;
scred = rb_tainted_str_new(servercred->bv_val,
servercred->bv_len);
*/
}
else
{
Check_LDAP_Result (ldapdata->err);
ldapdata->bind = 1;
}
if (rb_block_given_p ())
{
rb_ensure (rb_yield, self, rb_ldap_conn_unbind, self);
return Qnil;
}
else
{
return self;
};
}
开发者ID:pwillred,项目名称:ruby-ldap,代码行数:101,代码来源:saslconn.c
示例12: ra_sound_s_open
/*
* call-seq:
* CSound.open(...) => snd
* CSound.open(...) {|snd| block } => obj
*
* With no associated block, <code>open</code> is a synonym for
* <code>CSound.new</code>. If the optional code block is given, it will be
* passed <i>snd</i> as an argument, and the CSound object will automatically be
* closed when the block terminates. In this instance, <code>CSound.open</code>
* returns the value of the block.
*/
static VALUE ra_sound_s_open(int argc, VALUE *argv, VALUE klass) {
VALUE obj = rb_class_new_instance(argc, argv, klass);
if(!rb_block_given_p()) return obj;
return rb_ensure(rb_yield, obj, ra_sound_close_safe, obj);
}
开发者ID:zmack,项目名称:ruby-audio,代码行数:16,代码来源:ra_sound.c
示例13: Draw_annotate
/*
Method: Draw#annotate(img, w, h, x, y, text) <{optional parms}>
Purpose: annotates an image with text
Returns: self
Notes: Additional Draw attribute methods may be called in the
optional block, which is executed in the context of an
Draw object.
*/
VALUE Draw_annotate(
VALUE self,
VALUE image_arg,
VALUE width_arg,
VALUE height_arg,
VALUE x_arg,
VALUE y_arg,
VALUE text)
{
Draw *draw;
Image *image;
unsigned long width, height;
long x, y;
AffineMatrix keep;
char geometry_str[50];
// Save the affine matrix in case it is modified by
// Draw#rotation=
Data_Get_Struct(self, Draw, draw);
keep = draw->info->affine;
image_arg = rm_cur_image(image_arg);
image = rm_check_frozen(image_arg);
// If we have an optional parm block, run it in self's context,
// allowing the app a chance to modify the object's attributes
if (rb_block_given_p())
{
(void)rb_obj_instance_eval(0, NULL, self);
}
// Translate & store in Draw structure
#if defined(HAVE_INTERPRETIMAGEPROPERTIES)
draw->info->text = InterpretImageProperties(NULL, image, StringValuePtr(text));
#else
draw->info->text = InterpretImageAttributes(NULL, image, StringValuePtr(text));
#endif
if (!draw->info->text)
{
rb_raise(rb_eArgError, "no text");
}
// Create geometry string, copy to Draw structure, overriding
// any previously existing value.
width = NUM2ULONG(width_arg);
height = NUM2ULONG(height_arg);
x = NUM2LONG(x_arg);
y = NUM2LONG(y_arg);
if (width == 0 && height == 0)
{
sprintf(geometry_str, "%+ld%+ld", x, y);
}
// WxH is non-zero
else
{
sprintf(geometry_str, "%lux%lu%+ld%+ld", width, height, x, y);
}
magick_clone_string(&draw->info->geometry, geometry_str);
(void) AnnotateImage(image, draw->info);
magick_free(draw->info->text);
draw->info->text = NULL;
draw->info->affine = keep;
rm_check_image_exception(image, RetainOnError);
return self;
}
开发者ID:akankshita,项目名称:HealtyPrice,代码行数:80,代码来源:rmdraw.c
示例14: cColor_initialize
/** :call-seq:
Color.new # The default color. Let's say: black
Color.new :white # or any other QGlobalColor. These are cached.
Color.new Color
Color.new Color, alpha
Color.new Brush
Color.new '#rgb' # must be hexadecimals, case insensitive
Color.new '#rrggbb'
Color.new '#rrrgggbbb'
Color.new '#rrrrggggbbbb'
Color.new '#rgba' # etc
Color.new red, green, blue, opaqueness = 255 # all values must be between 0 and 255
Color.new gray_value, opaqueness = 255
Color.new red, green, blue, opaqueness = 1.0 # all values must be between 0.0 and 1.0
Color.new gray_value, opaqueness = 1.0
Color.new [array_args] # splatted
Color.new Hash # same as Control constructor
Color.new { initblock } # same as Control constructor
Colors have neither parents nor children
*/
static VALUE
cColor_initialize(int argc, VALUE *argv, VALUE v_self)
{
trace1("cColor_initialize, argc=%d", argc);
RPP::QColor self = v_self;
VALUE v_colorsym, v_g, v_b, v_a;
rb_scan_args(argc, argv, "04", &v_colorsym, &v_g, &v_b, &v_a);
track4("cColor_initialize(%s, %s, %s, %s)", v_colorsym, v_g, v_b, v_a);
const RPP::Object colorsym = v_colorsym;
const RPP::Object g = v_g, b = v_b, a = v_a;
switch (colorsym.type())
{
case T_HASH:
return self.call("setupQuickyhash", colorsym);
case T_NIL:
if (rb_block_given_p())
{
trace("instance_eval on block");
return self.instance_eval();
}
trace("default color assign");
*self = QColor();
return Qnil;
case T_DATA:
if (colorsym.is_kind_of(cColor))
{
trace("when Color");
if (!g.isNil()) colorsym.call("alpha=", g);
*self = *RPP::QColor(colorsym);
return Qnil;
}
if (colorsym.is_kind_of(cBrush))
{
trace("when Brush");
*self = *RPP::QColor(colorsym.call("color"));
return Qnil;
}
break;
case T_STRING:
{
trace("when String");
const char *s = RPP::String(colorsym);
if (*s == '#')
{
const size_t l = strlen(s);
char t[l + 1];
strcpy(t, s);
s = t;
for (char *u = t; *u; u++)
*u = toupper(*u);
switch (l)
{
case 5:
{
// 17 * 0xf = 17 * 15 = 255. How nice.
const int alpha = hex2int(t[4]) * 17;
t[4] = 0;
QColor * const r = new QColor(t);
r->setAlpha(alpha);
*self = *r;
return Qnil;
}
case 9:
{
const int alpha = hex2int(t[7]) * 16 + hex2int(t[8]);
t[7] = 0;
QColor * const r = new QColor(t);
r->setAlpha(alpha);
*self = *r;
return Qnil;
}
case 13:
{
const int alpha = hex2int(t[10]) * 256 + hex2int(t[11]) * 16 + hex2int(t[12]);
t[10] = 0;
QColor * const r = new QColor(t);
r->setAlphaF(alpha / 4096.0);
*self = *r;
return Qnil;
//.........这里部分代码省略.........
开发者ID:EugeneBrazwick,项目名称:Midibox,代码行数:101,代码来源:color.cpp
示例15: rb_grn_query_logger_s_register
/*
* Registers a query logger or a callback that is called when a
* query log event is emitted.
*
* @overload register(logger, options={})
* @param logger [#log, #reopen, #fin] The query logger. It is easy to
* inherit {QueryLogger}.
*
* @!macro query-logger.register.options
* @param options [::Hash] The options.
* @option options [Symbol, String, Integer or nil] :flags (:default)
* Flags describe what query log should be logged.
*
* If `flags` is String, it is parsed by {QueryLogger::Flags.parse}.
*
* @return void
*
* @overload register(options={})
* @yield [action, flag, timestamp, info, message]
* ...
*
* @!macro query-logger.register.options
*/
static VALUE
rb_grn_query_logger_s_register (int argc, VALUE *argv, VALUE klass)
{
VALUE rb_context = Qnil;
grn_ctx *context;
VALUE rb_logger, rb_callback;
VALUE rb_options, rb_command, rb_result_code, rb_destination;
VALUE rb_cache, rb_size, rb_score, rb_default, rb_all, rb_flags;
unsigned int flags = GRN_QUERY_LOG_NONE;
rb_scan_args(argc, argv, "02&", &rb_logger, &rb_options, &rb_callback);
if (rb_block_given_p()) {
rb_logger = rb_funcall(cGrnCallbackQueryLogger, id_new, 1, rb_callback);
}
rb_grn_scan_options(rb_options,
"command", &rb_command,
"result_code", &rb_result_code,
"destination", &rb_destination,
"cache", &rb_cache,
"size", &rb_size,
"score", &rb_score,
"default", &rb_default,
"all", &rb_all,
"flags", &rb_flags,
NULL);
if (RVAL2CBOOL(rb_command)) {
flags |= GRN_QUERY_LOG_COMMAND;
}
if (RVAL2CBOOL(rb_result_code)) {
flags |= GRN_QUERY_LOG_RESULT_CODE;
}
if (RVAL2CBOOL(rb_destination)) {
flags |= GRN_QUERY_LOG_DESTINATION;
}
if (RVAL2CBOOL(rb_cache)) {
flags |= GRN_QUERY_LOG_CACHE;
}
if (RVAL2CBOOL(rb_size)) {
flags |= GRN_QUERY_LOG_SIZE;
}
if (RVAL2CBOOL(rb_score)) {
flags |= GRN_QUERY_LOG_SCORE;
}
if (RVAL2CBOOL(rb_default)) {
flags |= GRN_QUERY_LOG_DEFAULT;
}
if (RVAL2CBOOL(rb_all)) {
flags |= GRN_QUERY_LOG_ALL;
}
if (!NIL_P(rb_flags)) {
flags = rb_funcall(mGrnQueryLoggerFlags, id_parse, 2,
rb_flags, UINT2NUM(flags));
}
rb_grn_query_logger.flags = flags;
rb_grn_query_logger.user_data = (void *)rb_logger;
context = rb_grn_context_ensure(&rb_context);
grn_query_logger_set(context, &rb_grn_query_logger);
rb_grn_context_check(context, rb_logger);
rb_cv_set(klass, "@@current_logger", rb_logger);
return Qnil;
}
开发者ID:genki,项目名称:rroonga,代码行数:90,代码来源:rb-grn-query-logger.c
示例16: zipruby_archive_s_open_buffer
static VALUE zipruby_archive_s_open_buffer(int argc, VALUE *argv, VALUE self) {
VALUE buffer, flags, comp_level;
VALUE archive;
struct zipruby_archive *p_archive;
void *data = NULL;
int len = 0, i_flags = 0;
int errorp;
int i_comp_level = Z_BEST_COMPRESSION;
int buffer_is_temporary = 0;
rb_scan_args(argc, argv, "03", &buffer, &flags, &comp_level);
if (FIXNUM_P(buffer) && NIL_P(comp_level)) {
comp_level = flags;
flags = buffer;
buffer = Qnil;
}
if (!NIL_P(flags)) {
i_flags = NUM2INT(flags);
}
if (!NIL_P(comp_level)) {
i_comp_level = NUM2INT(comp_level);
if (i_comp_level != Z_DEFAULT_COMPRESSION && i_comp_level != Z_NO_COMPRESSION && (i_comp_level < Z_BEST_SPEED || Z_BEST_COMPRESSION < i_comp_level)) {
rb_raise(rb_eArgError, "Wrong compression level %d", i_comp_level);
}
}
if (i_flags & ZIP_CREATE) {
if (!NIL_P(buffer)) {
Check_Type(buffer, T_STRING);
} else {
buffer = rb_str_new("", 0);
buffer_is_temporary = 1;
}
i_flags = (i_flags | ZIP_TRUNCATE);
} else if (TYPE(buffer) == T_STRING) {
data = RSTRING_PTR(buffer);
len = RSTRING_LEN(buffer);
} else if (rb_obj_is_instance_of(buffer, rb_cProc)) {
data = (void *) buffer;
len = -1;
} else {
rb_raise(rb_eTypeError, "wrong argument type %s (expected String or Proc)", rb_class2name(CLASS_OF(buffer)));
}
archive = rb_funcall(Archive, rb_intern("new"), 0);
Data_Get_Struct(archive, struct zipruby_archive, p_archive);
if ((p_archive->tmpfilnam = zipruby_tmpnam(data, len)) == NULL) {
rb_raise(Error, "Open archive failed: Failed to create temporary file");
}
if ((p_archive->archive = zip_open(p_archive->tmpfilnam, i_flags, &errorp)) == NULL) {
char errstr[ERRSTR_BUFSIZE];
zip_error_to_str(errstr, ERRSTR_BUFSIZE, errorp, errno);
rb_raise(Error, "Open archive failed: %s", errstr);
}
// p_archive->archive->comp_level = i_comp_level;
p_archive->path = rb_str_new2(p_archive->tmpfilnam);
p_archive->flags = i_flags;
p_archive->buffer = buffer;
p_archive->sources = rb_ary_new();
if (rb_block_given_p()) {
VALUE retval;
int status;
retval = rb_protect(rb_yield, archive, &status);
zipruby_archive_close(archive);
if (status != 0) {
rb_jump_tag(status);
}
return buffer_is_temporary ? buffer : retval;
} else {
return archive;
}
}
开发者ID:fjg,项目名称:zipruby,代码行数:84,代码来源:zipruby_archive.c
示例17: blockGiven
bool blockGiven()
{
return rb_block_given_p();
}
开发者ID:Groogy,项目名称:rbSFML,代码行数:4,代码来源:base.cpp
示例18: rbffi_SetupCallParams
void
rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, NativeType* paramTypes,
FFIStorage* paramStorage, void** ffiValues,
VALUE* callbackParameters, int callbackCount, VALUE enums)
{
VALUE callbackProc = Qnil;
FFIStorage* param = ¶mStorage[0];
int i, argidx, cbidx, argCount;
if (paramCount != -1 && paramCount != argc) {
if (argc == (paramCount - 1) && callbackCount == 1 && rb_block_given_p()) {
callbackProc = rb_block_proc();
} else {
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, paramCount);
}
}
argCount = paramCount != -1 ? paramCount : argc;
for (i = 0, argidx = 0, cbidx = 0; i < argCount; ++i) {
int type = argidx < argc ? TYPE(argv[argidx]) : T_NONE;
ffiValues[i] = param;
switch (paramTypes[i]) {
case NATIVE_INT8:
param->s8 = getSignedInt(argv[argidx++], type, -128, 127, "char", Qnil);
ADJ(param, INT8);
break;
case NATIVE_INT16:
param->s16 = getSignedInt(argv[argidx++], type, -0x8000, 0x7fff, "short", Qnil);
ADJ(param, INT16);
break;
case NATIVE_INT32:
case NATIVE_ENUM:
param->s32 = getSignedInt(argv[argidx++], type, -0x80000000, 0x7fffffff, "int", enums);
ADJ(param, INT32);
break;
case NATIVE_BOOL:
if (type != T_TRUE && type != T_FALSE) {
rb_raise(rb_eTypeError, "wrong argument type (expected a boolean parameter)");
}
param->s8 = argv[argidx++] == Qtrue;
ADJ(param, INT8);
break;
case NATIVE_UINT8:
param->u8 = getUnsignedInt(argv[argidx++], type, 0xff, "unsigned char");
ADJ(param, INT8);
break;
case NATIVE_UINT16:
param->u16 = getUnsignedInt(argv[argidx++], type, 0xffff, "unsigned short");
ADJ(param, INT16);
break;
case NATIVE_UINT32:
/* Special handling/checking for unsigned 32 bit integers */
param->u32 = getUnsignedInt32(argv[argidx++], type);
ADJ(param, INT32);
break;
case NATIVE_INT64:
if (type != T_FIXNUM && type != T_BIGNUM) {
rb_raise(rb_eTypeError, "Expected an Integer parameter");
}
param->i64 = NUM2LL(argv[argidx]);
ADJ(param, INT64);
++argidx;
break;
case NATIVE_UINT64:
if (type != T_FIXNUM && type != T_BIGNUM) {
rb_raise(rb_eTypeError, "Expected an Integer parameter");
}
param->u64 = NUM2ULL(argv[argidx]);
ADJ(param, INT64);
++argidx;
break;
case NATIVE_LONG:
*(ffi_sarg *) param = NUM2LONG(argv[argidx]);
ADJ(param, LONG);
++argidx;
break;
case NATIVE_ULONG:
*(ffi_arg *) param = NUM2ULONG(argv[argidx]);
ADJ(param, LONG);
//.........这里部分代码省略.........
开发者ID:albanpeignier,项目名称:ffi,代码行数:101,代码来源:Call.c
示例19: rb_scan_args
int
rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
{
int i;
const char *p = fmt;
VALUE *var;
va_list vargs;
int f_var = 0, f_block = 0;
int n_lead = 0, n_opt = 0, n_trail = 0, n_mand;
int argi = 0;
if (ISDIGIT(*p)) {
n_lead = *p - '0';
p++;
if (ISDIGIT(*p)) {
n_opt = *p - '0';
p++;
if (ISDIGIT(*p)) {
n_trail = *p - '0';
p++;
goto block_arg;
}
}
}
if (*p == '*') {
f_var = 1;
p++;
if (ISDIGIT(*p)) {
n_trail = *p - '0';
p++;
}
}
block_arg:
if (*p == '&') {
f_block = 1;
p++;
}
if (*p != '\0') {
rb_fatal("bad scan arg format: %s", fmt);
}
n_mand = n_lead + n_trail;
if (argc < n_mand)
goto argc_error;
va_start(vargs, fmt);
/* capture leading mandatory arguments */
for (i = n_lead; i-- > 0; ) {
var = va_arg(vargs, VALUE *);
if (var) *var = argv[argi];
argi++;
}
/* capture optional arguments */
for (i = n_opt; i-- > 0; ) {
var = va_arg(vargs, VALUE *);
if (argi < argc - n_trail) {
if (var) *var = argv[argi];
argi++;
}
else {
if (var) *var = Qnil;
}
}
/* capture variable length arguments */
if (f_var) {
int n_var = argc - argi - n_trail;
var = va_arg(vargs, VALUE *);
if (0 < n_var) {
if (var) *var = rb_ary_new4(n_var, &argv[argi]);
argi += n_var;
}
else {
if (var) *var = rb_ary_new();
}
}
/* capture trailing mandatory arguments */
for (i = n_trail; i-- > 0; ) {
var = va_arg(vargs, VALUE *);
if (var) *var = argv[argi];
argi++;
}
/* capture iterator block */
if (f_block) {
var = va_arg(vargs, VALUE *);
if (rb_block_given_p()) {
*var = rb_block_proc();
}
else {
*var = Qnil;
}
}
va_end(vargs);
if (argi < argc)
goto argc_error;
return argc;
//.........这里部分代码省略.........
开发者ID:technohippy,项目名称:oruby,代码行数:101,代码来源:class.c
示例20: rb_scan_args
//.........这里部分代码省略.........
}
block_arg:
if (*p == ':') {
f_hash = 1;
p++;
}
if (*p == '&') {
f_block = 1;
p++;
}
if (*p != '\0') {
rb_fatal("bad scan arg format: %s", fmt);
}
n_mand = n_lead + n_trail;
if (argc < n_mand)
goto argc_error;
va_start(vargs, fmt);
/* capture an option hash - phase 1: pop */
if (f_hash && n_mand < argc) {
VALUE last = argv[argc - 1];
if (NIL_P(last)) {
/* nil is taken as an empty option hash only if it is not
ambiguous; i.e. '*' is not specified and arguments are
given more than sufficient */
if (!f_var && n_mand + n_opt < argc)
argc--;
}
else {
hash = rb_check_hash_type(last);
if (!NIL_P(hash)) {
VALUE opts = rb_extract_keywords(&hash);
if (!hash) argc--;
hash = opts ? opts : Qnil;
}
}
}
/* capture leading mandatory arguments */
for (i = n_lead; i-- > 0; ) {
var = va_arg(vargs, VALUE *);
if (var) *var = argv[argi];
argi++;
}
/* capture optional arguments */
for (i = n_opt; i-- > 0; ) {
var = va_arg(vargs, VALUE *);
if (argi < argc - n_trail) {
if (var) *var = argv[argi];
argi++;
}
else {
if (var) *var = Qnil;
}
}
/* capture variable length arguments */
if (f_var) {
int n_var = argc - argi - n_trail;
var = va_arg(vargs, VALUE *);
if (0 < n_var) {
if (var) *var = rb_ary_new4(n_var, &argv[argi]);
argi += n_var;
}
else {
if (var) *var = rb_ary_new();
}
}
/* capture trailing mandatory arguments */
for (i = n_trail; i-- > 0; ) {
var = va_arg(vargs, VALUE *);
if (var) *var = argv[argi];
argi++;
}
/* capture an option hash - phase 2: assignment */
if (f_hash) {
var = va_arg(vargs, VALUE *);
if (var) *var = hash;
}
/* capture iterator block */
if (f_block) {
var = va_arg(vargs, VALUE *);
if (rb_block_given_p()) {
*var = rb_block_proc();
}
else {
*var = Qnil;
}
}
va_end(vargs);
if (argi < argc) {
argc_error:
rb_error_arity(argc, n_mand, f_var ? UNLIMITED_ARGUMENTS : n_mand + n_opt);
}
return argc;
}
开发者ID:Danylyuk,项目名称:first_app,代码行数:101,代码来源:class.c
注:本文中的rb_block_given_p函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论