[Rubycocoa-devel 959] Re: suggestion: dup method of NSPoint, NSSize, NSPoint and NSRange

Back to archive index

Satoshi Nakagawa snaka****@infot*****
Wed Jun 6 04:02:30 JST 2007


Hi.

I have tested r1817, it works good.
Thank you.

--
Satoshi Nakagawa


On 2007/06/06, at 2:48, Laurent Sansonetti wrote:

> Committed as r1817.
>
> On Jun 5, 2007, at 9:10 AM, Laurent Sansonetti wrote:
>
>> I think it's better/faster to do this at the C level. Also, this will
>> define #dup only for structure boxed types (and not opaque boxed
>> types, like NSZone).
>>
>> Laurent
>>
>> Index: framework/src/objc/BridgeSupport.m
>> ===================================================================
>> --- framework/src/objc/BridgeSupport.m	(revision 1815)
>> +++ framework/src/objc/BridgeSupport.m	(working copy)
>> @@ -521,9 +521,10 @@
>>  {
>>    void *  data;
>>    int     i;
>> +
>> +  if (success != NULL)
>> +    *success = NO;
>>
>> -  *success = NO;
>> -
>>    if (NIL_P(obj))
>>      return NULL;
>>
>> @@ -564,8 +565,10 @@
>>    }
>>    Data_Get_Struct(obj, void, data);
>>
>> -  *size = bs_boxed_size(bs_boxed);
>> -  *success = YES;
>> +  if (size != NULL)
>> +    *size = bs_boxed_size(bs_boxed);
>> +  if (success != NULL)
>> +    *success = YES;
>>
>>    return data;
>>  }
>> @@ -790,6 +793,18 @@
>>  }
>>
>>  static VALUE
>> +rb_bs_struct_dup (VALUE rcv)
>> +{
>> +  struct bsBoxed * bs_struct;
>> +  void  *data;
>> +
>> +  bs_struct = rb_bs_struct_get_bs_struct(CLASS_OF(rcv));
>> +  data = rb_bs_boxed_struct_get_data(rcv, bs_struct, NULL, NULL, NO);
>> +
>> +  return rb_bs_boxed_new_from_ocdata(bs_struct, data);
>> +}
>> +
>> +static VALUE
>>  rb_define_bs_boxed_class (VALUE mOSX, const char *name, const char
>> *encoding)
>>  {
>>    VALUE klass;
>> @@ -851,6 +866,7 @@
>>    }
>>    rb_define_singleton_method(klass, "new", rb_bs_struct_new, -1);
>>    rb_define_method(klass, "==", rb_bs_struct_is_equal, 1);
>> +  rb_define_method(klass, "dup", rb_bs_struct_dup, 0);
>>
>>    // Allocate and return bs_boxed entry.
>>    bs_boxed = init_bs_boxed(bsBoxedStructType, name, encoding, klass);
>>
>>
>>
>> On Jun 5, 2007, at 8:07 AM, kimura wataru wrote:
>>
>>> like this, Laurent?
>>>
>>> === framework/src/ruby/osx/objc/oc_types.rb
>>> ==================================================================
>>> --- framework/src/ruby/osx/objc/oc_types.rb	(revision 166)
>>> +++ framework/src/ruby/osx/objc/oc_types.rb	(local)
>>> @@ -37,3 +37,12 @@
>>>  alias_method :old_to_a, :to_a # To remove a warning.
>>>  def to_a; [origin.to_a, size.to_a]; end
>>> end
>>> +
>>> +class OSX::Boxed
>>> +
>>> +  def dup
>>> +    values = self.class.fields.map {|sym| self.send(sym)}
>>> +    self.class.new(*values)
>>> +  end
>>> +
>>> +end
>>>
>>> On Tue, 5 Jun 2007 08:02:24 -0700, Laurent Sansonetti wrote:
>>>> Hi Satoshi-san,
>>>>
>>>> Good suggestion. I will add a general OSX::Boxed#dup method. All
>>>> boxed
>>>> structures inherit from OSX::Boxed.
>>>>
>>>> Laurent
>>>>
>>>> On Jun 5, 2007, at 7:30 AM, Satoshi Nakagawa wrote:
>>>>
>>>>> Hi.
>>>>>
>>>>> Currently when I wrote some drawing code, I often want to dup
>>>>> NSRect, NSSize and NSPoint.
>>>>>
>>> -- 
>>> kimura wataru
>>>
>>> _______________________________________________
>>> Rubycocoa-devel mailing list
>>> Rubyc****@lists*****
>>> http://lists.sourceforge.jp/mailman/listinfo/rubycocoa-devel
>>
>> _______________________________________________
>> Rubycocoa-devel mailing list
>> Rubyc****@lists*****
>> http://lists.sourceforge.jp/mailman/listinfo/rubycocoa-devel
>
> _______________________________________________
> Rubycocoa-devel mailing list
> Rubyc****@lists*****
> http://lists.sourceforge.jp/mailman/listinfo/rubycocoa-devel




More information about the Rubycocoa-devel mailing list
Back to archive index