2 Copyright (C) 2000-2005 SKYRIX Software AG
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 "EOKeyGlobalID.h"
25 @implementation EOKeyGlobalID
27 + (id)globalIDWithEntityName:(NSString *)_name
29 keyCount:(unsigned int)_count
35 @"missing key-values (count is 0, entity is %@", _name);
37 if ((kid = (id)NSAllocateObject(self, sizeof(id) * _count, _zone))) {
39 kid->entityName = [_name copyWithZone:_zone];
42 for (i = 0; i < _count; i++)
43 kid->values[i] = [_keyValues[i] retain];
45 return [kid autorelease];
53 for (i = 0; i < self->count; i++) {
54 [self->values[i] release];
55 self->values[i] = nil;
57 [self->entityName release];
63 - (NSString *)entityName {
64 return self->entityName;
67 - (unsigned int)keyCount {
71 return &(self->values[0]);
74 - (NSArray *)keyValuesArray {
75 return [NSArray arrayWithObjects:&(self->values[0]) count:self->count];
81 return [self->entityName hash] - [self->values[0] hash];
84 - (BOOL)isEqual:(id)_other {
85 EOKeyGlobalID *otherKey;
88 if (_other == nil) return NO;
89 if (_other == self) return YES;
91 if (otherKey->isa != self->isa) return NO;
92 if (otherKey->count != self->count) return NO;
93 if (![otherKey->entityName isEqualToString:self->entityName]) return NO;
95 for (i = 0; i < self->count; i++) {
96 if (self->values[i] != otherKey->values[i]) {
97 if (![self->values[i] isEqual:otherKey->values[i]])
107 - (id)copyWithZone:(NSZone *)_zone {
108 return [self retain];
113 - (void)encodeWithCoder:(NSCoder *)_coder {
114 [self doesNotRecognizeSelector:_cmd];
116 - (id)initWithCoder:(NSCoder *)_coder {
117 [self doesNotRecognizeSelector:_cmd];
120 NSString *entityName;
127 entityName = [_coder decodeObject];
129 self = [EOKeyGlobalID globalIDWithEntityName:entityName
133 return [self retain];
139 - (NSString *)description {
144 s = [[NSMutableString alloc] init];
145 [s appendFormat:@"<0x%08X[%@]: %@",
146 self, NSStringFromClass([self class]),
149 for (i = 0; i < self->count; i++) {
150 if (i == 0) [s appendString:@" "];
151 else [s appendString:@"/"];
152 [s appendString:[self->values[i] stringValue]];
155 [s appendString:@">"];
159 return [d autorelease];
162 @end /* EOKeyGlobalID */