コード例 #1
0
ファイル: mochilo_pack.c プロジェクト: adelcambre/mochilo
void mochilo_pack_symbol(mochilo_buf *buf, VALUE rb_symbol)
{
	long size;
	const char *name;

	name = rb_id2name(SYM2ID(rb_symbol));
	size = strlen(name);

	if (size < 0x100) {
		uint8_t lead = size;
		mochilo_buf_putc(buf, MSGPACK_T_SYM);
		mochilo_buf_putc(buf, lead);
	} else {
		rb_raise(rb_eMochiloPackError,
			"Symbol too long: must be under %d bytes, %ld given", 0x100, size);
	}

	mochilo_buf_put(buf, name, size);
}
コード例 #2
0
ファイル: sfcc.c プロジェクト: steakknife/ruby-sfcc
const char *
to_charptr(VALUE v)
{
  const char *str;
  if (SYMBOL_P(v)) {
    str = rb_id2name(SYM2ID(v));
  }
  else if (TYPE(v) == T_STRING) {
    str = StringValuePtr(v);
  }
  else if (v == Qnil) {
    str = NULL;
  }
  else {
    VALUE v_s = rb_funcall(v, rb_intern("to_s"), 0 );
    str = StringValuePtr(v_s);
  }
  return str;
}
コード例 #3
0
ファイル: ruby.c プロジェクト: ogochan/libmondai
static VALUE
recval_get_field(VALUE self)
{
    VALUE obj;
    value_struct_data *data;
    ValueStruct *val;
    char *name = rb_id2name(ruby_frame->last_func);

    Data_Get_Struct(self, value_struct_data, data);

    if (!NIL_P(obj = rb_hash_aref(data->cache, rb_str_new2(name))))
        return obj;

    val = GetRecordItem(data->value, name);
    obj = get_value(val);
    if (CACHEABLE(val))
        rb_hash_aset(data->cache, rb_str_new2(name), obj);
    return obj;
}
コード例 #4
0
ファイル: class.c プロジェクト: asimoov/emscripted-ruby
static int
ins_methods_push(ID name, long type, VALUE ary, long visi)
{
    if (type == -1) return ST_CONTINUE;
    switch (visi) {
      case NOEX_PRIVATE:
      case NOEX_PROTECTED:
      case NOEX_PUBLIC:
	visi = (type == visi);
	break;
      default:
	visi = (type != NOEX_PRIVATE);
	break;
    }
    if (visi) {
	rb_ary_push(ary, rb_str_new2(rb_id2name(name)));
    }
    return ST_CONTINUE;
}
コード例 #5
0
ファイル: rbgtktoolbutton.c プロジェクト: benolee/ruby-gnome2
static VALUE
toolbutton_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE obj, label;
    GtkToolItem* item;

    rb_scan_args(argc, argv, "02", &obj, &label);

    if (TYPE(obj) == T_SYMBOL){
        item = gtk_tool_button_new_from_stock(rb_id2name(SYM2ID(obj)));
    } else if (TYPE(obj) == T_STRING){
        item = gtk_tool_button_new_from_stock(RVAL2CSTR(obj));
    } else {
        item = gtk_tool_button_new(GTK_WIDGET(RVAL2GOBJ(obj)), 
                                   NIL_P(label) ? NULL : RVAL2CSTR(label));
    }
    RBGTK_INITIALIZE(self, item);
    return Qnil;
}
コード例 #6
0
    VALUE
cb_unify_key(struct cb_bucket_st *bucket, VALUE key, int apply_prefix)
{
    VALUE ret = Qnil, tmp;

    if (RTEST(bucket->key_prefix_val) && apply_prefix) {
        ret = rb_str_dup(bucket->key_prefix_val);
    }
    switch (TYPE(key)) {
        case T_STRING:
            return NIL_P(ret) ? key : rb_str_concat(ret, key);
        case T_SYMBOL:
            tmp = STR_NEW_CSTR(rb_id2name(SYM2ID(key)));
            return NIL_P(ret) ? tmp : rb_str_concat(ret, tmp);
        default:    /* call #to_str or raise error */
            tmp = StringValue(key);
            return NIL_P(ret) ? tmp : rb_str_concat(ret, tmp);
    }
}
コード例 #7
0
static void
vm_define_method(rb_thread_t *th, VALUE obj, ID id, VALUE iseqval,
		 rb_num_t is_singleton, NODE *cref)
{
    VALUE klass = cref->nd_clss;
    int noex = (int)cref->nd_visi;
    rb_iseq_t *miseq;
    GetISeqPtr(iseqval, miseq);

    if (miseq->klass) {
	iseqval = rb_iseq_clone(iseqval, 0);
	RB_GC_GUARD(iseqval);
	GetISeqPtr(iseqval, miseq);
    }

    if (NIL_P(klass)) {
	rb_raise(rb_eTypeError, "no class/module to add method");
    }

    if (is_singleton) {
	if (FIXNUM_P(obj) || SYMBOL_P(obj)) {
	    rb_raise(rb_eTypeError,
		     "can't define singleton method \"%s\" for %s",
		     rb_id2name(id), rb_obj_classname(obj));
	}

	rb_check_frozen(obj);
	klass = rb_singleton_class(obj);
	noex = NOEX_PUBLIC;
    }

    /* dup */
    COPY_CREF(miseq->cref_stack, cref);
    miseq->cref_stack->nd_visi = NOEX_PUBLIC;
    miseq->klass = klass;
    miseq->defined_method_id = id;
    rb_add_method(klass, id, VM_METHOD_TYPE_ISEQ, miseq, noex);

    if (!is_singleton && noex == NOEX_MODFUNC) {
	rb_add_method(rb_singleton_class(klass), id, VM_METHOD_TYPE_ISEQ, miseq, NOEX_PUBLIC);
    }
    INC_VM_STATE_VERSION();
}
コード例 #8
0
ファイル: rbgtkaction.c プロジェクト: Mazwak/ruby-gnome2
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE name, label, tooltip, stock_id;
    const gchar *stock = NULL;

    rb_scan_args(argc, argv, "22", &name, &label, &tooltip, &stock_id);

    if (TYPE(stock_id) == T_SYMBOL) {
        stock = rb_id2name(SYM2ID(stock_id));
    } else if (TYPE(stock_id) == T_STRING){
        stock = RVAL2CSTR(stock_id);
    }

    G_INITIALIZE(self, gtk_action_new(RVAL2CSTR(name), RVAL2CSTR(label),
                                      NIL_P(tooltip) ? NULL : RVAL2CSTR(tooltip),
                                      stock));
    return Qnil;
}
コード例 #9
0
ファイル: struct.c プロジェクト: Danylyuk/first_app
static VALUE
rb_struct_aref_id(VALUE s, ID id)
{
    VALUE *ptr, members, *ptr_members;
    long i, len;

    ptr = RSTRUCT_PTR(s);
    members = rb_struct_members(s);
    ptr_members = RARRAY_PTR(members);
    len = RARRAY_LEN(members);
    for (i=0; i<len; i++) {
	if (SYM2ID(ptr_members[i]) == id) {
	    return ptr[i];
	}
    }
    rb_name_error(id, "no member '%s' in struct", rb_id2name(id));

    UNREACHABLE;
}
コード例 #10
0
static VALUE
gobj_get_property(VALUE self, VALUE prop_name)
{
    GParamSpec* pspec;
    const char* name;

    if (SYMBOL_P(prop_name))
        name = rb_id2name(SYM2ID(prop_name));
    else
        name = StringValuePtr(prop_name);

    pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(RVAL2GOBJ(self)),
                                         name);

    if (!pspec)
        rb_raise(eNoPropertyError, "No such property: %s", name);
    else {
        // FIXME: use rb_ensure to call g_value_unset()
        GValueToRValueFunc getter = NULL;
        GValue gval = {0,};
        VALUE ret;

        {
            VALUE table = rb_hash_aref(type_to_prop_getter_table,
                                       INT2FIX(pspec->owner_type));
            if (!NIL_P(table)){
                VALUE obj = rb_hash_aref(table, CSTR2RVAL(g_param_spec_get_name(pspec)));
                if (!NIL_P(obj))
                    Data_Get_Struct(obj, void, getter);
            }
        }

        g_value_init(&gval, G_PARAM_SPEC_VALUE_TYPE(pspec));
        g_object_get_property(RVAL2GOBJ(self), name, &gval);

        ret = getter ? getter(&gval) : GVAL2RVAL(&gval);
        g_value_unset(&gval);

        G_CHILD_SET(self, rb_intern(name), ret);

        return ret;
    }
}
コード例 #11
0
VALUE
rb_struct_getmember(VALUE obj, ID id)
{
    VALUE members, slot, *ptr, *ptr_members;
    long i, len;

    ptr = RSTRUCT_PTR(obj);
    members = rb_struct_members(obj);
    ptr_members = RARRAY_PTR(members);
    slot = ID2SYM(id);
    len = RARRAY_LEN(members);
    for (i=0; i<len; i++) {
	if (ptr_members[i] == slot) {
	    return ptr[i];
	}
    }
    rb_name_error(id, "%s is not struct member", rb_id2name(id));
    return Qnil;		/* not reached */
}
コード例 #12
0
/* Font/Text functions */
static   VALUE
cr_select_font_face (int argc, VALUE *argv, VALUE self)
{
  VALUE rb_family, rb_slant, rb_weight;
  const char *family;
  cairo_font_slant_t slant;
  cairo_font_weight_t weight;

  rb_scan_args(argc, argv, "03", &rb_family, &rb_slant, &rb_weight);

  if (NIL_P (rb_family))
    {
      family = "";
    }
  else if (rb_cairo__is_kind_of (rb_family, rb_cString))
    {
      family = RSTRING_PTR (rb_family);
    }
  else if (rb_cairo__is_kind_of (rb_family, rb_cSymbol))
    {
      family = rb_id2name (SYM2ID (rb_family));
    }
  else
    {
      rb_raise (rb_eArgError,
                "family name should be nil, String or Symbol: %s",
                rb_cairo__inspect (rb_family));
    }

  if (NIL_P (rb_slant))
    slant = CAIRO_FONT_SLANT_NORMAL;
  else
    slant = RVAL2CRFONTSLANT (rb_slant);

  if (NIL_P (rb_weight))
    weight = CAIRO_FONT_WEIGHT_NORMAL;
  else
    weight = RVAL2CRFONTWEIGHT (rb_weight);

  cairo_select_font_face (_SELF, family, slant, weight);
  cr_check_status (_SELF);
  return self;
}
コード例 #13
0
ファイル: eval_error.c プロジェクト: AdamDotCom/my-rvm
static void
error_pos(void)
{
    const char *sourcefile = rb_sourcefile();
    int sourceline = rb_sourceline();

    if (sourcefile) {
	if (sourceline == 0) {
	    warn_printf("%s", sourcefile);
	}
	else if (rb_frame_callee()) {
	    warn_printf("%s:%d:in `%s'", sourcefile, sourceline,
			rb_id2name(rb_frame_callee()));
	}
	else {
	    warn_printf("%s:%d", sourcefile, sourceline);
	}
    }
}
コード例 #14
0
ファイル: rb_xmmsclient.c プロジェクト: dsheeler/xmms2
/*
 * call-seq:
 *  xc.playback_volume_set(channel, volume) -> result
 *
 * Sets playback volume for _channel_ to _volume_.
 */
static VALUE
c_playback_volume_set (VALUE self, VALUE channel, VALUE volume)
{
	RbXmmsClient *xmms = NULL;
	xmmsc_result_t *res;

	Data_Get_Struct (self, RbXmmsClient, xmms);

	CHECK_DELETED (xmms);

	Check_Type (channel, T_SYMBOL);
	Check_Type (volume, T_FIXNUM);

	res = xmmsc_playback_volume_set (xmms->real,
	                                 rb_id2name (SYM2ID (channel)),
	                                 NUM2UINT (volume));

	return TO_XMMS_CLIENT_RESULT (self, res);
}
コード例 #15
0
ファイル: vm_eval.c プロジェクト: 3runo5ouza/rhodes
static VALUE
specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
{
    if (rb_block_given_p()) {
	if (argc > 0) {
	    rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
	}
	return yield_under(klass, self, Qundef);
    }
    else {
	const char *file = "(eval)";
	int line = 1;

//RHO
    rb_raise(rb_eNotImpError, "Not implemented: only eval of block is supported.");
//RHO

	if (argc == 0) {
	    rb_raise(rb_eArgError, "block not supplied");
	}
	else {
	    if (rb_safe_level() >= 4) {
		StringValue(argv[0]);
	    }
	    else {
		SafeStringValue(argv[0]);
	    }
	    if (argc > 3) {
		const char *name = rb_id2name(rb_frame_callee());
		rb_raise(rb_eArgError,
			 "wrong number of arguments: %s(src) or %s{..}",
			 name, name);
	    }
	    if (argc > 2)
		line = NUM2INT(argv[2]);
	    if (argc > 1) {
		file = StringValuePtr(argv[1]);
	    }
	}
	return eval_under(klass, self, argv[0], file, line);
    }
}
コード例 #16
0
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE stock_id;
    GtkToolItem* item;

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

    if (NIL_P(stock_id)){
        item = gtk_toggle_tool_button_new();
    } else {
        if (TYPE(stock_id) == T_SYMBOL){
            item = gtk_toggle_tool_button_new_from_stock(rb_id2name(SYM2ID(stock_id)));
        } else {
            item = gtk_toggle_tool_button_new_from_stock(RVAL2CSTR(stock_id));
        }
    }
    RBGTK_INITIALIZE(self, item);
    return Qnil;
}
コード例 #17
0
ファイル: ipsocket.c プロジェクト: SongJungHwan/hwan
int
rsock_revlookup_flag(VALUE revlookup, int *norevlookup)
{
#define return_norevlookup(x) {*norevlookup = (x); return 1;}
    ID id;

    switch (revlookup) {
      case Qtrue:  return_norevlookup(0);
      case Qfalse: return_norevlookup(1);
      case Qnil: break;
      default:
	Check_Type(revlookup, T_SYMBOL);
	id = SYM2ID(revlookup);
	if (id == id_numeric) return_norevlookup(1);
	if (id == id_hostname) return_norevlookup(0);
	rb_raise(rb_eArgError, "invalid reverse_lookup flag: :%s", rb_id2name(id));
    }
    return 0;
#undef return_norevlookup
}
コード例 #18
0
ファイル: struct.c プロジェクト: asimoov/emscripted-ruby
static VALUE
rb_struct_set(VALUE obj, VALUE val)
{
    VALUE members, slot;
    ID id;
    long i;

    members = rb_struct_members(obj);
    rb_struct_modify(obj);
    id = ruby_frame->orig_func;
    for (i=0; i<RARRAY(members)->len; i++) {
	slot = RARRAY(members)->ptr[i];
	if (rb_id_attrset(SYM2ID(slot)) == id) {
	    return RSTRUCT(obj)->ptr[i] = val;
	}
    }
    rb_name_error(ruby_frame->last_func, "`%s' is not a struct member",
		  rb_id2name(id));
    return Qnil;		/* not reached */
}
コード例 #19
0
ファイル: rb_change.c プロジェクト: jarmo/wdm
static VALUE
extract_change_type_from_notification(const PFILE_NOTIFY_INFORMATION info) {
    ID type;

    switch(info->Action) {
    case FILE_ACTION_ADDED: type = wdm_rb_sym_added; break;
    case FILE_ACTION_REMOVED: type = wdm_rb_sym_removed; break;
    case FILE_ACTION_MODIFIED: type = wdm_rb_sym_modified; break;
    case FILE_ACTION_RENAMED_OLD_NAME: type = wdm_rb_sym_renamed_old_file; break;
    case FILE_ACTION_RENAMED_NEW_NAME: type = wdm_rb_sym_renamed_new_file; break;
    default:
        rb_raise(eWDM_Error, "Unknown change happened to a file in a watched directory!");
    }

#if WDM_DEBUG_ENABLED // Used to avoid the func call when in release mode
    WDM_DEBUG("change type: '%s'", rb_id2name(type));
#endif

    return ID2SYM(type);
}
コード例 #20
0
ファイル: mouse.c プロジェクト: AXElements/mouse
/*
 * Perform a rotation gesture in the given `direction` the given `angle` degrees
 *
 * Possible directions are:
 *
 *   - `:cw`, ':clockwise`, ':clock_wise` to rotate in the clockwise
 *     direction
 *   - `:ccw`, ':counter_clockwise`, `:counter_clock_wise` to rotate in
 *     the the counter clockwise direction
 *
 * The `angle` parameter is a number of degrees to rotate. There are 360
 * degrees in a full rotation, as you would expect in Euclidian geometry.
 *
 * You can also optionally specify a point on screen for the mouse
 * pointer to be moved to before the gesture begins. The movement will
 * be instantaneous. Default `point` is {#current_position}.
 *
 * An animation duration can also be specified. The default is 0.2 seconds.
 *
 * @overload rotate(direction, angle)
 *   @param direction [Symbol]
 *   @param angle [Float]
 *   @return [CGPoint]
 * @overload rotate(direction, angle, point)
 *   @param direction [Symbol]
 *   @param angle [Float]
 *   @param point [CGPoint]
 *   @return [CGPoint]
 * @overload rotate(direction, angle, point, duration)
 *   @param direction [Symbol]
 *   @param angle [Float]
 *   @param point [CGPoint]
 *   @param duration [Float]
 *   @return [CGPoint]
 */
static
VALUE
rb_mouse_rotate(const int argc, VALUE* const argv, UNUSED const VALUE self)
{
    if (argc < 2)
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 2+)", argc);


    const VALUE input_dir = argv[0];
    CGRotateDirection direction = kCGRotateNone;

    if      (input_dir == sym_cw ||
             input_dir == sym_clockwise ||
             input_dir == sym_clock_wise)
        direction = kCGRotateClockwise;

    else if (input_dir == sym_ccw ||
             input_dir == sym_counter_clockwise ||
             input_dir == sym_counter_clock_wise)
        direction = kCGRotateCounterClockwise;
    else
        rb_raise(rb_eArgError,
                 "invalid rotation direction `%s'",
                 rb_id2name(SYM2ID(input_dir)));

    const double angle = NUM2DBL(argv[1]);

    if (argc == 2) {
        mouse_rotate(direction, angle);
        return CURRENT_POSITION;
    }

    const CGPoint point = rb_mouse_unwrap_point(argv[2]);
    if (argc == 3) {
        mouse_rotate2(direction, angle, point);
        return CURRENT_POSITION;
    }

    mouse_rotate3(direction, angle, point, NUM2DBL(argv[3]));
    return CURRENT_POSITION;
}
コード例 #21
0
ファイル: vm_eval.c プロジェクト: 3runo5ouza/rhodes
static VALUE
rb_f_local_variables(void)
{
    VALUE ary = rb_ary_new();
    rb_thread_t *th = GET_THREAD();
    rb_control_frame_t *cfp =
	vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp));
    int i;

    while (cfp) {
	if (cfp->iseq) {
	    for (i = 0; i < cfp->iseq->local_table_size; i++) {
		ID lid = cfp->iseq->local_table[i];
		if (lid) {
		    const char *vname = rb_id2name(lid);
		    /* should skip temporary variable */
		    if (vname) {
			rb_ary_push(ary, ID2SYM(lid));
		    }
		}
	    }
	}
	if (cfp->lfp != cfp->dfp) {
	    /* block */
	    VALUE *dfp = GC_GUARDED_PTR_REF(cfp->dfp[0]);

	    if (vm_collect_local_variables_in_heap(th, dfp, ary)) {
		break;
	    }
	    else {
		while (cfp->dfp != dfp) {
		    cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
		}
	    }
	}
	else {
	    break;
	}
    }
    return ary;
}
コード例 #22
0
ファイル: rbgtkdrag.c プロジェクト: Vasfed/ruby-gnome2
static VALUE
rg_m_source_set_icon(int argc, VALUE *argv, VALUE self)
{
    VALUE widget, obj, pixmap = Qnil, mask = Qnil;

    rb_scan_args(argc, argv, "22", &widget, &obj, &pixmap, &mask);
    if (argc == 4){
        gtk_drag_source_set_icon(RVAL2WIDGET(widget), GDK_COLORMAP(RVAL2GOBJ(obj)),
                                 GDK_PIXMAP(RVAL2GOBJ(pixmap)), 
                                 GDK_BITMAP(RVAL2GOBJ(mask)));
    } else if (argc == 2){
        if (TYPE(obj) == T_SYMBOL){
            gtk_drag_source_set_icon_stock(RVAL2WIDGET(widget), rb_id2name(SYM2ID(obj)));
        } else {
            gtk_drag_source_set_icon_pixbuf(RVAL2WIDGET(widget), GDK_PIXBUF(RVAL2GOBJ(obj)));
        }
    } else {
        rb_raise(rb_eArgError, "need 2 or 4 arguments");
    }
    return self;
}
コード例 #23
0
static VALUE
rb_struct_set(VALUE obj, VALUE val)
{
    VALUE members, slot, *ptr, *ptr_members;
    long i, len;

    members = rb_struct_members(obj);
    ptr_members = RARRAY_PTR(members);
    len = RARRAY_LEN(members);
    rb_struct_modify(obj);
    ptr = RSTRUCT_PTR(obj);
    for (i=0; i<len; i++) {
	slot = ptr_members[i];
	if (rb_id_attrset(SYM2ID(slot)) == rb_frame_this_func()) {
	    return ptr[i] = val;
	}
    }
    rb_name_error(rb_frame_this_func(), "`%s' is not a struct member",
		  rb_id2name(rb_frame_this_func()));
    return Qnil;		/* not reached */
}
コード例 #24
0
ファイル: struct.c プロジェクト: AdamDotCom/my-rvm
static VALUE
rb_struct_aset_id(VALUE s, ID id, VALUE val)
{
    VALUE members;
    long i, len;

    members = rb_struct_members(s);
    rb_struct_modify(s);
    len = RARRAY_LEN(members);
    if (RSTRUCT_LEN(s) != RARRAY_LEN(members)) {
	rb_raise(rb_eTypeError, "struct size differs (%ld required %ld given)",
		 RARRAY_LEN(members), RSTRUCT_LEN(s));
    }
    for (i=0; i<len; i++) {
	if (SYM2ID(RARRAY_PTR(members)[i]) == id) {
	    RSTRUCT_PTR(s)[i] = val;
	    return val;
	}
    }
    rb_name_error(id, "no member '%s' in struct", rb_id2name(id));
}
コード例 #25
0
static VALUE
rb_struct_set(VALUE obj, VALUE val)
{
    VALUE members, slot;
    long i, len;

    members = rb_struct_members(obj);
    len = RARRAY_LEN(members);
    rb_struct_modify(obj);
    for (i=0; i<len; i++) {
        slot = RARRAY_AREF(members, i);
        if (rb_id_attrset(SYM2ID(slot)) == rb_frame_this_func()) {
            RSTRUCT_SET(obj, i, val);
            return val;
        }
    }
    rb_name_error(rb_frame_this_func(), "`%s' is not a struct member",
                  rb_id2name(rb_frame_this_func()));

    UNREACHABLE;
}
コード例 #26
0
ファイル: ruby_symbol.c プロジェクト: isuruf/symengine.rb
VALUE csymbol_init(VALUE self, VALUE name_or_id) {
    char *str_ptr;

    switch (TYPE(name_or_id)) {
    case T_STRING:
      str_ptr = StringValueCStr(name_or_id);
      break;
    case T_SYMBOL:
      str_ptr = rb_id2name(rb_to_id(name_or_id));
      break;      
    default:
      rb_raise(rb_eTypeError, "wrong argument type %s (expected Symbol or String)", rb_obj_classname(name_or_id));
    }

    basic_struct *this;
    Data_Get_Struct(self, basic_struct, this);

    symbol_set(this, str_ptr);

    return self;
}
コード例 #27
0
ファイル: gcd.c プロジェクト: JosephKu/MacRuby
/*
 *  call-seq:
 *     Dispatch::Queue.concurrent(priority=:default)    => Dispatch::Queue
 *
 *  Returns one of the global concurrent priority queues.
 * 
 *  A dispatch queue is a FIFO queue that accepts tasks in the form of a block. 
 *  Blocks submitted to dispatch queues are executed on a pool of threads fully 
 *  managed by the system. Dispatched tasks execute one at a time in FIFO order.
 *  GCD takes take of using multiple cores effectively and better accommodate 
 *  the needs of all running applications, matching them to the 
 *  available system resources in a balanced fashion.
 *   
 *  Use concurrent queues to execute large numbers of tasks concurrently.
 *  GCD automatically creates three concurrent dispatch queues that are global 
 *  to your application and are differentiated only by their priority level. 
 *  
 *  The three priority levels are: +:low+, +:default+, 
 *  +:high+, corresponding to the DISPATCH_QUEUE_PRIORITY_HIGH, 
 *  DISPATCH_QUEUE_PRIORITY_DEFAULT, and DISPATCH_QUEUE_PRIORITY_LOW 
 *  (detailed in the dispatch_queue_create(3)[http://developer.apple.com/mac/library/DOCUMENTATION/Darwin/Reference/ManPages/man3/dispatch_queue_create.3.html]
 *  man page). The GCD thread dispatcher
 *  will perform actions submitted to the high priority queue before any actions 
 *  submitted to the default or low queues, and will only perform actions on the 
 *  low queues if there are no actions queued on the high or default queues.
 *
 *     gcdq = Dispatch::Queue.concurrent(:high)
 *     5.times { gcdq.async { print 'foo' } }
 *     gcdq_2 = Dispatch::Queue.concurrent(:low)
 *     gcdq_2.sync { print 'bar' }  # will always print 'foofoofoofoofoobar'.
 *
 */
static VALUE
rb_queue_get_concurrent(VALUE klass, SEL sel, int argc, VALUE *argv)
{
    VALUE priority;
    rb_scan_args(argc, argv, "01", &priority);
    if (!NIL_P(priority)) {
	ID id = rb_to_id(priority);
	if (id == high_priority_id) {
	    return qHighPriority;
	}
	else if (id == low_priority_id) {
	    return qLowPriority;
	}
	else if (id != default_priority_id) {
	    rb_raise(rb_eArgError,
		    "invalid priority `%s' (expected either :low, :default or :high)",
		    rb_id2name(id));
        }
    }
    return qDefaultPriority;
}
コード例 #28
0
ファイル: mouse.c プロジェクト: AXElements/mouse
/*
 * Perform a pinch gesture in given `direction`
 *
 * You can optionally specify the `magnification` factor and/or
 * `duration` for the pinch event.
 *
 * Available pinch directions are:
 *
 *   - `:zoom` or `:expand`
 *   - `:unzoom` or `:contract`
 *
 * Magnification is a relative magnification setting. A zoom value of
 * `1.0` means `1.0` more than the current zoom level. `2.0` would be
 * `2.0` levels higher than the current zoom. Default is `1.0`.
 *
 * You can also optionally specify a point on screen for the mouse
 * pointer to be moved to before the gesture begins. The movement will
 * be instantaneous. Default `point` is {#current_position}.
 *
 * An animation duration can also be specified. The default is 0.2 seconds.
 *
 * @overload pinch(direction)
 *   @param direction [Symbol]
 *   @return [CGPoint]
 * @overload pinch(direction, magnification)
 *   @param direction [Symbol]
 *   @param magnification [Float]
 *   @return [CGPoint]
 * @overload pinch(direction, magnification, point)
 *   @param direction [Symbol]
 *   @param magnification [Float]
 *   @param point [CGPoint,#to_point]
 *   @return [CGPoint]
 * @overload pinch(direction, magnification, point, duration)
 *   @param direction [Symbol]
 *   @param magnification [Float]
 *   @param point [CGPoint,#to_point]
 *   @param duration [Float]
 *   @return [CGPoint]
 */
static
VALUE
rb_mouse_pinch(const int argc, VALUE* const argv, UNUSED const VALUE self)
{
    if (!argc)
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 1+)", argc);

    const VALUE input_direction = argv[0];
    CGPinchDirection  direction = kCGPinchNone;

    if (input_direction == sym_expand || input_direction == sym_zoom)
        direction = kCGPinchExpand;
    else if (input_direction == sym_contract || input_direction == sym_unzoom)
        direction = kCGPinchContract;
    else
        rb_raise(rb_eArgError,
                 "invalid pinch direction `%s'",
                 rb_id2name(SYM2ID(input_direction)));

    if (argc == 1) {
        mouse_pinch(direction);
        return CURRENT_POSITION;
    }

    const double magnification = NUM2DBL(argv[1]);
    if (argc == 2) {
        mouse_pinch2(direction, magnification);
        return CURRENT_POSITION;
    }

    const CGPoint point = rb_mouse_unwrap_point(argv[2]);
    if (argc == 3) {
        mouse_pinch3(direction, magnification, point);
        return CURRENT_POSITION;
    }

    const double duration = NUM2DBL(argv[3]);
    mouse_pinch4(direction, magnification, point, duration);
    return CURRENT_POSITION;
}
コード例 #29
0
static GtkWidget*
create_button(VALUE group, VALUE label, VALUE use_underline)
{
    GtkWidget* widget = NULL;

    if (TYPE(label) == T_STRING){
        if (NIL_P(use_underline) || RVAL2CBOOL(use_underline)){
            widget = gtk_radio_button_new_with_mnemonic_from_widget(_GROUP(group), RVAL2CSTR(label));
        } else {
            widget = gtk_radio_button_new_with_label_from_widget(_GROUP(group), RVAL2CSTR(label));
        }
    } else if (TYPE(label) == T_SYMBOL){
        widget = gtk_radio_button_new_with_label_from_widget(_GROUP(group), rb_id2name(SYM2ID(label)));
        gtk_button_set_use_stock(GTK_BUTTON(widget), TRUE);
    } else if (NIL_P(label)){
        widget = gtk_radio_button_new_from_widget(_GROUP(group));
    } else {
        rb_raise(rb_eArgError, "invalid argument %s (expect Symbol(Gtk::Stock constants) or String)", 
                         rb_class2name(CLASS_OF(label)));
    }
    return widget;
}
コード例 #30
0
static void
create_factory_entry(GtkItemFactoryEntry *entry, VALUE self, VALUE path, VALUE item_type, VALUE accel, VALUE extdata, VALUE func, VALUE data)
{
    VALUE action;

    entry->path = NIL_P(path) ? NULL : RVAL2CSTR(path);
    entry->item_type = NIL_P(item_type) ? "<Branch>" : RVAL2CSTR(item_type);
    entry->accelerator = NIL_P(accel) ? NULL : RVAL2CSTR(accel);
        
    if (menuitem_type_check(entry->item_type) == 0) {
        entry->callback = NULL;
    } else {
        if (NIL_P(func)) {
            entry->callback = NULL;
        } else {
            entry->callback = items_exec_callback_wrap;
        }
    }
    action = rb_ary_new3(2, func, data);
    G_RELATIVE(self, action);
    rb_hash_aset(action_table, UINT2NUM(action_id), action);
    entry->callback_action = action_id;
    action_id++;

    if (NIL_P(extdata)){
        entry->extra_data = NULL;
    } else if (TYPE(extdata) == T_STRING){
        entry->extra_data = RVAL2CSTR(extdata);
    } else if (TYPE(extdata) == T_SYMBOL){
        entry->extra_data = rb_id2name(SYM2ID(extdata));
    } else if (RVAL2GTYPE(extdata) == GDK_TYPE_PIXBUF){
        GdkPixdata pixdata;
        guint stream_length_p;
        gdk_pixdata_from_pixbuf(&pixdata, GDK_PIXBUF(RVAL2GOBJ(extdata)), TRUE);
        entry->extra_data = gdk_pixdata_serialize(&pixdata, &stream_length_p);
    } else {
        entry->extra_data = NULL;
    }
}