Skip to content
Newer
Older
100644 112 lines (99 sloc) 4.07 KB
dc5be1c Initial check-in.
uli authored
1 //
2 // UKHelperMacros.h
3 //
4 // Created by Uli Kusterer on 09.08.07.
720b0e7 @uliwitness Added licensing information to the source files.
authored
5 // Copyright 2007 Uli Kusterer.
6 //
7 // This software is provided 'as-is', without any express or implied
8 // warranty. In no event will the authors be held liable for any damages
9 // arising from the use of this software.
10 //
11 // Permission is granted to anyone to use this software for any purpose,
12 // including commercial applications, and to alter it and redistribute it
13 // freely, subject to the following restrictions:
14 //
15 // 1. The origin of this software must not be misrepresented; you must not
16 // claim that you wrote the original software. If you use this software
17 // in a product, an acknowledgment in the product documentation would be
18 // appreciated but is not required.
19 //
20 // 2. Altered source versions must be plainly marked as such, and must not be
21 // misrepresented as being the original software.
22 //
23 // 3. This notice may not be removed or altered from any source
24 // distribution.
25 //
dc5be1c Initial check-in.
uli authored
26
720b0e7 @uliwitness Added licensing information to the source files.
authored
27 /*
28 You'd generally #import this file in your project's prefix header.
29 */
dc5be1c Initial check-in.
uli authored
30
31 //
32 // Use UKLog() instead of NSLog() to output debug-only messages that you don't
33 // want in release builds. You'll have to add DEBUG=1 to the preprocessor macros
34 // in your target's compiler settings for the Development build configuration.
35 //
36 // This prefixes the method or function name to the message.
37 //
38
5afa0d7 @uliwitness Merge a few compatibility ifdefs in for people who redefine their log…
authored
39 #ifndef UKLog
dc5be1c Initial check-in.
uli authored
40 #if DEBUG
41 #define UKLog(args...) NSLog( @"%s: %@", __PRETTY_FUNCTION__, [NSString stringWithFormat: args])
42 #else
5afa0d7 @uliwitness Merge a few compatibility ifdefs in for people who redefine their log…
authored
43 #define UKLog(args...) while(0) // stubbed out
dc5be1c Initial check-in.
uli authored
44 #endif
5afa0d7 @uliwitness Merge a few compatibility ifdefs in for people who redefine their log…
authored
45 #endif // UKLog
dc5be1c Initial check-in.
uli authored
46
47
4b07924 @uliwitness Added UKInvalidPointer constant that fills a pointer with 0x55... lik…
authored
48 #if __LP64__
49 #define UKInvalidPointer ((id)0x5555555555555555)
50 #else
51 #define UKInvalidPointer ((id)0x55555555)
52 #endif
53
54
dc5be1c Initial check-in.
uli authored
55 // The following use the same syntax as the ones in GNUstep. Just cuz that's
56 // the closest we have to a standard for stuff like this.
57 //
58 // Create a pool around some code by doing:
59 // CREATE_AUTORELEASE_POOL(myPool);
60 // // Use the pool.
61 // DESTROY(myPool);
62 //
63 // ASSIGN() is a neat macro to use inside mutators, DESTROY() is a shorthand
64 // that lets you release an object and clear its variable in one go.
65 //
66 // The do/while(0) stuff is just there so the macro behaves just like any other
67 // function call, as far as if/else etc. are concerned.
68
69 #define CREATE_AUTORELEASE_POOL(pool) NSAutoreleasePool* (pool) = [[NSAutoreleasePool alloc] init]
70
5afa0d7 @uliwitness Merge a few compatibility ifdefs in for people who redefine their log…
authored
71 #ifndef ASSIGN // SenTest declares its own macro
dc5be1c Initial check-in.
uli authored
72 #define ASSIGN(targ,newval) do {\
f8692e7 Added PROPERTY(), fixed DESTROY() to clear first, to avoid accidental…
uli authored
73 NSObject* __UKHELPERMACRO_OLDTARG = (NSObject*)(targ);\
dc5be1c Initial check-in.
uli authored
74 (targ) = [(newval) retain];\
75 [__UKHELPERMACRO_OLDTARG release];\
76 } while(0)
5afa0d7 @uliwitness Merge a few compatibility ifdefs in for people who redefine their log…
authored
77 #endif // !defined(ASSIGN)
a1d334c @uliwitness Added ASSIGNMUTABLECOPY() to UKHelperMacros.
authored
78 #define ASSIGNMUTABLECOPY(targ,newval) do {\
79 NSObject* __UKHELPERMACRO_OLDTARG = (NSObject*)(targ);\
80 (targ) = [(newval) mutableCopy];\
81 [__UKHELPERMACRO_OLDTARG release];\
82 } while(0)
31ccfaf @uliwitness Added ASSIGNCOPY and ASSIGNMUTABLECOPY.
authored
83
4b07924 @uliwitness Added UKInvalidPointer constant that fills a pointer with 0x55... lik…
authored
84 #define DESTROY(targ) do {\
31ccfaf @uliwitness Added ASSIGNCOPY and ASSIGNMUTABLECOPY.
authored
85 NSObject* __UKHELPERMACRO_OLDTARG = (NSObject*)(targ);\
4b07924 @uliwitness Added UKInvalidPointer constant that fills a pointer with 0x55... lik…
authored
86 (targ) = nil;\
31ccfaf @uliwitness Added ASSIGNCOPY and ASSIGNMUTABLECOPY.
authored
87 [__UKHELPERMACRO_OLDTARG release];\
88 } while(0)
4b07924 @uliwitness Added UKInvalidPointer constant that fills a pointer with 0x55... lik…
authored
89 #define DESTROY_DEALLOC(targ) do {\
f8692e7 Added PROPERTY(), fixed DESTROY() to clear first, to avoid accidental…
uli authored
90 NSObject* __UKHELPERMACRO_OLDTARG = (NSObject*)(targ);\
4b07924 @uliwitness Added UKInvalidPointer constant that fills a pointer with 0x55... lik…
authored
91 (targ) = UKInvalidPointer;\
f8692e7 Added PROPERTY(), fixed DESTROY() to clear first, to avoid accidental…
uli authored
92 [__UKHELPERMACRO_OLDTARG release];\
dc5be1c Initial check-in.
uli authored
93 } while(0)
f8692e7 Added PROPERTY(), fixed DESTROY() to clear first, to avoid accidental…
uli authored
94
95 // The following macro is for specifying property (ivar) names to KVC or KVO methods.
96 // These methods generally take strings, but strings don't get checked for typos
97 // by the compiler. If you write PROPERTY(fremen) instead of PROPERTY(frame),
98 // the compiler will immediately complain that it doesn't know the selector
99 // 'fremen', and thus point out the typo. For this to work, you need to make
100 // sure the warning -Wunknown-selector is on.
101 //
102 // The code that checks here is (theoretically) slower than just using a string
103 // literal, so what we do is we only do the checking in debug builds. In
104 // release builds, we use the identifier-stringification-operator "#" to turn
105 // the given property name into an ObjC string literal.
106
107 #if DEBUG
108 #define PROPERTY(propName) NSStringFromSelector(@selector(propName))
109 #else
110 #define PROPERTY(propName) @#propName
111 #endif
Something went wrong with that request. Please try again.