Sorry, I am be a little confused here, what is the difference between 
@encode(CGPoint) and @encode(NSPoint)? Shouldn't these two yield the same 
result?

Fred

On the road

Am 11.03.2015 um 04:31 schrieb Amr Aboelela <[email protected]>:

> To support CGPoint and CGRect in NSValue, the following needs to be done:
> 
> 
> 
> 1. In GSObjCRuntime.m file:
> 
> id GSObjCGetVal(NSObject *self, const char *key, SEL sel,
> 
>              const char *type, unsigned size, int offset)
> 
> {
> 
> ...
> 
>             case _C_STRUCT_B:
> 
>                 if (strcmp(@encode(CGPoint), type)==0) {
> 
>                     DLog(@"@encode(CGPoint): %s", @encode(CGPoint));
> 
>                     CGPoint   v;
> 
>                     if (sel == 0) {
> 
>                         memcpy((char*)&v, ((char *)self + offset), sizeof(v));
> 
>                     } else {
> 
>                         CGPoint       (*imp)(id, SEL) =
> 
>                         (CGPoint (*)(id, SEL))[self methodForSelector: sel];
> 
>                         v = (*imp)(self, sel);
> 
>                     }
> 
>                     val = [NSValue valueWithCGPoint:v];
> 
>                 } else if (strcmp(@encode(CGRect), type)==0) {
> 
>                     DLog(@"@encode(CGRect): %s", @encode(CGRect));
> 
>                     CGRect    v;
> 
>                     if (sel == 0) {
> 
>                         memcpy((char*)&v, ((char *)self + offset), sizeof(v));
> 
>                     } else {
> 
>                         CGRect        (*imp)(id, SEL) =
> 
>                         (CGRect (*)(id, SEL))[self methodForSelector: sel];
> 
>                         v = (*imp)(self, sel);
> 
>                     }
> 
>                     val = [NSValue valueWithCGRect:v];
> 
>                 } else if (GSSelectorTypesMatch(@encode(NSPoint), type))
> 
> 
>                 {
> 
> ...
> 
> }
> 
> 
> 
> void GSObjCSetVal(NSObject *self, const char *key, id val, SEL sel,
> 
>              const char *type, unsigned size, int offset)
> 
> {
> 
> 
>   ...
> 
>             case _C_STRUCT_B:
> 
>                 if (strcmp(@encode(CGPoint), type)==0) {
> 
>                     DLog(@"@encode(CGPoint): %s", @encode(CGPoint));
> 
>                     CGPoint v = [val CGPointValue];
> 
>                     if (sel == 0) {
> 
>                         CGPoint *ptr = (CGPoint*)((char *)self + offset);
> 
>                         *ptr = v;
> 
>                     } else {
> 
>                         void  (*imp)(id, SEL, CGPoint) =
> 
>                         (void (*)(id, SEL, CGPoint))[self methodForSelector: 
> sel];
> 
>                         (*imp)(self, sel, v);
> 
>                     }
> 
>                 } else if (strcmp(@encode(CGRect), type)==0) {
> 
>                     DLog(@"strcmp(@encode(CGRect): %s", @encode(CGRect));
> 
>                     CGRect v = [val CGRectValue];
> 
>                     if (sel == 0) {
> 
>                         CGRect *ptr = (CGRect*)((char *)self + offset);
> 
>                         *ptr = v;
> 
>                     } else {
> 
>                         void  (*imp)(id, SEL, CGRect) =
> 
>                         (void (*)(id, SEL, CGRect))[self methodForSelector: 
> sel];
> 
>                         (*imp)(self, sel, v);
> 
>                     }
> 
>                 } else if (GSSelectorTypesMatch(@encode(NSPoint), type))
> 
> 
>                 {
> 
> ...
> 
> }
> 
> 
> 
> 2. In NSValue.m file:
> 
> 
> 
> + (Class) valueClassWithObjCType: (const char *)type
> 
> {
> 
>     Class     theClass = concreteClass;
> 
>     
> 
>     /* Let someone else deal with this error */
> 
>     if (!type)
> 
>         return theClass;
> 
>     
> 
>     /* Try for an exact type match.
> 
>      */
> 
>     if (strcmp(@encode(id), type) == 0)
> 
>         theClass = nonretainedObjectValueClass;
> 
>     else if (strcmp(@encode(NSPoint), type) == 0)
> 
>         theClass = pointValueClass;
> 
>     else if (strcmp(@encode(void *), type) == 0)
> 
>         theClass = pointerValueClass;
> 
>     else if (strcmp(@encode(NSRange), type) == 0)
> 
>         theClass = rangeValueClass;
> 
>     else if (strcmp(@encode(NSRect), type) == 0)
> 
>         theClass = rectValueClass;
> 
>     else if (strcmp(@encode(NSSize), type) == 0)
> 
>         theClass = sizeValueClass;
> 
>     
> 
>     /* Try for equivalent types match.
> 
>      */
> 
>     /*else if (GSSelectorTypesMatch(@encode(id), type))
> 
>         theClass = nonretainedObjectValueClass;
> 
>     else if (GSSelectorTypesMatch(@encode(NSPoint), type))
> 
>         theClass = pointValueClass;
> 
>     else if (GSSelectorTypesMatch(@encode(void *), type))
> 
>         theClass = pointerValueClass;
> 
>     else if (GSSelectorTypesMatch(@encode(NSRange), type))
> 
>         theClass = rangeValueClass;
> 
>     else if (GSSelectorTypesMatch(@encode(NSRect), type))
> 
>         theClass = rectValueClass;
> 
>     else if (GSSelectorTypesMatch(@encode(NSSize), type))
> 
>         theClass = sizeValueClass;*/
> 
>     DLog(@"theClass: %@", theClass);
> 
>     return theClass;
> 
> 
> }
> 
> 
> 
> Check full files here:
> 
> https://github.com/amraboelela/myos.frameworks/blob/master/Foundation/GSObjCRuntime-myos.m
> 
> https://github.com/amraboelela/myos.frameworks/blob/master/Foundation/NSValue-myos.m
> 
> 
> 
> _______________________________________________
> Discuss-gnustep mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/discuss-gnustep
_______________________________________________
Discuss-gnustep mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnustep

Reply via email to