2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "NSNull+misc.h"
26 #if LIB_FOUNDATION_LIBRARY || GNUSTEP_BASE_LIBRARY
27 # include <objc/objc-api.h>
28 # include <objc/objc.h>
29 # include <objc/encoding.h>
31 # import <extensions/objc-runtime.h>
34 # import <objc/objc-class.h>
37 @implementation NSNull(misc)
39 static int _doAbort = -1;
40 static inline BOOL doAbort(void) {
42 _doAbort = [[NSUserDefaults standardUserDefaults]
43 boolForKey:@"NSNullAbortOnMessage"] ? 1 : 0;
45 return _doAbort ? YES : NO;
53 NSLog(@"WARNING(%s): called deprecated -isNull on NSNull (use -isNotNull) !",
55 if (doAbort()) abort();
60 - (NSString *)stringValue {
62 NSLog(@"WARNING(%s): "
63 @"NSNull -stringValue returns empty string.",
65 if (doAbort()) abort();
69 - (double)doubleValue {
71 NSLog(@"WARNING(%s): "
72 @"NSNull -doubleValue returns 0.0.",
74 if (doAbort()) abort();
79 - (unsigned int)length {
81 NSLog(@"WARNING(%s): "
82 @"called NSNull -length (returns 0) !!!",
84 if (doAbort()) abort();
88 - (unsigned int)count {
90 NSLog(@"WARNING(%s): "
91 @"called NSNull -count (returns 0) !!!",
93 if (doAbort()) abort();
98 - (BOOL)isEqualToString:(NSString *)_s {
100 NSLog(@"WARNING(%s): "
101 @"called NSNull -isEqualToString:!!!",
102 __PRETTY_FUNCTION__);
103 if (doAbort()) abort();
105 return _s == (id)self || _s == nil ? YES : NO;
108 - (unichar)characterAtIndex:(unsigned int)_idx {
110 NSLog(@"WARNING(%s): "
111 @"called NSNull -characterAtIndex:%d - returning 0!",
112 __PRETTY_FUNCTION__, _idx);
113 if (doAbort()) abort();
118 /* key-value coding */
120 - (void)takeValue:(id)_value forKey:(NSString *)_key {
123 - (id)valueForKey:(NSString *)_key {
124 if ([_key isEqualToString:@"isNotNull"]) {
125 static NSNumber *noNum = nil;
128 noNum = [NSNumber numberWithBool:NO];
132 if ([_key isEqualToString:@"isNull"]) {
133 static NSNumber *yesNum = nil;
136 yesNum = [NSNumber numberWithBool:YES];
147 - (BOOL)respondsToSelector:(SEL)_sel {
148 /* fake that we have a selector */
152 - (NSString *)descriptionWithLocale:(id)_locale indent:(int)_indent {
155 - (NSString *)descriptionWithLocale:(id)_locale {
161 - (void)forwardInvocation:(NSInvocation *)_invocation {
162 NSMethodSignature *sig;
164 NSLog(@"ERROR(%s): called selector %@ on NSNull !",
166 NSStringFromSelector([_invocation selector]));
167 if (doAbort()) abort();
169 if ((sig = [_invocation methodSignature])) {
170 const unsigned char *ret;
172 if ((ret = [sig methodReturnType])) {
176 [_invocation setReturnValue:&v];
181 [_invocation setReturnValue:&v];
188 [_invocation setReturnValue:&v];
193 NSLog(@" didn't set return value for type '%s'", ret);
198 NSLog(@" no method return type in signature %@", sig);
201 NSLog(@" no method signature in invocation %@", _invocation);
204 @end /* NSNull(misc) */
206 @implementation NSObject(NSNullMisc)
214 NSLog(@"%s: WARNING, called -isNull on NSObject (use -isNotNull) !",
215 __PRETTY_FUNCTION__);
220 @end /* NSObject(NSNullMisc) */