discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CGPoint support in NSValue


From: Ivan Vučica
Subject: Re: CGPoint support in NSValue
Date: Wed, 11 Mar 2015 20:47:29 +0000

Looks like this should give similar results to Mac then:

typedef struct _CGPoint                                                         
{                                                                               
  float x, y;                                                                   
} CGPoint;                                                                      
typedef CGPoint NSPoint;                                                        
                                                                                
int main()                                                                      
{                                                                               
  printf("%s\n", @encode(NSPoint));                                             
  printf("%s\n", @encode(CGPoint));                                             
}                                                                               

$ ./a.out 
{_CGPoint=ff}
{_CGPoint=ff}



On Wed, Mar 11, 2015 at 8:44 PM, Fred Kiefer <fredkiefer@gmx.de> wrote:
I just run the line 

NSLog(@"CGPoint %s NSPoint %s", @encode(CGPoint),  @encode(NSPoint));

On my Mac and this gives me the same output, {CGPoint=dd}. The same may not be true on GNUstep, but this could just mean we need to corrcet this?

Fred

On the road

Am 11.03.2015 um 19:14 schrieb Amr Aboelela <amraboelela@gmail.com>:

They hold the same data yes, but in CoreGraphics, UIKit, and CoreAnimation, it is called CGPoint and CGRect :)
If we don't do that, then the KVC will not work right in the CoreAnimation for the CALayer

On Wed, Mar 11, 2015 at 1:39 AM, Fred Kiefer <fredkiefer@gmx.de> wrote:
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 <amraboelela@gmail.com>:

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
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep



--
Info about Islam: http://wikiz.info/islam


_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep



reply via email to

[Prev in Thread] Current Thread [Next in Thread]