]> err.no Git - sope/blob - sope-appserver/WEExtensions/WEResourceKey.m
added strict OSX bundle dependencies
[sope] / sope-appserver / WEExtensions / WEResourceKey.m
1 /*
2   Copyright (C) 2004-2005 Helge Hess
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 #include "WEResourceKey.h"
23 #include "common.h"
24
25 @implementation WEResourceKey
26
27 - (id)initCachedKey {
28   if ((self = [self init])) {
29     self->flags.retainsValues = 0;
30   }
31   return self;
32 }
33
34 - (void)dealloc {
35   if (self->flags.retainsValues) {
36     [self->frameworkName release];
37     [self->name          release];
38     [self->language      release];
39   }
40   [super dealloc];
41 }
42
43 /* NSCopying */
44
45 - (id)duplicate {
46   /* returns a retained object */
47   WEResourceKey *newKey;
48   
49   newKey = [[[self class] alloc] init];
50   newKey->flags.retainsValues = 1;
51   newKey->hashValue     = self->hashValue;
52   newKey->frameworkName = [self->frameworkName copy];
53   newKey->name          = [self->name          copy];
54   newKey->language      = [self->language      copy];
55   return newKey;
56 }
57
58 - (id)copyWithZone:(NSZone *)_zone {
59   if (!self->flags.retainsValues)
60     return [self duplicate];
61   
62   /* we are immutable */
63   return [self retain];
64 }
65
66 /* equality */
67
68 - (unsigned)hash {
69   if (self->hashValue == 0) {
70     /* don't know whether this is smart, Nat! needs to comment ;-) */
71     self->hashValue = [self->name hash];
72     if (self->language != nil)
73       self->hashValue += [self->language characterAtIndex:0];
74   }
75   return self->hashValue;
76 }
77
78 - (BOOL)isEqual:(id)_other {
79   /* this method isn't very tolerant, but fast ;-) */
80   WEResourceKey *okey;
81   
82   if (_other == nil)  return NO;
83   if (_other == self) return YES;
84   if (*(Class*)_other != *(Class *)self) return NO;
85   okey = _other;
86   
87   if (self->name != okey->name) {
88     if (![self->name isEqualToString:okey->name])
89       return NO;
90   }
91   if (self->language != okey->language) {
92     if (![self->language isEqualToString:okey->language])
93       return NO;
94   }
95   if (self->frameworkName != okey->frameworkName) {
96     if (![self->frameworkName isEqualToString:okey->frameworkName])
97       return NO;
98   }
99   return YES;
100 }
101
102 /* description */
103
104 - (NSString *)description {
105   NSMutableString *ms;
106
107   ms = [NSMutableString stringWithCapacity:128];
108   [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
109   if (self->name)          [ms appendFormat:@" name=%@", self->name];
110   if (self->frameworkName) [ms appendFormat:@" fw=%@",   self->frameworkName];
111   if (self->language)      [ms appendFormat:@" lang=%@", self->language];
112   [ms appendString:@">"];
113   return ms;
114 }
115
116 @end /* WEResourceKey */