Hi,

I found a couple of things I didn't know in the CPP manual... first, $
is considerred (for compatibility reasons with... VMS ;-)) a letter,
so you can use it as the first character of a macro. Second, you /can/
have optional parameters in macros, but only with variable arguments.

So armed with that, I redefined the macros for creating
dictionaries/numbers/arrays like that:

        #define $I(x) [NSNumber numberWithInt: x]
        #define $F(x) [NSNumber numberWithFloat: x]
        #define $D(args...) \
                [NSDictionary dictionaryWithObjectsAndKeys: args, nil]
        #define $A(args...) \
                [NSArray arrayWithObjects: args, nil]
        #define $MD(args...) \
                [NSMutableDictionary dictionaryWithObjectsAndKeys: args, nil]
        #define $MA(args...) \
                [NSMutableArray arrayWithObjects: args, nil]

So we can easily create a dictionary:

NSDictionary* dict = $D( $I(5), @"toto" );

I think it's a good idea to use $ as we can stick with very short
names yet be very easily spottable. Comments ?

Regarding the optional arguments, that let me define macros like
GETIMP/CALLIMP in a simpler way:

        #define GETIMP(object,sel) [object methodForSelector: @selector(sel)]
        #define CALLIMP(imp,object,sel, args...) (*imp)(object,
@selector(sel) , ##args)

...that you can use like that:

IMP imp1 = GETIMP(test, plop);
IMP imp2 = GETIMP(test, say:);

CALLIMP(imp1, test, plop);
CALLIMP(imp2, test, say:, @"hello");

--
Nicolas Roard
"La perfection, ce n'est pas quand il n'y a plus rien à ajouter, c'est
quand il n'y a plus rien à retrancher." -- Antoine de St-Exupéry

_______________________________________________
Etoile-dev mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-dev

Reply via email to