本文整理汇总了C++中rb_block_given_p函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_block_given_p函数的具体用法?C++ rb_block_given_p怎么用?C++ rb_block_given_p使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_block_given_p函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
//.........这里部分代码省略.........
示例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;
};
}
示例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);
}
示例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;
}
示例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;
//.........这里部分代码省略.........
示例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;
}