discuss-gnustep
[Top][All Lists]
Advanced

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

CGPoint support in NSValue


From: Amr Aboelela
Subject: CGPoint support in NSValue
Date: Tue, 10 Mar 2015 20:31:07 -0700

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



reply via email to

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