Last active
August 29, 2015 14:19
-
-
Save adamnemecek/160a3d56c4e663eaa961 to your computer and use it in GitHub Desktop.
cocoa.snippets.mm
This file contains 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
#import <Foundation/Foundation.h> | |
void loadFScript() { | |
[[[NSBundle bundleWithPath:@"/Library/Frameworks/FScript.framework"] classNamed:@"FScriptMenuItem"] performSelector:@selector(insertInMainMenu)]; | |
} | |
template<typename T> | |
inline | |
NSValue* NSValueFromStruct(T *object) | |
{ | |
return [NSValue value:object withObjCType:@encode(T)]; | |
} | |
template<typename T> | |
inline | |
T NSValueToStruct(NSValue *value) | |
{ | |
T s = {}; | |
[value getValue:&s]; | |
return s; | |
} | |
void f() | |
{ | |
NSRect r = {}; | |
NSMutableArray *a = [[NSMutableArray alloc] init]; | |
[a addObject:NSValueFromStruct<NSRect>(&r)]; | |
NSLog(@"%@", NSStringFromRect(r)); | |
NSLog(@"%@", a); | |
NSLog(@"%@", NSStringFromRect(NSValueToStruct<NSRect>([a objectAtIndex:0]))); | |
} | |
// | |
template<typename T> | |
T WXMin(T a, T b); | |
template<typename T> | |
T WXMax(T a, T b); | |
template<> | |
float WXMin(float a, float b) { | |
return fminf(a, b); | |
} | |
template<> | |
float WXMax(float a, float b) { | |
return fmaxf(a, b); | |
} | |
template<typename T> | |
class WXMinMax { | |
public: | |
WXMinMax(T _a, T _b): a(_a), b(_b) {}; | |
inline T min() { return WXMin(a, b); } | |
inline T max() { return WXMax(a, b); } | |
inline T diff() { return max() - min(); } | |
private: | |
T a; | |
T b; | |
}; | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
f(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment