// // NGAUtilities.h // P4ObjectLayer // // Created by Michael Bishop on 10/4/10. // Copyright 2010 Numerical Garden, LLC. All rights reserved. // #define CLEAN_CFRELEASE(x) \ do { \ if (x) \ { \ CFRelease(x); \ x = NULL; \ } \ } while (0) #ifdef __OBJC__ #import <Cocoa/Cocoa.h> #import "NGAAdditions.h" #import "NGAAutoObserver.h" #if __has_feature(objc_arc) #define RETAIN(...) __VA_ARGS__ #else #define RETAIN(...) [__VA_ARGS__ retain] #endif #if __has_feature(objc_arc) #define DEALLOC(...) -(void)dealloc {__VA_ARGS__ ;} #else #define DEALLOC(...) -(void)dealloc {__VA_ARGS__ [super dealloc];} #endif #if __has_feature(objc_arc) #define RELEASE(var) var = nil #else #define RELEASE(var) \ do { \ NSObject * __tempVar__ = (NSObject*)var; \ var = nil; \ [__tempVar__ release]; \ } while (0) #endif #if __has_feature(objc_arc) #define AUTORELEASE(x) (x) #else #define AUTORELEASE(x) [x autorelease] #endif // Singleton implementation right from the "Cocoa Fundamentals Guide: Creating a Singleton Instance" #define PRIV_SINGLETON_ACCESSOR_IMPLEMENTATION(RETURNTYPE, ALLOCATINGCLASS, SHAREDACCESSOR) \ + (RETURNTYPE*)SHAREDACCESSOR \ { \ static dispatch_once_t pred; \ static RETURNTYPE *sharedInstance = nil; \ \ dispatch_once(&pred, ^{ \ sharedInstance = [[ALLOCATINGCLASS allocWithZone:NULL] init]; \ }); \ return sharedInstance; \ } #define SINGLETON_ACCESSOR_IMPLEMENTATION(RETURNTYPE, SHAREDACCESSOR) PRIV_SINGLETON_ACCESSOR_IMPLEMENTATION(RETURNTYPE, RETURNTYPE, SHAREDACCESSOR) #if __has_feature(objc_arc) #define SINGLETON_IMPLEMENTATION(RETURNTYPE, SHAREDACCESSOR) PRIV_SINGLETON_ACCESSOR_IMPLEMENTATION(RETURNTYPE, super, SHAREDACCESSOR) #else #define SINGLETON_IMPLEMENTATION(RETURNTYPE, SHAREDACCESSOR) PRIV_SINGLETON_ACCESSOR_IMPLEMENTATION(RETURNTYPE, super, SHAREDACCESSOR) \ \ + (id)allocWithZone:(NSZone *)zone \ { \ return [[self SHAREDACCESSOR] retain]; \ } \ \ - (id)copyWithZone:(NSZone *)zone \ { \ return self; \ } \ \ - (id)retain \ { \ return self; \ } \ \ - (NSUInteger)retainCount \ { \ return NSUIntegerMax; \ } \ \ - (oneway void)release \ { \ } \ \ - (id)autorelease \ { \ return self; \ } #endif /// Use this before declaring a block so you can have a reference to self inside the block. /// Using this macro will prevent the block from retaining "self" which is likely to happen /// if you use any of self's methods or instance variables in your block. #define DECLARE_UNRETAINED_SELF(TYPE) __block TYPE unretainedSelf = self /// Use this when you are comparing two NSString pointers and it's possible that the left side /// of the comparison is nil. This works even in that case (and considers comparing two nils /// as equal) #define NSSTRING_ISEQUALTOSTRING(x, y) \ (((x) == (y)) || ((x) != nil && [(x) isEqualToString:(y)])) #define NSOBJECT_ISEQUAL(x, y) \ (((x) == (y)) || ((x) != nil && [(x) isEqual:(y)])) #define NEW_VALUE(x) ( [[NSNull null] isEqual:[(x) objectForKey:NSKeyValueChangeNewKey]] ? nil : [(x) objectForKey:NSKeyValueChangeNewKey]) #define OLD_VALUE(x) ( [[NSNull null] isEqual:[(x) objectForKey:NSKeyValueChangeOldKey]] ? nil : [(x) objectForKey:NSKeyValueChangeOldKey]) #define IF_NO_CHANGE_THEN_RETURN(x) \ do { \ if ( NSOBJECT_ISEQUAL(OLD_VALUE(x), NEW_VALUE(x) ) ) return; \ } while (0) #define NSARRAY(...) [NSArray arrayWithObjects:__VA_ARGS__, nil] #define NSSET(...) [NSSet setWithObjects:__VA_ARGS__, nil] #define KEYPATH(...) [NSARRAY(__VA_ARGS__) componentsJoinedByString:@"."] // Use this to declare a C-function that acts as an accessor to a constant set at runtime. // For instance, if you have a static string that you want to create, but it is a composition // of two static strings eg. @"home".@"name", you cannot make that a static // NSString variable, but you CAN make a C-function that acts like it and // just loads a value at runtime. // // TYPE - The type of constant // NAME - the name of the C-function to be generated // INITIALIZATION_STATEMENT - a single statement that is assigned to the constant. You MUST // enclose your statment in parenthesis. // eg. "([[NSString stringWithFormat:@"%@.%@", kName, kTypeName] retain]) #define RUNTIME_CONSTANT_FUNCTION(TYPE, NAME, ...) \ static TYPE NAME() \ { \ static TYPE k##NAME; \ static dispatch_once_t onceToken; \ dispatch_once(&onceToken, ^{ \ k##NAME = __VA_ARGS__; \ }); \ return k##NAME; \ } #endif // __OBJC__
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 20722 | jdputsch | initial branch, prep for -Zapp= support | ||
//guest/michael_bishop/MacMenu/src/NGAUtilities/Source/NGAUtilities.h | |||||
#1 | 8331 | Matt Attaway |
Adding initial version of MacMenu for Perforce MacMenu is a helpful Perforce client that sits in your toolbar. It allows you to run standard Perforce operations on the document that is open the currently active editor/viewer. |