1994-11-04 16:29:24 +00:00
|
|
|
/* Implementation for Objective-C MappedCollector collection object
|
1996-02-22 15:11:43 +00:00
|
|
|
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
1994-11-04 16:29:24 +00:00
|
|
|
|
1996-04-17 20:17:45 +00:00
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
1996-02-22 15:11:43 +00:00
|
|
|
Created: May 1993
|
1994-11-04 16:29:24 +00:00
|
|
|
|
1996-04-17 19:55:26 +00:00
|
|
|
This file is part of the Gnustep Base Library.
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
1996-04-17 15:23:00 +00:00
|
|
|
#include <gnustep/base/MappedCollector.h>
|
|
|
|
#include <gnustep/base/Dictionary.h>
|
|
|
|
#include <gnustep/base/CollectionPrivate.h>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
@implementation MappedCollector
|
|
|
|
|
|
|
|
/* This is the designated initializer for this class */
|
1996-02-22 15:11:43 +00:00
|
|
|
- initWithCollection: (id <KeyedCollecting>)aDomain
|
1994-11-04 16:29:24 +00:00
|
|
|
map: (id <KeyedCollecting>)aMap
|
|
|
|
{
|
|
|
|
_map = aMap;
|
|
|
|
_domain = aDomain;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Archiving must mimic the above designated initializer */
|
|
|
|
|
1995-04-09 01:53:53 +00:00
|
|
|
- (void) encodeWithCoder: anEncoder
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
|
|
|
[self notImplemented:_cmd];
|
|
|
|
}
|
|
|
|
|
1995-04-09 01:53:53 +00:00
|
|
|
+ newWithCoder: aDecoder
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
|
|
|
[self notImplemented:_cmd];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
/* Override our superclass' designated initializer */
|
|
|
|
- initWithObjects: (id*)objects forKeys: (id*)keys count: (unsigned)c
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
[self notImplemented: _cmd];
|
1996-03-18 13:52:10 +00:00
|
|
|
return nil;
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Empty copy must empty an allocCopy'ed version of self */
|
|
|
|
- emptyCopy
|
|
|
|
{
|
|
|
|
MappedCollector *copy = [super emptyCopy];
|
|
|
|
copy->_map = [_map emptyCopy];
|
|
|
|
copy->_domain = [_domain emptyCopy];
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This must work without sending any messages to content objects */
|
1996-02-22 15:11:43 +00:00
|
|
|
- (void) empty
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
|
|
|
[_domain empty];
|
|
|
|
}
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
- objectAtKey: aKey
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
return [_domain objectAtKey: [_map objectAtKey: aKey]];
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
- keyOfObject: aContentObject
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
[self notImplemented: _cmd];
|
|
|
|
return self;
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
- (void) replaceObjectAtKey: aKey with: newObject
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
return [_domain replaceObjectAtKey: [_map objectAtKey: aKey]
|
|
|
|
with: newObject];
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
- (void) putObject: newObject atKey: aKey
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
return [_domain putObject: newObject
|
|
|
|
atKey: [_map objectAtKey:aKey]];
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
- (void) removeObjectAtKey: aKey
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
return [_domain removeObjectAtKey: [_map objectAtKey: aKey]];
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
- (BOOL) containsKey: aKey
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
return [_domain containsKey: [_map objectAtKey:aKey]];
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
1996-04-01 02:41:44 +00:00
|
|
|
- (void*) newEnumState
|
|
|
|
{
|
|
|
|
return [_domain newEnumState];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) freeEnumState: (void**)enumState
|
|
|
|
{
|
|
|
|
return [_domain freeEnumState: enumState];
|
|
|
|
}
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
- nextObjectAndKey: (id*)keyPtr withEnumState: (void**)enumState
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
id mapContent;
|
|
|
|
id domainKey;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
1996-04-01 02:50:55 +00:00
|
|
|
/* xxx This needs debugging; see checks/test02.m */
|
1996-02-22 15:11:43 +00:00
|
|
|
while ((mapContent = [_map nextObjectAndKey:keyPtr withEnumState:enumState])
|
1994-11-04 16:29:24 +00:00
|
|
|
&&
|
1996-02-22 15:11:43 +00:00
|
|
|
(![_domain containsKey: (domainKey = [_map objectAtKey:*keyPtr])]))
|
1994-11-04 16:29:24 +00:00
|
|
|
;
|
1996-02-22 15:11:43 +00:00
|
|
|
if (mapContent == NO_OBJECT)
|
|
|
|
return NO_OBJECT;
|
|
|
|
return [_domain objectAtKey: domainKey];
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- species
|
|
|
|
{
|
|
|
|
return [Dictionary class];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|