Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 108 lines (95 sloc) 4.053 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
39 #if DEBUG
40 #define UKLog(args...) NSLog( @"%s: %@", __PRETTY_FUNCTION__, [NSString stringWithFormat: args])
41 #else
42 #define UKLog(args...) // stubbed out
43 #endif
44
45
4b07924 @uliwitness Added UKInvalidPointer constant that fills a pointer with 0x55... lik…
authored
46 #if __LP64__
47 #define UKInvalidPointer ((id)0x5555555555555555)
48 #else
49 #define UKInvalidPointer ((id)0x55555555)
50 #endif
51
52
dc5be1c Initial check-in.
uli authored
53 // The following use the same syntax as the ones in GNUstep. Just cuz that's
54 // the closest we have to a standard for stuff like this.
55 //
56 // Create a pool around some code by doing:
57 // CREATE_AUTORELEASE_POOL(myPool);
58 // // Use the pool.
59 // DESTROY(myPool);
60 //
61 // ASSIGN() is a neat macro to use inside mutators, DESTROY() is a shorthand
62 // that lets you release an object and clear its variable in one go.
63 //
64 // The do/while(0) stuff is just there so the macro behaves just like any other
65 // function call, as far as if/else etc. are concerned.
66
67 #define CREATE_AUTORELEASE_POOL(pool) NSAutoreleasePool* (pool) = [[NSAutoreleasePool alloc] init]
68
69 #define ASSIGN(targ,newval) do {\
f8692e7 Added PROPERTY(), fixed DESTROY() to clear first, to avoid accidental…
uli authored
70 NSObject* __UKHELPERMACRO_OLDTARG = (NSObject*)(targ);\
dc5be1c Initial check-in.
uli authored
71 (targ) = [(newval) retain];\
72 [__UKHELPERMACRO_OLDTARG release];\
73 } while(0)
a1d334c @uliwitness Added ASSIGNMUTABLECOPY() to UKHelperMacros.
authored
74 #define ASSIGNMUTABLECOPY(targ,newval) do {\
75 NSObject* __UKHELPERMACRO_OLDTARG = (NSObject*)(targ);\
76 (targ) = [(newval) mutableCopy];\
77 [__UKHELPERMACRO_OLDTARG release];\
78 } while(0)
31ccfaf @uliwitness Added ASSIGNCOPY and ASSIGNMUTABLECOPY.
authored
79
4b07924 @uliwitness Added UKInvalidPointer constant that fills a pointer with 0x55... lik…
authored
80 #define DESTROY(targ) do {\
31ccfaf @uliwitness Added ASSIGNCOPY and ASSIGNMUTABLECOPY.
authored
81 NSObject* __UKHELPERMACRO_OLDTARG = (NSObject*)(targ);\
4b07924 @uliwitness Added UKInvalidPointer constant that fills a pointer with 0x55... lik…
authored
82 (targ) = nil;\
31ccfaf @uliwitness Added ASSIGNCOPY and ASSIGNMUTABLECOPY.
authored
83 [__UKHELPERMACRO_OLDTARG release];\
84 } while(0)
4b07924 @uliwitness Added UKInvalidPointer constant that fills a pointer with 0x55... lik…
authored
85 #define DESTROY_DEALLOC(targ) do {\
f8692e7 Added PROPERTY(), fixed DESTROY() to clear first, to avoid accidental…
uli authored
86 NSObject* __UKHELPERMACRO_OLDTARG = (NSObject*)(targ);\
4b07924 @uliwitness Added UKInvalidPointer constant that fills a pointer with 0x55... lik…
authored
87 (targ) = UKInvalidPointer;\
f8692e7 Added PROPERTY(), fixed DESTROY() to clear first, to avoid accidental…
uli authored
88 [__UKHELPERMACRO_OLDTARG release];\
dc5be1c Initial check-in.
uli authored
89 } while(0)
f8692e7 Added PROPERTY(), fixed DESTROY() to clear first, to avoid accidental…
uli authored
90
91 // The following macro is for specifying property (ivar) names to KVC or KVO methods.
92 // These methods generally take strings, but strings don't get checked for typos
93 // by the compiler. If you write PROPERTY(fremen) instead of PROPERTY(frame),
94 // the compiler will immediately complain that it doesn't know the selector
95 // 'fremen', and thus point out the typo. For this to work, you need to make
96 // sure the warning -Wunknown-selector is on.
97 //
98 // The code that checks here is (theoretically) slower than just using a string
99 // literal, so what we do is we only do the checking in debug builds. In
100 // release builds, we use the identifier-stringification-operator "#" to turn
101 // the given property name into an ObjC string literal.
102
103 #if DEBUG
104 #define PROPERTY(propName) NSStringFromSelector(@selector(propName))
105 #else
106 #define PROPERTY(propName) @#propName
107 #endif
Something went wrong with that request. Please try again.