复杂写法的宏

来源:互联网 发布:晚会暖场小游戏知乎 编辑:程序博客网 时间:2024/05/16 05:18

// Some simple defines to make life easier on ourself

#if TARGET_OS_IPHONE
  #define MakeColor(r, g, b) [UIColor colorWithRed:(r/
255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:1.0f]
#else
  #define MakeColor(r, g, b) [NSColor colorWithCalibratedRed:(r/
255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:1.0f]
#endif

#if TARGET_OS_IPHONE
  #define OSColor UIColor
#else
  #define OSColor NSColor
#endif

// If running in a shell, not all RGB colors will be supported.
// In this case we automatically map to the closest available color.
// In order to provide this mapping, we have a hard-coded set of the standard RGB values available in the shell.
// However, not every shell is the same, and Apple likes to think different even when it comes to shell colors.
//





// 参考写法
#define LOG_LEVEL2

#define NSLogError(frmt, ...)    do{ if(LOG_LEVEL >=1) NSLog((frmt), ##__VA_ARGS__); } while(0)
#define NSLogWarn(frmt, ...)     do{ if(LOG_LEVEL >=
2) NSLog((frmt), ##__VA_ARGS__); } while(0)
#define NSLogInfo(frmt, ...)     do{ if(LOG_LEVEL >=
3) NSLog((frmt), ##__VA_ARGS__); } while(0)
#define NSLogVerbose(frmt, ...)  do{ if(LOG_LEVEL >=4) NSLog((frmt), ##__VA_ARGS__); } while(0)

#define LOG_MACRO(isAsynchronous, lvl, flg, ctx, atag, fnct, frmt, ...) \
  [DDLog log:isAsynchronous                                             \
       level:lvl                                                        \
        flag:flg                                                        \
     context:ctx                                                        \
        file:__FILE__                                                   \
    function:fnct                                                       \
        line:__LINE__                                                   \
         tag:atag                                                       \
      format:(frmt), ##__VA_ARGS__]



//判断区分的宏的写法
#if TARGET_IPHONE_SIMULATOR
  #define XATTR_ARCHIVED_NAME  @
"archived"
#else
  #define XATTR_ARCHIVED_NAME  @
"lumberjack.log.archived"
#endif

#ifndef NSXMLElementDeclarationKind
  #define NSXMLElementDeclarationKind DDXMLElementDeclarationKind
#endif
#ifndef NSXMLNotationDeclarationKind
  #define NSXMLNotationDeclarationKind DDXMLNotationDeclarationKind
#endif


// The debugging macro adds a significant amount of overhead, and should NOT be enabled on production builds.

#if DEBUG
  #define DDXML_DEBUG_MEMORY_ISSUES
0
#else
  #define DDXML_DEBUG_MEMORY_ISSUES
0 // Don't change me!
#endif




- (void)inDatabase:(void(^)(FMDatabase*db))block {
   
/* Get the currently executing queue (which should probably be nil, but in theory could be another DB queue
     * and then check it against self to make sure we're not about to deadlock. */

   
FMDatabaseQueue *currentSyncQueue = (__bridgeid)dispatch_get_specific(kDispatchQueueSpecificKey);
   
assert(currentSyncQueue !=self&& "inDatabase: was called reentrantly on the same queue, which would lead to a deadlock");
   
   
FMDBRetain(self);
   
   
dispatch_sync(_queue, ^() {
       
       
FMDatabase *db = [selfdatabase];
        block(db);
       
       
if ([dbhasOpenResultSets]) {
           
NSLog(@"Warning: there is at least one open result set around after performing [FMDatabaseQueue inDatabase:]");
           
#if defined(DEBUG) && DEBUG
           NSSet*openSetCopy =FMDBReturnAutoreleased([[db valueForKey:@"_openResultSets"] copy]);
           
for (NSValue*rsInWrappedInATastyValueMealin openSetCopy) {
               
FMResultSet *rs = (FMResultSet*)[rsInWrappedInATastyValueMealpointerValue];
               
NSLog(@"query: '%@'", [rsquery]);
            }
#endif
        }
    });
   
   
FMDBRelease(self);
}


//判断含警告
#if ! __has_feature(objc_arc)
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif
0 0