Created
March 6, 2013 11:21
-
-
Save beccadax/5098673 to your computer and use it in GitHub Desktop.
Stupid Macro Tricks™
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TsImageSizeConstraintType is an enum with these four values: | |
#define MAP \ | |
ENTRY(TsEditionImageSizeConstraintNone) \ | |
ENTRY(TsEditionImageSizeConstraintDimensions) \ | |
ENTRY(TsEditionImageSizeConstraintPixelCount) \ | |
ENTRY(TsEditionImageSizeConstraintByteCount) | |
NSString * TsStringForImageSizeConstraintType(TsImageSizeConstraintType type) { | |
switch(type) { | |
#define ENTRY(TYPE) case TYPE: return @#TYPE; | |
MAP | |
#undef ENTRY | |
} | |
} | |
TsImageSizeConstraintType TsImageSizeConstraintTypeFromString(NSString * string) { | |
static NSDictionary * table; | |
static dispatch_once_t once; | |
dispatch_once(&once, ^{ | |
#define ENTRY(TYPE) @#TYPE : @(TYPE), | |
table = @{ MAP }; | |
#undef ENTRY | |
}); | |
return [table[string] integerValue]; | |
} | |
#undef MAP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment