]> err.no Git - sope/blobdiff - sope-core/NGExtensions/NGHashMap.m
fixed resource/module lookup on 64bit systems
[sope] / sope-core / NGExtensions / NGHashMap.m
index c6394a28e7eea8d4da43b875c665be87c9932051..18a02b27f91e6e74b3cca410ed67a0af50f6e776 100644 (file)
@@ -1,32 +1,27 @@
 /*
-  Copyright (C) 2000-2004 SKYRIX Software AG
+  Copyright (C) 2000-2005 SKYRIX Software AG
 
-  This file is part of OpenGroupware.org.
+  This file is part of SOPE.
 
-  OGo is free software; you can redistribute it and/or modify it under
+  SOPE is free software; you can redistribute it and/or modify it under
   the terms of the GNU Lesser General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.
 
-  OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+  SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
   License for more details.
 
   You should have received a copy of the GNU Lesser General Public
-  License along with OGo; see the file COPYING.  If not, write to the
+  License along with SOPE; see the file COPYING.  If not, write to the
   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
   02111-1307, USA.
 */
-// $Id$
 
 #include "NGHashMap.h"
 #include "common.h"
 
-#if LIB_FOUNDATION_LIBRARY
-#  import <extensions/exceptions/GeneralExceptions.h>
-#endif
-
 #if !LIB_FOUNDATION_LIBRARY
 @interface NSException(SetUI) /* allowed on Jaguar ? */
 - (void)setUserInfo:(NSDictionary *)_ui;
@@ -54,32 +49,33 @@ static inline void checkForAddErrorMessage(id _self, id _object, id _key) {
   NSString     *r;
   
   if (_key == nil) {
-    r = [NSString stringWithFormat:@"nil key to be added in HashMap with object %@",
-           _object ? _object : @"<nil>"];
-    ui = [NSDictionary dictionaryWithObjectsAndKeys:
-                                     _self, @"map",
-                                     _key ? _key : @"<nil>",
-                                     @"key",
-                                     _object ? _object : @"<nil>",
-                                     @"object",
-                                     nil];
+    r = [[NSString alloc] initWithFormat:
+                           @"nil key to be added in HashMap with object %@",
+                           (_object != nil ? _object : (id)@"<nil>")];
+    ui = [[NSDictionary alloc] initWithObjectsAndKeys:
+                                _self,                            @"map",
+                                _key ? _key : (id)@"<nil>",       @"key",
+                                _object ? _object : (id)@"<nil>", @"object",
+                              nil];
     exc = [NSException exceptionWithName:NSInvalidArgumentException
                        reason:r userInfo:ui];
+    [r  release]; r  = nil;
+    [ui release]; ui = nil;
     [exc raise];
   }
   if (_object == nil) {
-    r = [NSString stringWithFormat:
-                   @"nil object to be added in HashMap for key %@",
-                   _key ? _key : @"<nil>"];
-    ui = [NSDictionary dictionaryWithObjectsAndKeys:
-                                     _self, @"map",
-                                     _key ? _key : @"<nil>",
-                                     @"key",
-                                     _object ? _object : @"<nil>",
-                                     @"object",
-                                     nil];
+    r = [[NSString alloc] initWithFormat:
+                           @"nil object to be added in HashMap for key %@",
+                           _key ? _key : (id)@"<nil>"];
+    ui = [[NSDictionary alloc] initWithObjectsAndKeys:
+                                _self,                            @"map",
+                                _key ? _key : (id)@"<nil>",       @"key",
+                                _object ? _object : (id)@"<nil>", @"object",
+                              nil];
     exc = [NSException exceptionWithName:NSInvalidArgumentException
                        reason:r userInfo:ui];
+    [r  release]; r  = nil;
+    [ui release]; ui = nil;
     [exc raise];
   }
 }
@@ -92,18 +88,18 @@ static inline void checkForRemoveErrorMessage(id _self, id _object, id _key) {
   if (_object != nil && _key != nil)
     return;
   
-  r = [NSString stringWithFormat:
-                 @"nil object to be removed in HashMap for key %@",
-                 _key ? _key : @"<nil>"];
-  ui = [NSDictionary dictionaryWithObjectsAndKeys:
-                                     _self, @"map",
-                                     _key ? _key : @"<nil>",
-                                     @"key",
-                                     _object ? _object : @"<nil>",
-                                     @"object",
-                                     nil];
+  r = [[NSString alloc] initWithFormat:
+                         @"nil object to be removed in HashMap for key %@",
+                         _key ? _key : (id)@"<nil>"];
+  ui = [[NSDictionary alloc] initWithObjectsAndKeys:
+                              _self,                            @"map",
+                              _key ? _key : (id)@"<nil>",       @"key",
+                              _object ? _object : (id)@"<nil>", @"object",
+                            nil];
   exc = [NSException exceptionWithName:NSInvalidArgumentException
                      reason:r userInfo:ui];
+  [ui release]; ui = nil;
+  [r  release]; r  = nil;
   [exc raise];
 }
 
@@ -411,17 +407,10 @@ static inline unsigned __countObjectsForKey(NGHashMap *self, id _key) {
     return nil;
   
   if ((_index < list->count) == 0) {
-#if LIB_FOUNDATION_LIBRARY
-    NSException *exc = [[IndexOutOfRangeException alloc]
-      initForSize:list->count index:_index];
-    [exc setUserInfo:
-          [NSDictionary dictionaryWithObject:self forKey:@"object"]];
-    [exc raise];
-#else
     [NSException raise:NSRangeException
                  format:@"index %d out of range for key %@ of length %d",
                    _index, _key, list->count];
-#endif
+    return nil;
   }
 
   while (_index--)
@@ -731,16 +720,10 @@ static inline unsigned __countObjectsForKey(NGHashMap *self, id _key) {
   checkForAddErrorMessage(self, _objects[0],_key);
   if ((root = [self __structForKey:_key]) == NULL) {
     if (_index > 0) {
-#if LIB_FOUNDATION_LIBRARY
-      NSException *exc = [[IndexOutOfRangeException alloc]
-        initForSize:0 index:_index];
-      [exc setUserInfo:[NSDictionary dictionaryWithObject:self forKey:@"map"]];
-      [exc raise];
-#else
       [NSException raise:NSRangeException
-                   format:@"index %d out of range in map 0x%08X", 
+                   format:@"index %d out of range in map 0x%p", 
                     _index, self];
-#endif
+      return;
     }
 
     root        = initLListElement(_objects[0], NULL);
@@ -749,16 +732,10 @@ static inline unsigned __countObjectsForKey(NGHashMap *self, id _key) {
   }
   else {
     if (!(_index < root->count)) {
-#if LIB_FOUNDATION_LIBRARY
-      NSException *exc = [[IndexOutOfRangeException alloc]
-        initForSize:root->count index:_index];
-      [exc setUserInfo:[NSDictionary dictionaryWithObject:self forKey:@"map"]];
-      [exc raise];
-#else
       [NSException raise:NSRangeException
-                   format:@"index %d out of range in map 0x%08X length %d", 
+                   format:@"index %d out of range in map 0x%p length %d", 
                     _index, self, root->count];
-#endif
+      return;
     }
     
     root->count += _count;