]> err.no Git - sope/blob - sope-core/NGExtensions/FdExt.subproj/NSDictionary+misc.m
fixed a gstep-base issue
[sope] / sope-core / NGExtensions / FdExt.subproj / NSDictionary+misc.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
6   SOPE 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
9   later version.
10
11   SOPE 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.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with SOPE; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #import "common.h"
23 #import "NSDictionary+misc.h"
24
25 @implementation NSDictionary(misc)
26
27 - (NSDictionary *)dictionaryByExchangingKeysAndValues {
28   NSDictionary *reverse;
29   NSArray  *oKeys;
30   unsigned i, len;
31   id *keys, *values;
32   
33   oKeys = [self allKeys];
34   if ((len = [oKeys count]) == 0)
35     return [[self copy] autorelease];
36   
37   keys   = calloc(len + 10, sizeof(id));
38   values = calloc(len + 10, sizeof(id));
39   for (i = 0; i < len; i++) {
40     values[i] = [oKeys objectAtIndex:i];
41     keys[i]   = [self objectForKey:values[i]];
42   }
43   
44   reverse =
45     [[NSDictionary alloc] initWithObjects:values forKeys:keys count:len];
46   free(keys);
47   free(values);
48   return [reverse autorelease];
49 }
50
51 @end /* NSDictionary(misc) */
52
53 @implementation NSMutableDictionary(misc)
54
55 - (void)removeObjectsForKeysV:(id)_firstKey, ... {
56   va_list ap;
57
58   va_start(ap, _firstKey);
59   while (_firstKey) {
60     [self removeObjectForKey:_firstKey];
61     _firstKey = va_arg(ap, id);
62   }
63   va_end(ap);
64 }
65
66 @end /* NSMutableDictionary(misc) */
67
68 void __link_NSDictionary_misc() {
69   __link_NSDictionary_misc();
70 }