2 Copyright (C) 2000-2006 SKYRIX Software AG
3 Copyright (C) 2006 Helge Hess
5 This file is part of SOPE.
7 SOPE is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with SOPE; see the file COPYING. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "EOKeyGlobalID.h"
26 @implementation EOKeyGlobalID
28 + (id)globalIDWithEntityName:(NSString *)_name
30 keyCount:(unsigned int)_count
36 @"missing key-values (count is 0, entity is %@", _name);
38 if ((kid = (id)NSAllocateObject(self, sizeof(id) * _count, _zone))) {
40 kid->entityName = [_name copyWithZone:_zone];
43 for (i = 0; i < _count; i++) {
45 if (_keyValues[i] == nil) {
46 NSLog(@"WARN(%s): got 'nil' as a EOKeyGlobalID value (entity=%@)!",
47 __PRETTY_FUNCTION__, _name);
50 kid->values[i] = [_keyValues[i] retain];
53 return [kid autorelease];
61 for (i = 0; i < self->count; i++) {
62 [self->values[i] release];
63 self->values[i] = nil;
65 [self->entityName release];
71 - (NSString *)entityName {
72 return self->entityName;
75 - (unsigned int)keyCount {
79 return &(self->values[0]);
82 - (NSArray *)keyValuesArray {
83 return [NSArray arrayWithObjects:&(self->values[0]) count:self->count];
89 return [self->entityName hash] - [self->values[0] hash];
92 - (BOOL)isEqual:(id)_other {
93 EOKeyGlobalID *otherKey;
96 if (_other == nil) return NO;
97 if (_other == self) return YES;
99 if (otherKey->isa != self->isa) return NO;
100 if (otherKey->count != self->count) return NO;
101 if (![otherKey->entityName isEqualToString:self->entityName]) return NO;
103 for (i = 0; i < self->count; i++) {
104 if (self->values[i] != otherKey->values[i]) {
105 if (![self->values[i] isEqual:otherKey->values[i]])
115 - (id)copyWithZone:(NSZone *)_zone {
116 return [self retain];
121 - (void)encodeWithCoder:(NSCoder *)_coder {
122 [self doesNotRecognizeSelector:_cmd];
124 - (id)initWithCoder:(NSCoder *)_coder {
125 [self doesNotRecognizeSelector:_cmd];
128 NSString *entityName;
135 entityName = [_coder decodeObject];
137 self = [EOKeyGlobalID globalIDWithEntityName:entityName
141 return [self retain];
147 - (NSString *)description {
152 s = [[NSMutableString alloc] init];
153 [s appendFormat:@"<0x%p[%@]: %@",
154 self, NSStringFromClass([self class]),
157 if (self->count == 0) {
158 [s appendString:@" no-key-values"];
161 for (i = 0; i < self->count; i++) {
162 if (i == 0) [s appendString:@" "];
163 else [s appendString:@"/"];
164 if (self->values[i] == nil)
165 [s appendString:@"<nil>"];
166 else if (self->values[i] == nil)
167 [s appendString:@"<NSNull>"];
169 [s appendString:[self->values[i] stringValue]];
173 [s appendString:@">"];
177 return [d autorelease];
180 @end /* EOKeyGlobalID */