2 Copyright (C) 2004-2005 Helge Hess
4 This file is part of SOPE.
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
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.
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
22 #include "WEResourceKey.h"
25 @implementation WEResourceKey
28 if ((self = [self init])) {
29 self->flags.retainsValues = 0;
35 if (self->flags.retainsValues) {
36 [self->frameworkName release];
38 [self->language release];
46 /* returns a retained object */
47 WEResourceKey *newKey;
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];
58 - (id)copyWithZone:(NSZone *)_zone {
59 if (!self->flags.retainsValues)
60 return [self duplicate];
62 /* we are immutable */
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];
75 return self->hashValue;
78 - (BOOL)isEqual:(id)_other {
79 /* this method isn't very tolerant, but fast ;-) */
82 if (_other == nil) return NO;
83 if (_other == self) return YES;
84 if (*(Class*)_other != *(Class *)self) return NO;
87 if (self->name != okey->name) {
88 if (![self->name isEqualToString:okey->name])
91 if (self->language != okey->language) {
92 if (![self->language isEqualToString:okey->language])
95 if (self->frameworkName != okey->frameworkName) {
96 if (![self->frameworkName isEqualToString:okey->frameworkName])
104 - (NSString *)description {
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:@">"];
116 @end /* WEResourceKey */