-2

I like to see framework sourcecode. when I see this framework , I cann't get it . please help me .

I don't konw every step at this macro. What does this marco do ?

define metamacro_concat_(A, B) A ## B

I feel this macro is not objective-c syntax.

thx

//
//  Macro.h
//  Macro
//
//  Created by JerryBob on 14-12-11.
//
//

#import <Foundation/Foundation.h>
@class RACSignal;




/**
 * Returns the number of arguments (up to twenty) provided to the macro. At
 * least one argument must be provided.
 *
 * Inspired by P99: http://p99.gforge.inria.fr
 */
#define metamacro_argcount(...) \
metamacro_at(20, __VA_ARGS__, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)

/**
 * Returns the Nth variadic argument (starting from zero). At least
 * N + 1 variadic arguments must be given. N must be between zero and twenty,
 * inclusive.
 */
#define metamacro_at(N, ...) \
metamacro_concat(metamacro_at, N)(__VA_ARGS__)

/**
 * Returns A and B concatenated after full macro expansion.
 */
#define metamacro_concat(A, B) \
metamacro_concat_(A, B)

#define metamacro_concat_(A, B) A ## B


/**************************************************************************/


/* @endcode
*
* This is primarily useful when dealing with indexes and counts in
* metaprogramming.
*/
#define metamacro_if_eq(A, B) \
metamacro_concat(metamacro_if_eq, A)(B)

/**
 * Returns A and B concatenated after full macro expansion.
 */
#define metamacro_concat(A, B) \
metamacro_concat_(A, B)

/********************************start from  here******************************************/
#define RAC(TARGET, ...) \
metamacro_if_eq(1, metamacro_argcount(__VA_ARGS__)) \
(RAC_(TARGET, __VA_ARGS__, nil)) \
(RAC_(TARGET, __VA_ARGS__))

/// Do not use this directly. Use the RAC macro above.
#define RAC_(TARGET, KEYPATH, NILVALUE) \
[[RACSubscriptingAssignmentTrampoline alloc] initWithTarget:(TARGET) nilValue:(NILVALUE)]      [@keypath(TARGET, KEYPATH)]`enter code here`


@interface RACSubscriptingAssignmentTrampoline : NSObject

- (id)initWithTarget:(id)target nilValue:(id)nilValue;
- (void)setObject:(RACSignal *)signal forKeyedSubscript:(NSString *)keyPath;

@end
1
  • and this /** * Returns the Nth variadic argument (starting from zero). At least * N + 1 variadic arguments must be given. N must be between zero and twenty, * inclusive. */ #define metamacro_at(N, ...) \ metamacro_concat(metamacro_at, N)(VA_ARGS)
    – jerry
    Dec 11, 2014 at 10:36

1 Answer 1

1

metamacro_concat takes the value of macro A and macro B and concatenates them

3
  • why it use "##" concatenates them ?
    – jerry
    Dec 11, 2014 at 9:48
  • Counts the number of arguments passed to the macro Dec 11, 2014 at 10:45
  • thx. metamacro_concat_(A, B) A ## B When I use this macro . metamacro_concat_(1,2) why it return 12. When I use this ( int i = 1 ## 2) compile error.
    – jerry
    Dec 13, 2014 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.