libs-gdl2/EOControl/EOMutableKnownKeyDictionary.m

968 lines
23 KiB
Mathematica
Raw Normal View History

/**
EEOMutableKnownKeyDictionary.m <title>EEOMutableKnownKeyDictionary</title>
Copyright (C) 2000-2002 Free Software Foundation, Inc.
Author: Manuel Guesdon <mguesdon@orange-concept.com>
Date: October 2000
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
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; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</license>
**/
#include "config.h"
RCS_ID("$Id$")
#ifdef GNUSTEP
2003-03-30 David Ayers <d.ayers@inode.at> * *.h/m, *.h/m): Used #include instead of depricated #import. Avoid including entire library headers. Use export macro where applicable. * EOControl/GNUmakefile: Removed EOKeyValueCodingBase.m/h and EOUndoMananger.h. Added EOArrayDataSource.m/h, EODefines.h and EODepricated.h. * EOControl/EODefines.h: Updated for GDL2 & gnustep-make. * EOControl/EODebug.h: Updated. * EOControl/EODepricated.h: Updated for current state of GDL2. ([NSObject +flushClassKeyBindings]): Added declaration. ([EOClassDescription +setDelegate:]): Added declaration. ([EOClassDescription +delegate]): Added declaration. (EOUndoManager): Moved declaration of interface here. * EOControl/EOKeyValueCoding.m ([EOClassDescription +flushClassKeyBindings]): Added empty implementation. ([NSObject takeStoredValuesFromDictionary:]): Cache EONull instance and use it instead of isKindOfClass:. * EOControl/EOEditingContext.m ([EOEditingContext +initialize]): Tidied. ([EOEditingContest -deleteObject]): Use NSUndoManager instead of EOUndoManager. * EOControl/EOQualifier.m ([NSArray -filteredArrayUsingQualifier:]): Added minor optimization tweak. * EOControl/EOClassDescription.m: Removed inactive commented code. Added private declerations of EOAccess methods to avoid compiler warnings. ([EOClassDescription +initialize]): Tidied. ([EOClassDescription -classDescriptionForClass:]): Use GSObjCName() instead of objc runtime routines. * EOControl/EOFault.m: Exchanged direct usages of ObjC runtime routines with NS/GSObjCRuntime abstraction API. ([EOFault +superclass]): Ditto. ([EOFault +targetClassForFault:]): Ditto. ([EOFault -respondsToSelector:]): Ditto. ([EOFault +initialize]): Cache static class variable. ([EOFault +isKindOfClass]): Use static class variable. ([EOFault +handlerForFault:]): Ditto. ([EOFault +targetClassForFault:]): Ditto. ([EOFault -dealloc]): Ditto. * EOControl/EOGenericRecord.m: ([EOGenericRecord +initialize]): Tidied. * EOControl/EOKeyComparisonQualifier.m: Tidied documentation. * EOControl/EOKeyValueQualifier.m: Ditto. * EOControl/EONSAddOns.h/m: Added declarations to surpress compiler warnings. ([NSObject -eoCompareOnName:]): Adjusted casts to surpress compiler warnings. (GSUseStrictWO451Compatibility): Added function. (GDL2GlobalLock, GDL2GlobalRecursive): Ditto. * EOControl/EONull: Remove implementations for foundation libraries without key value coding and fully rely on NSNull. Added assertions in all intance methods as instances should never be created. ([EONull +allocWithZone:]) Corrected method name so it will actually be used. * EOControl/EOSortOrdering.m ([NSArray sortedArrayUsingKeyOrderArray:]): Tidied. ([NSMutableArray sortUsingKeyOrderArray:]): Ditto. ([EONull compareAscending:]): Sync with referencs implementation. ([EONull compareDescending:]): Ditto. ([EONull compareCaseInsensitiveAscending:]): Ditto. ([EONull compareCaseInsensitiveDescending:]): Ditto. * EOAccess/EOAdaptor.h: Added comment about API compatibility. * EOAccess/EOAdaptor.m ([EOAdaptor -contexts]): Return array of adaptor contexts rather tham GC-wrapper objects containing adaptor contexts. ([EOAdaptor -databaseEncoding]): Use GSEncodingName() instead of GetEncodingName(). * EOAccess/EODatabaseContext.m ([EODatabaseContext -_turnFault:gid:editingContext:isComplete:]): Use GSObjCClass() instead of trying to access isa by dereferencing from id with incorrect member. * EOAccess/EOModel.m ([EOModel -entityNames]): Sort returned array to insure comparable output. * EOAccess/EOSQLExpression.m ([EOSQLExpression sqlStringForArrayOfQualifiers:operation:]): Added cast to surpress compiler warning. * EOAccess/EOUtilities.m ([EOObjectStoreCoordinator setModelGroup:]): Ditto. * EOAccess/EORelationship.h ([EORelationship -docComment]): Added declaration. * EOAccess/GNUmakefile: Added EODefines.h and EODepricated.h. * Tools/*.m: Use RCS_ID macro. * Tools/EOAttribute+GSDoc.h: ([EOAttribute gsdocContentWithTagName:idPtr:]): Corrected Typo. * Tools/EOModel+GSDoc.h/m: ([EOModel gsdocContentSplittedByEntities:idPtr:]): Ditto. * Tools/EORelationship+GSDoc.m: ([EORelationship gsdocContentWithTagName:idPtr:]): Change variable type to supress compiler warnings. * Tools/eoutil.m (dump): Initialize variables to supress compiler warnings. * Tools/gsdoc-model.m: Include GSCategories.h to supress compiler warnings. (main): Added cast to supress compiler warning. Fixed typo in method invocation. 2003-03-25 Stephane Corthesy <stephane@sente.ch> * EOControl/EODefines.h: Added new file for export/win32 support. * EOControl/EODepricated.h: Added new file for depricated features. * EOControl/EOControl.h: Added EOArrayDataSource.h and EODefines.h. * EOControl/EOArrayDataSource.h/m: Added new files. Some methods (<NSCoding> and qualifier bindings) are empty stubs. * EOControl/EODebug.h: Use export macro instead of explicit extern for function and symbol declarations. * EOControl/EOGlobalID.h: Ditto. * EOControl/EONull.h: Ditto. * EOControl/EOObjectStore.h: Ditto. * EOControl/EOOrQualifier.m: Replaced autorelease by AUTORELEASE and fixed typo. * EOControl/EOQualifier.m ([NSArray -filteredArrayUsingQualifier:]): Implemented. * EOControl/EONSAddOns.m: Use volatile in some exception handlers (man longjmp for more info). * EOControl/EOSortOrdering.h/m ([EOSortOrdering -copyWithZone:]): Implemented <NSCopying>. ([EOSortOrdering -encodeWithKeyValueArchiver:]): Implemented. * EOAccess/EODefines.h: Added new file for export/win32 support. * EOAccess/EODepricated.h: Added new file for depricated features. * EOAccess/EOAccess.h: Added EODefines.h. * EOAccess/EOSQLExpression.h/m: Fixed typo for EOPrimaryKeyConstraintKey. * EOAccess/EOExpressionArray.h/m: Use volatile for variables usein in exception handlers. (man longjmp for more info) * EOAccess/EODatabase.h: Use export macro instead of explicit extern for function and symbol declarations. * EOAccess/EOEntity.h: Ditto. * EOAccess/EOModel.h: Ditto. * EOAccess/EOSchemaGeneration.h: Ditto. * EOAccess/EOSQLExpression.h: Ditto. * EOAccess/EOUtilities.h: Ditto. * Tools/eoutil.m (dump): Implemented use of -postinstall option. Corrected bug when getting adaptor's expression class. Renamed symbol EOPrimaryKeyContraintsKey into EOPrimaryKeyConstraintsKey. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@16298 72102866-910b-0410-8b05-ffd578937521
2003-03-31 00:24:15 +00:00
#include <Foundation/NSArray.h>
#include <Foundation/NSString.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSEnumerator.h>
#include <Foundation/NSException.h>
#include <Foundation/NSZone.h>
#include <Foundation/NSMapTable.h>
#else
#include <Foundation/Foundation.h>
#endif
#ifndef GNUSTEP
#include <GNUstepBase/GNUstep.h>
#include <GNUstepBase/GSObjCRuntime.h>
* EOAccess/EOAdaptor.m: Include GNUstep-specific headers for non-GNUstep systems. * EOAccess/EOAdaptorChannel.m: Ditto. * EOAccess/EOAdaptorContext.m: Ditto. * EOAccess/EOAttribute.m: Ditto. * EOAccess/EODatabaseChannel.m: Ditto. * EOAccess/EODatabaseDataSource.m: Ditto. * EOAccess/EOEntity.m: Ditto. * EOAccess/EOModel.m: Ditto. * EOAccess/EOModelGroup.m: Ditto. * EOAccess/EORelationship.m: Ditto. * EOAccess/EOSQLQualifier.m: Ditto. * EOAccess/EOUtilities.m: Ditto. * EOControl/EOAndQualifier.m: Ditto. * EOControl/EOClassDescription.m: Ditto. * EOControl/EODataSource.m: Ditto. * EOControl/EOEditingContext.m: Ditto. * EOControl/EOFault.m: Ditto. * EOControl/EOFaultHandler.m: Ditto. * EOControl/EOFetchSpecification.m: Ditto. * EOControl/EOKeyValueArchiver.m: Ditto. * EOControl/EOKeyValueQualifier.m: Ditto. * EOControl/EOMutableKnownKeyDictionary.m: Ditto. * EOControl/EONSAddOns.m: Ditto. * EOControl/EOObjectStore.m: Ditto. * EOControl/EOObjectStoreCoordinator.m: Ditto. * EOControl/EOObserver.m: Ditto. * EOControl/EOOrQualifier.m: Ditto. * EOControl/EOQualifier.m: Ditto. * EOControl/EOUndoManager.m: Ditto. * EOModeler/EOModelExtensions.m: Ditto. * EOAccess/EOModel.h/m (+/-[EOModel version]) Remove. ([EOModel init]): Handle version internally. ([EOModel encodeTableOfContentsIntoPropertyList:]): Ditto. ([EOModel encodeIntoPropertyList:]): Ditto. * EOAccess/EODatabaseContext.m ([EODatabaseContext dealloc]): Use NSCountHashTable instead of NSCountMapTable on hash table. * EOAccess/EOAttribute.m ([EOAttribute newValueForBytes:length:]): Added casts to avoid warnings. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@18500 72102866-910b-0410-8b05-ffd578937521
2004-01-29 13:23:22 +00:00
#include <GNUstepBase/GSCategories.h>
#endif
2003-03-30 David Ayers <d.ayers@inode.at> * *.h/m, *.h/m): Used #include instead of depricated #import. Avoid including entire library headers. Use export macro where applicable. * EOControl/GNUmakefile: Removed EOKeyValueCodingBase.m/h and EOUndoMananger.h. Added EOArrayDataSource.m/h, EODefines.h and EODepricated.h. * EOControl/EODefines.h: Updated for GDL2 & gnustep-make. * EOControl/EODebug.h: Updated. * EOControl/EODepricated.h: Updated for current state of GDL2. ([NSObject +flushClassKeyBindings]): Added declaration. ([EOClassDescription +setDelegate:]): Added declaration. ([EOClassDescription +delegate]): Added declaration. (EOUndoManager): Moved declaration of interface here. * EOControl/EOKeyValueCoding.m ([EOClassDescription +flushClassKeyBindings]): Added empty implementation. ([NSObject takeStoredValuesFromDictionary:]): Cache EONull instance and use it instead of isKindOfClass:. * EOControl/EOEditingContext.m ([EOEditingContext +initialize]): Tidied. ([EOEditingContest -deleteObject]): Use NSUndoManager instead of EOUndoManager. * EOControl/EOQualifier.m ([NSArray -filteredArrayUsingQualifier:]): Added minor optimization tweak. * EOControl/EOClassDescription.m: Removed inactive commented code. Added private declerations of EOAccess methods to avoid compiler warnings. ([EOClassDescription +initialize]): Tidied. ([EOClassDescription -classDescriptionForClass:]): Use GSObjCName() instead of objc runtime routines. * EOControl/EOFault.m: Exchanged direct usages of ObjC runtime routines with NS/GSObjCRuntime abstraction API. ([EOFault +superclass]): Ditto. ([EOFault +targetClassForFault:]): Ditto. ([EOFault -respondsToSelector:]): Ditto. ([EOFault +initialize]): Cache static class variable. ([EOFault +isKindOfClass]): Use static class variable. ([EOFault +handlerForFault:]): Ditto. ([EOFault +targetClassForFault:]): Ditto. ([EOFault -dealloc]): Ditto. * EOControl/EOGenericRecord.m: ([EOGenericRecord +initialize]): Tidied. * EOControl/EOKeyComparisonQualifier.m: Tidied documentation. * EOControl/EOKeyValueQualifier.m: Ditto. * EOControl/EONSAddOns.h/m: Added declarations to surpress compiler warnings. ([NSObject -eoCompareOnName:]): Adjusted casts to surpress compiler warnings. (GSUseStrictWO451Compatibility): Added function. (GDL2GlobalLock, GDL2GlobalRecursive): Ditto. * EOControl/EONull: Remove implementations for foundation libraries without key value coding and fully rely on NSNull. Added assertions in all intance methods as instances should never be created. ([EONull +allocWithZone:]) Corrected method name so it will actually be used. * EOControl/EOSortOrdering.m ([NSArray sortedArrayUsingKeyOrderArray:]): Tidied. ([NSMutableArray sortUsingKeyOrderArray:]): Ditto. ([EONull compareAscending:]): Sync with referencs implementation. ([EONull compareDescending:]): Ditto. ([EONull compareCaseInsensitiveAscending:]): Ditto. ([EONull compareCaseInsensitiveDescending:]): Ditto. * EOAccess/EOAdaptor.h: Added comment about API compatibility. * EOAccess/EOAdaptor.m ([EOAdaptor -contexts]): Return array of adaptor contexts rather tham GC-wrapper objects containing adaptor contexts. ([EOAdaptor -databaseEncoding]): Use GSEncodingName() instead of GetEncodingName(). * EOAccess/EODatabaseContext.m ([EODatabaseContext -_turnFault:gid:editingContext:isComplete:]): Use GSObjCClass() instead of trying to access isa by dereferencing from id with incorrect member. * EOAccess/EOModel.m ([EOModel -entityNames]): Sort returned array to insure comparable output. * EOAccess/EOSQLExpression.m ([EOSQLExpression sqlStringForArrayOfQualifiers:operation:]): Added cast to surpress compiler warning. * EOAccess/EOUtilities.m ([EOObjectStoreCoordinator setModelGroup:]): Ditto. * EOAccess/EORelationship.h ([EORelationship -docComment]): Added declaration. * EOAccess/GNUmakefile: Added EODefines.h and EODepricated.h. * Tools/*.m: Use RCS_ID macro. * Tools/EOAttribute+GSDoc.h: ([EOAttribute gsdocContentWithTagName:idPtr:]): Corrected Typo. * Tools/EOModel+GSDoc.h/m: ([EOModel gsdocContentSplittedByEntities:idPtr:]): Ditto. * Tools/EORelationship+GSDoc.m: ([EORelationship gsdocContentWithTagName:idPtr:]): Change variable type to supress compiler warnings. * Tools/eoutil.m (dump): Initialize variables to supress compiler warnings. * Tools/gsdoc-model.m: Include GSCategories.h to supress compiler warnings. (main): Added cast to supress compiler warning. Fixed typo in method invocation. 2003-03-25 Stephane Corthesy <stephane@sente.ch> * EOControl/EODefines.h: Added new file for export/win32 support. * EOControl/EODepricated.h: Added new file for depricated features. * EOControl/EOControl.h: Added EOArrayDataSource.h and EODefines.h. * EOControl/EOArrayDataSource.h/m: Added new files. Some methods (<NSCoding> and qualifier bindings) are empty stubs. * EOControl/EODebug.h: Use export macro instead of explicit extern for function and symbol declarations. * EOControl/EOGlobalID.h: Ditto. * EOControl/EONull.h: Ditto. * EOControl/EOObjectStore.h: Ditto. * EOControl/EOOrQualifier.m: Replaced autorelease by AUTORELEASE and fixed typo. * EOControl/EOQualifier.m ([NSArray -filteredArrayUsingQualifier:]): Implemented. * EOControl/EONSAddOns.m: Use volatile in some exception handlers (man longjmp for more info). * EOControl/EOSortOrdering.h/m ([EOSortOrdering -copyWithZone:]): Implemented <NSCopying>. ([EOSortOrdering -encodeWithKeyValueArchiver:]): Implemented. * EOAccess/EODefines.h: Added new file for export/win32 support. * EOAccess/EODepricated.h: Added new file for depricated features. * EOAccess/EOAccess.h: Added EODefines.h. * EOAccess/EOSQLExpression.h/m: Fixed typo for EOPrimaryKeyConstraintKey. * EOAccess/EOExpressionArray.h/m: Use volatile for variables usein in exception handlers. (man longjmp for more info) * EOAccess/EODatabase.h: Use export macro instead of explicit extern for function and symbol declarations. * EOAccess/EOEntity.h: Ditto. * EOAccess/EOModel.h: Ditto. * EOAccess/EOSchemaGeneration.h: Ditto. * EOAccess/EOSQLExpression.h: Ditto. * EOAccess/EOUtilities.h: Ditto. * Tools/eoutil.m (dump): Implemented use of -postinstall option. Corrected bug when getting adaptor's expression class. Renamed symbol EOPrimaryKeyContraintsKey into EOPrimaryKeyConstraintsKey. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@16298 72102866-910b-0410-8b05-ffd578937521
2003-03-31 00:24:15 +00:00
#include <EOControl/EOMutableKnownKeyDictionary.h>
#include <EOControl/EODebug.h>
#include <EOControl/EONull.h>
@implementation EOMKKDInitializer
+ (EOMKKDInitializer*)initializerFromKeyArray: (NSArray*)keys
{
EOMKKDInitializer *initializer = [[self newWithKeyArray: keys] autorelease];
return initializer;
}
+ (id)newWithKeyArray: (NSArray*)keys
{
return [[self alloc]
initWithKeys: keys];
}
+ (id)newWithKeyArray: (NSArray*)keys
zone: (NSZone*)zone
{
return [[self allocWithZone: zone]
initWithKeys: keys];
}
- (id)initWithKeys: (id*)keys
count: (int)count
{
if ((self = [self init]))
{
int i;
NSAssert(keys, @"No array of keys");
NSAssert(count > 0, @"No keys in array");
_keyToIndex = NSCreateMapTableWithZone(NSObjectMapKeyCallBacks,
NSIntMapValueCallBacks,
count,
[self zone]);
_keys = NSZoneMalloc([self zone], count * sizeof(NSString*));
EOFLOGObjectLevelArgs(@"EOMKKD", @"keys=%p _keys=%p", keys, _keys);
for (i = 0; i < count; i++)
{
id key = keys[i];
void *oldValue;
_count = i + 1;
EOFLOGObjectLevelArgs(@"EOMKKD", @"key=%p", key);
EOFLOGObjectLevelArgs(@"EOMKKD", @"key=%@ RETAINCOUNT=%d",
key, [key retainCount]);
oldValue = NSMapInsertIfAbsent(_keyToIndex,key, (const void*)(i + 1)); //+1 because 0 = no object
_keys[i] = key; //Don't retain: already retained by Map
EOFLOGObjectLevelArgs(@"EOMKKD", @"key=%@ RETAINCOUNT=%d",
key, [key retainCount]);
NSAssert1(!oldValue, @"%@ already present", key);
}
EOFLOGObjectLevelArgs(@"EOMKKD", @"self=%p", self);
}
return self;
}
- (id)initWithKeys: (NSArray*)keys
{
int count = [keys count];
NSAssert(keys, @"No array of keys");
NSAssert([keys count] > 0, @"No keys in array");
{
id keysArray[count];
memset(keysArray, 0, count * sizeof(id));
[keys getObjects: keysArray];
if ((self = [self initWithKeys: keysArray
count: count]))
{
}
}
EOFLOGObjectLevelArgs(@"EOMKKD", @"self=%p", self);
return self;
}
- (void)dealloc
{
EOFLOGObjectLevelArgs(@"EOMKKD", @"Deallocate EOMKKDInitliazer %p", self);
if (_keyToIndex)
NSFreeMapTable(_keyToIndex);
if (_keys)
NSZoneFree([self zone],_keys);
[super dealloc];
//EOFLogC("GSWElementIDString end of dealloc");
}
- (void)gcDecrementRefCountOfContainedObjects
{
// [X gcDecrementRefCount];
}
- (BOOL)gcIncrementRefCountOfContainedObjects
{
if (![super gcIncrementRefCountOfContainedObjects])
return NO;
//[XX gcIncrementRefCount];
//[XX gcIncrementRefCountOfContainedObjects];
return YES;
}
- (NSString*)description
{
NSString *dscr;
int i;
dscr = [NSString stringWithFormat: @"<%s %p - keys=",
object_get_class_name(self),
(void*)self];
for (i = 0; i < _count; i++)
{
dscr = [dscr stringByAppendingFormat: @"%@ [%d] ",
_keys[i],
i];
}
dscr = [dscr stringByAppendingString: @">"];
return dscr;
}
- (void) setObject: (id)object
forIndex: (unsigned int)index
dictionary: (NSMutableDictionary*)dictionary
{
//OK?
id key;
NSAssert2(index < _count, @"bad index %d (count=%u)", index, _count);
key = _keys[index];
[dictionary setObject: object
forKey: key];
}
- (id) objectForIndex: (unsigned int)index
dictionary: (NSDictionary*)dictionary
{
id key;
NSAssert2(index < _count, @"bad index %d (count=%u)", index, _count);
key = _keys[index];
return [dictionary objectForKey: key];
}
- (unsigned int) indexForKey: (NSString*)key
{
void *index = NSMapGet(_keyToIndex, (const void *)key);
if (!index)
return NSNotFound;
else
return (unsigned int)(index - 1);
}
- (BOOL)hasKey: (id)key
{
return ([self indexForKey: key] != NSNotFound);
}
- (EOMKKDArrayMapping*) arrayMappingForKeys: (NSArray*)keys
{
int selfKeyCount = [keys count];
int keyCount = [keys count];
EOMKKDArrayMapping *arrayMapping;
int i;
NSAssert(keyCount <= selfKeyCount, @"key count greater than our key count");
arrayMapping = [[EOMKKDArrayMapping newInstanceWithKeyCount: selfKeyCount
destinationDescription: self
zone: [self zone]] autorelease];
for (i = 0; i < keyCount; i++)
{
NSString *key = [keys objectAtIndex: i];
int destinationIndex = [self indexForKey:key];
arrayMapping->_destinationOffsetForArrayIndex[i] = destinationIndex + 1;
}
return arrayMapping;
}
- (EOMKKDSubsetMapping*) subsetMappingForSourceDictionaryInitializer: (EOMKKDInitializer*)sourceInitializer
sourceKeys: (NSArray*)sourceKeys
destinationKeys: (NSArray*)destinationKeys
{
unsigned int selfKeyCount = [self count];
unsigned int keyCount = [destinationKeys count];
EOMKKDSubsetMapping *subsetMapping;
int i;
NSAssert([sourceKeys count] == keyCount, @"Source and destination keys count are different");
NSAssert(keyCount <= selfKeyCount, @"key count greater than our key count");
subsetMapping = [[EOMKKDSubsetMapping newInstanceWithKeyCount: selfKeyCount
sourceDescription: sourceInitializer
destinationDescription: self
zone: [self zone]] autorelease];
EOFLOGObjectLevelArgs(@"EOMKKD", @"sourceDescription=%@", sourceInitializer);
EOFLOGObjectLevelArgs(@"EOMKKD", @"destinationDescription=%@", self);
EOFLOGObjectLevelArgs(@"EOMKKD", @"sourceKeys=%@", sourceKeys);
EOFLOGObjectLevelArgs(@"EOMKKD", @"destinationKeys=%@", destinationKeys);
for (i = 0; i < keyCount; i++)
{
NSString *sourceKey;
NSString *destinationKey;
int destinationIndex;
int sourceIndex;
sourceKey = [sourceKeys objectAtIndex: i];
EOFLOGObjectLevelArgs(@"EOMKKD", @"sourceKey=%@", sourceKey);
destinationKey = [destinationKeys objectAtIndex: i];
EOFLOGObjectLevelArgs(@"EOMKKD", @"destinationKey=%@", destinationKey);
destinationIndex = [self indexForKey: destinationKey];
EOFLOGObjectLevelArgs(@"EOMKKD", @"destinationIndex=%d",
destinationIndex);
sourceIndex = [sourceInitializer indexForKey: sourceKey];
EOFLOGObjectLevelArgs(@"EOMKKD", @"sourceIndex=%d", sourceIndex);
NSAssert2(destinationIndex != NSNotFound,
2003-03-21 Manuel Guesdon <mguesdon@orange-concept.com> * EOAccess/EODatabaseContext.m: o added assert in _primaryKeyForObject: o in -recordChangesInEditingContext test nil/eonull on relationshipCommitedSnapshotValue and relationshipSnapshotValue instead of only nil testing o in -recordChangesInEditingContext fix for value changing testing when commitedSnapshotValue is nil/EONull * EOAccess/EOEntity.m: o logs o fix in inverseRelationshipClassPropertyNames to test on destination entity property names * EOControl/EOClassDescription.m: o logs * EOControl/GNUmakefile: o added EONSAddOns.h * EOCOntrol/EOKeyValueCoding.m: o fixes in NSArray -computeXXForKey: * EOAccess/EOSQLExpression.m: o assert in -sqlStringForKeyValueQualifier: o -sqlStringForArrayOfQualifiers:operation: hanlde different qualifier cases using isKindOfClass: may probably be improved o logs * EOControl/EOEditingContext.m: o fix in unprocessedInfo (invert/change swap). * EOControl/EOQualifier.m o -qualifierWithQualifierFormat:varargList: raise exception if operator is unknwon * EOControl/EOMutableKnownKeyDictionary.m: o add precision in exception message * EOAccess/EORelationship.m: o more info in some logs o fix in -_sourceRowToForeignKeyMapping for foreign keys which are not in primaryKey. * EOControl/EODatabaseOperation.m: o in -setDatabaseOperator: Don't Delete a not inserted object * EOControl/EOAccessFault.m: o logs o EOAccessFaultHandler: -dealloc fix: call super dealloc o implement faultWillFire: This fix a hard memory problem * EOControl/EOFault.m: o -dealloc: fix possible infinite loop o logs * EOCheapCopyArray.m: o ucomment retain/release/... o fix shallowCopy for memory management. This was causing hard memory trouble git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@16217 72102866-910b-0410-8b05-ffd578937521
2003-03-21 20:41:07 +00:00
@"Destination Key %@ not found in %@",
destinationKey,
self);
NSAssert2(sourceIndex != NSNotFound,
2003-03-21 Manuel Guesdon <mguesdon@orange-concept.com> * EOAccess/EODatabaseContext.m: o added assert in _primaryKeyForObject: o in -recordChangesInEditingContext test nil/eonull on relationshipCommitedSnapshotValue and relationshipSnapshotValue instead of only nil testing o in -recordChangesInEditingContext fix for value changing testing when commitedSnapshotValue is nil/EONull * EOAccess/EOEntity.m: o logs o fix in inverseRelationshipClassPropertyNames to test on destination entity property names * EOControl/EOClassDescription.m: o logs * EOControl/GNUmakefile: o added EONSAddOns.h * EOCOntrol/EOKeyValueCoding.m: o fixes in NSArray -computeXXForKey: * EOAccess/EOSQLExpression.m: o assert in -sqlStringForKeyValueQualifier: o -sqlStringForArrayOfQualifiers:operation: hanlde different qualifier cases using isKindOfClass: may probably be improved o logs * EOControl/EOEditingContext.m: o fix in unprocessedInfo (invert/change swap). * EOControl/EOQualifier.m o -qualifierWithQualifierFormat:varargList: raise exception if operator is unknwon * EOControl/EOMutableKnownKeyDictionary.m: o add precision in exception message * EOAccess/EORelationship.m: o more info in some logs o fix in -_sourceRowToForeignKeyMapping for foreign keys which are not in primaryKey. * EOControl/EODatabaseOperation.m: o in -setDatabaseOperator: Don't Delete a not inserted object * EOControl/EOAccessFault.m: o logs o EOAccessFaultHandler: -dealloc fix: call super dealloc o implement faultWillFire: This fix a hard memory problem * EOControl/EOFault.m: o -dealloc: fix possible infinite loop o logs * EOCheapCopyArray.m: o ucomment retain/release/... o fix shallowCopy for memory management. This was causing hard memory trouble git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@16217 72102866-910b-0410-8b05-ffd578937521
2003-03-21 20:41:07 +00:00
@"Source Key %@ not found in %@",
sourceKey,
sourceInitializer);
subsetMapping->_sourceOffsetForDestinationOffset[destinationIndex]
= sourceIndex + 1;
}
return subsetMapping;
}
- (EOMKKDSubsetMapping*)subsetMappingForSourceDictionaryInitializer: (EOMKKDInitializer*)sourceInitializer
{
unsigned keyCount = [self count];
EOMKKDSubsetMapping *subsetMapping = [[EOMKKDSubsetMapping
newInstanceWithKeyCount: keyCount
sourceDescription: sourceInitializer
destinationDescription: self
zone: [self zone]] autorelease];
int i;
for (i = 0; i < keyCount; i++)
{
NSString *key;
int index;
key = _keys[i];
EOFLOGObjectLevelArgs(@"EOMKKD", @"key=%@", key);
index = [sourceInitializer indexForKey: key];
EOFLOGObjectLevelArgs(@"EOMKKD", @"index=%d", index);
subsetMapping->_sourceOffsetForDestinationOffset[i]
= (index == NSNotFound ? 0 : index + 1);
}
return subsetMapping;
}
- (id*) keys
{
return _keys;
}
- (unsigned int) count
{
return _count;
}
@end
@implementation EOMKKDKeyEnumerator : NSEnumerator
- (id) initWithTarget: (EOMutableKnownKeyDictionary*)target
{
if ((self = [super init]))
{
EOMKKDInitializer *initializer;
NSAssert(target,@"No target");
ASSIGN(_target,target);
ASSIGN(_extraEnumerator, [[_target extraData] keyEnumerator]);
initializer = [_target eoMKKDInitializer];
_end = [initializer count];
_keys = [initializer keys];
}
return self;
}
- (void) dealloc
{
// EOFLOGObjectLevelArgs(@"EOMKKD",@"Deallocate EOMKKDEnumerator %p (target=%p)",self,_target);
DESTROY(_target);
DESTROY(_extraEnumerator);
[super dealloc];
}
- (NSString*)description
{
NSString *dscr;
dscr = [NSString stringWithFormat: @"<%s %p - target=%p>",
object_get_class_name(self),
(void*)self,
_target];
return dscr;
}
- (id) nextObject
{
id object = nil;
if (_position < _end)
{
object = _keys[_position];
_position++;
}
else if (_extraEnumerator)
{
object = [_extraEnumerator nextObject];
if (object)
_position++;
}
return object;
}
@end
@implementation EOMKKDSubsetMapping
+ (id)newInstanceWithKeyCount: (unsigned int)keyCount
sourceDescription: (EOMKKDInitializer*)source
destinationDescription: (EOMKKDInitializer*)destination
zone: (NSZone*)zone
{
unsigned extraBytes = (keyCount > 0 ? (keyCount - 1) : 0) * sizeof(int);
EOMKKDSubsetMapping *subsetMapping;
subsetMapping = (EOMKKDSubsetMapping*)NSAllocateObject([EOMKKDSubsetMapping class],
extraBytes,
zone);
[subsetMapping init];
ASSIGN(subsetMapping-> _sourceDescription,source);
ASSIGN(subsetMapping-> _destinationDescription,destination);
memset(subsetMapping-> _sourceOffsetForDestinationOffset, 0,
extraBytes + sizeof(int));
return subsetMapping;
}
- (void) dealloc
{
DESTROY(_sourceDescription);
DESTROY(_destinationDescription);
[super dealloc];
}
- (NSString*)description
{
NSString *dscr;
NSMutableString *offsets = [NSMutableString string];
int i;
int count = [_destinationDescription count];
dscr = [NSString stringWithFormat: @"<%s %p - ",
object_get_class_name(self),
(void*)self];
dscr = [dscr stringByAppendingFormat: @"\nsourceDescription=%@",
[_sourceDescription description]];
dscr = [dscr stringByAppendingFormat: @"\ndestinationDescription=%@",
[_destinationDescription description]];
for (i = 0; i < count; i++)
[offsets appendFormat: @" %d", _sourceOffsetForDestinationOffset[i]];
dscr = [dscr stringByAppendingFormat:
@"\nsourceOffsetForDestinationOffset:%@>", offsets];
return dscr;
}
@end
@implementation EOMKKDArrayMapping
+ (id)dictionaryFromDictionary: (NSDictionary *)dict
subsetMapping: (EOMKKDSubsetMapping *)subsetMapping
{
#warning (stephane@sente.ch) Method is really not implemented!
2003-03-30 David Ayers <d.ayers@inode.at> * *.h/m, *.h/m): Used #include instead of depricated #import. Avoid including entire library headers. Use export macro where applicable. * EOControl/GNUmakefile: Removed EOKeyValueCodingBase.m/h and EOUndoMananger.h. Added EOArrayDataSource.m/h, EODefines.h and EODepricated.h. * EOControl/EODefines.h: Updated for GDL2 & gnustep-make. * EOControl/EODebug.h: Updated. * EOControl/EODepricated.h: Updated for current state of GDL2. ([NSObject +flushClassKeyBindings]): Added declaration. ([EOClassDescription +setDelegate:]): Added declaration. ([EOClassDescription +delegate]): Added declaration. (EOUndoManager): Moved declaration of interface here. * EOControl/EOKeyValueCoding.m ([EOClassDescription +flushClassKeyBindings]): Added empty implementation. ([NSObject takeStoredValuesFromDictionary:]): Cache EONull instance and use it instead of isKindOfClass:. * EOControl/EOEditingContext.m ([EOEditingContext +initialize]): Tidied. ([EOEditingContest -deleteObject]): Use NSUndoManager instead of EOUndoManager. * EOControl/EOQualifier.m ([NSArray -filteredArrayUsingQualifier:]): Added minor optimization tweak. * EOControl/EOClassDescription.m: Removed inactive commented code. Added private declerations of EOAccess methods to avoid compiler warnings. ([EOClassDescription +initialize]): Tidied. ([EOClassDescription -classDescriptionForClass:]): Use GSObjCName() instead of objc runtime routines. * EOControl/EOFault.m: Exchanged direct usages of ObjC runtime routines with NS/GSObjCRuntime abstraction API. ([EOFault +superclass]): Ditto. ([EOFault +targetClassForFault:]): Ditto. ([EOFault -respondsToSelector:]): Ditto. ([EOFault +initialize]): Cache static class variable. ([EOFault +isKindOfClass]): Use static class variable. ([EOFault +handlerForFault:]): Ditto. ([EOFault +targetClassForFault:]): Ditto. ([EOFault -dealloc]): Ditto. * EOControl/EOGenericRecord.m: ([EOGenericRecord +initialize]): Tidied. * EOControl/EOKeyComparisonQualifier.m: Tidied documentation. * EOControl/EOKeyValueQualifier.m: Ditto. * EOControl/EONSAddOns.h/m: Added declarations to surpress compiler warnings. ([NSObject -eoCompareOnName:]): Adjusted casts to surpress compiler warnings. (GSUseStrictWO451Compatibility): Added function. (GDL2GlobalLock, GDL2GlobalRecursive): Ditto. * EOControl/EONull: Remove implementations for foundation libraries without key value coding and fully rely on NSNull. Added assertions in all intance methods as instances should never be created. ([EONull +allocWithZone:]) Corrected method name so it will actually be used. * EOControl/EOSortOrdering.m ([NSArray sortedArrayUsingKeyOrderArray:]): Tidied. ([NSMutableArray sortUsingKeyOrderArray:]): Ditto. ([EONull compareAscending:]): Sync with referencs implementation. ([EONull compareDescending:]): Ditto. ([EONull compareCaseInsensitiveAscending:]): Ditto. ([EONull compareCaseInsensitiveDescending:]): Ditto. * EOAccess/EOAdaptor.h: Added comment about API compatibility. * EOAccess/EOAdaptor.m ([EOAdaptor -contexts]): Return array of adaptor contexts rather tham GC-wrapper objects containing adaptor contexts. ([EOAdaptor -databaseEncoding]): Use GSEncodingName() instead of GetEncodingName(). * EOAccess/EODatabaseContext.m ([EODatabaseContext -_turnFault:gid:editingContext:isComplete:]): Use GSObjCClass() instead of trying to access isa by dereferencing from id with incorrect member. * EOAccess/EOModel.m ([EOModel -entityNames]): Sort returned array to insure comparable output. * EOAccess/EOSQLExpression.m ([EOSQLExpression sqlStringForArrayOfQualifiers:operation:]): Added cast to surpress compiler warning. * EOAccess/EOUtilities.m ([EOObjectStoreCoordinator setModelGroup:]): Ditto. * EOAccess/EORelationship.h ([EORelationship -docComment]): Added declaration. * EOAccess/GNUmakefile: Added EODefines.h and EODepricated.h. * Tools/*.m: Use RCS_ID macro. * Tools/EOAttribute+GSDoc.h: ([EOAttribute gsdocContentWithTagName:idPtr:]): Corrected Typo. * Tools/EOModel+GSDoc.h/m: ([EOModel gsdocContentSplittedByEntities:idPtr:]): Ditto. * Tools/EORelationship+GSDoc.m: ([EORelationship gsdocContentWithTagName:idPtr:]): Change variable type to supress compiler warnings. * Tools/eoutil.m (dump): Initialize variables to supress compiler warnings. * Tools/gsdoc-model.m: Include GSCategories.h to supress compiler warnings. (main): Added cast to supress compiler warning. Fixed typo in method invocation. 2003-03-25 Stephane Corthesy <stephane@sente.ch> * EOControl/EODefines.h: Added new file for export/win32 support. * EOControl/EODepricated.h: Added new file for depricated features. * EOControl/EOControl.h: Added EOArrayDataSource.h and EODefines.h. * EOControl/EOArrayDataSource.h/m: Added new files. Some methods (<NSCoding> and qualifier bindings) are empty stubs. * EOControl/EODebug.h: Use export macro instead of explicit extern for function and symbol declarations. * EOControl/EOGlobalID.h: Ditto. * EOControl/EONull.h: Ditto. * EOControl/EOObjectStore.h: Ditto. * EOControl/EOOrQualifier.m: Replaced autorelease by AUTORELEASE and fixed typo. * EOControl/EOQualifier.m ([NSArray -filteredArrayUsingQualifier:]): Implemented. * EOControl/EONSAddOns.m: Use volatile in some exception handlers (man longjmp for more info). * EOControl/EOSortOrdering.h/m ([EOSortOrdering -copyWithZone:]): Implemented <NSCopying>. ([EOSortOrdering -encodeWithKeyValueArchiver:]): Implemented. * EOAccess/EODefines.h: Added new file for export/win32 support. * EOAccess/EODepricated.h: Added new file for depricated features. * EOAccess/EOAccess.h: Added EODefines.h. * EOAccess/EOSQLExpression.h/m: Fixed typo for EOPrimaryKeyConstraintKey. * EOAccess/EOExpressionArray.h/m: Use volatile for variables usein in exception handlers. (man longjmp for more info) * EOAccess/EODatabase.h: Use export macro instead of explicit extern for function and symbol declarations. * EOAccess/EOEntity.h: Ditto. * EOAccess/EOModel.h: Ditto. * EOAccess/EOSchemaGeneration.h: Ditto. * EOAccess/EOSQLExpression.h: Ditto. * EOAccess/EOUtilities.h: Ditto. * Tools/eoutil.m (dump): Implemented use of -postinstall option. Corrected bug when getting adaptor's expression class. Renamed symbol EOPrimaryKeyContraintsKey into EOPrimaryKeyConstraintsKey. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@16298 72102866-910b-0410-8b05-ffd578937521
2003-03-31 00:24:15 +00:00
#warning (Ayers 28-03-2003) Either remove this method from array or use EOMutableKnownKeyDictionary instead of self
return [[self newDictionaryFromDictionary: dict
subsetMapping: subsetMapping
zone: NULL] autorelease];
}
+ (id)newInstanceWithKeyCount: (unsigned int)keyCount
destinationDescription: (EOMKKDInitializer*)destination
zone: (NSZone*)zone
{
unsigned extraBytes = (keyCount > 0 ? (keyCount - 1) : 0) * sizeof(int);
EOMKKDArrayMapping *arrayMapping;
arrayMapping = (EOMKKDArrayMapping*)NSAllocateObject([EOMKKDArrayMapping class],
extraBytes,
zone);
[arrayMapping init];
ASSIGN(arrayMapping->_destinationDescription, destination);
memset(arrayMapping->_destinationOffsetForArrayIndex, 0,
extraBytes + sizeof(int));
return arrayMapping;
}
- (void) dealloc
{
DESTROY(_destinationDescription);
[super dealloc];
}
- (NSString*)description
{
NSString *dscr;
dscr = [NSString stringWithFormat: @"<%s %p >",
object_get_class_name(self),
(void*)self];
return dscr;
}
@end
@implementation EOMutableKnownKeyDictionary
2003-03-21 Manuel Guesdon <mguesdon@orange-concept.com> * EOAccess/EODatabaseContext.m: o added assert in _primaryKeyForObject: o in -recordChangesInEditingContext test nil/eonull on relationshipCommitedSnapshotValue and relationshipSnapshotValue instead of only nil testing o in -recordChangesInEditingContext fix for value changing testing when commitedSnapshotValue is nil/EONull * EOAccess/EOEntity.m: o logs o fix in inverseRelationshipClassPropertyNames to test on destination entity property names * EOControl/EOClassDescription.m: o logs * EOControl/GNUmakefile: o added EONSAddOns.h * EOCOntrol/EOKeyValueCoding.m: o fixes in NSArray -computeXXForKey: * EOAccess/EOSQLExpression.m: o assert in -sqlStringForKeyValueQualifier: o -sqlStringForArrayOfQualifiers:operation: hanlde different qualifier cases using isKindOfClass: may probably be improved o logs * EOControl/EOEditingContext.m: o fix in unprocessedInfo (invert/change swap). * EOControl/EOQualifier.m o -qualifierWithQualifierFormat:varargList: raise exception if operator is unknwon * EOControl/EOMutableKnownKeyDictionary.m: o add precision in exception message * EOAccess/EORelationship.m: o more info in some logs o fix in -_sourceRowToForeignKeyMapping for foreign keys which are not in primaryKey. * EOControl/EODatabaseOperation.m: o in -setDatabaseOperator: Don't Delete a not inserted object * EOControl/EOAccessFault.m: o logs o EOAccessFaultHandler: -dealloc fix: call super dealloc o implement faultWillFire: This fix a hard memory problem * EOControl/EOFault.m: o -dealloc: fix possible infinite loop o logs * EOCheapCopyArray.m: o ucomment retain/release/... o fix shallowCopy for memory management. This was causing hard memory trouble git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@16217 72102866-910b-0410-8b05-ffd578937521
2003-03-21 20:41:07 +00:00
+ (id)dictionaryFromDictionary: (NSDictionary *)dict
subsetMapping: (EOMKKDSubsetMapping *)subsetMapping
{
return [[self newDictionaryFromDictionary: dict
subsetMapping: subsetMapping
zone: NULL] autorelease];
}
+ (id)newDictionaryFromDictionary: (NSDictionary*)dict
subsetMapping: (EOMKKDSubsetMapping*)subsetMapping
zone: (NSZone*)zone
{
EOMutableKnownKeyDictionary *newDict = nil;
int objectsCount;
NSAssert(dict, @"No dictionary");
NSAssert(subsetMapping, @"No subsetMapping");
EOFLOGObjectLevelArgs(@"EOMKKD", @"dict=%@", dict);
EOFLOGObjectLevelArgs(@"EOMKKD", @"subsetMapping->_sourceDescription=%@",
subsetMapping->_sourceDescription);
EOFLOGObjectLevelArgs(@"EOMKKD", @"subsetMapping->_destinationDescription=%@",
subsetMapping->_destinationDescription);
objectsCount = [subsetMapping->_destinationDescription count];
EOFLOGObjectLevelArgs(@"EOMKKD", @"objectsCount=%d", objectsCount);
if (objectsCount > 0)
{
id objects[objectsCount];
int i;
for (i = 0; i < objectsCount; i++)
{
objects[i] = nil;
if (subsetMapping->_sourceOffsetForDestinationOffset[i] > 0)
{
int index = subsetMapping->_sourceOffsetForDestinationOffset[i] - 1;
EOFLOGObjectLevelArgs(@"EOMKKD", @"index=%d", index);
objects[i] = [subsetMapping->_sourceDescription
objectForIndex: index
dictionary: dict];
EOFLOGObjectLevelArgs(@"EOMKKD", @"objects[i]=%@", objects[i]);
NSAssert2(objects[i], @"No object for index %d from row %@",
index,
dict);
}
}
newDict = [self newWithInitializer: subsetMapping->_destinationDescription
objects: objects
zone: zone];
}
else
newDict = [self newWithInitializer: subsetMapping->_destinationDescription
zone: zone];
EOFLOGObjectLevel(@"EOMKKD", @"END");
return newDict;
}
+ (id)newDictionaryWithObjects: (id*)objects
arrayMapping: (id)mapping
zone: (NSZone*)zone
{
return [self notImplemented: _cmd];
}
+ (id)newWithInitializer: (EOMKKDInitializer*)initializer
objects: (id*)objects
zone: (NSZone*)zone
{
return [[self allocWithZone: zone] initWithInitializer: initializer
objects: objects];
}
+ (id)dictionaryWithObjects: (NSArray*)objects
forKeys: (NSArray*)keys
{
EOMutableKnownKeyDictionary *dict = nil;
int objectsCount = [objects count];
int keysCount = [keys count];
NSAssert2(objectsCount == keysCount,
@"Objects Count (%d) is not equal to keys Count (%d)",
objectsCount,
keysCount);
if (objectsCount > 0)
{
id objectIds[objectsCount];
id keyIds[keysCount];
[objects getObjects: objectIds];
[keys getObjects: keyIds];
dict = [[[self alloc] initWithObjects: objectIds
forKeys: keyIds
count: objectsCount] autorelease];
}
return dict;
}
+ (EOMKKDInitializer*)initializerFromKeyArray: (NSArray*)keys
{
return [EOMKKDInitializer initializerFromKeyArray: keys];
}
+ (id)newWithInitializer: (EOMKKDInitializer*)initializer
{
return [self newWithInitializer: initializer
zone: NULL];
}
+ (id)newWithInitializer: (EOMKKDInitializer*)initializer
zone: (NSZone*)zone
{
return [[self allocWithZone: zone] initWithInitializer: initializer];
}
+ (id) dictionaryWithInitializer: (EOMKKDInitializer*)initializer
{
return [[self newWithInitializer: initializer]autorelease];
}
- (id) initWithInitializer: (EOMKKDInitializer*)initializer
{
EOFLOGObjectFnStart();
if ((self = [self init]))
{
int count;
NSAssert(initializer, @"No Initializer");
EOFLOGObjectLevel(@"EOMKKD", @"suite");
ASSIGN(_MKKDInitializer, initializer);
count = [_MKKDInitializer count];
EOFLOGObjectLevelArgs(@"EOMKKD", @"count=%d", count);
_values = NSZoneMalloc([self zone], count * sizeof(id));
memset(_values, 0, count * sizeof(id));
}
EOFLOGObjectFnStop();
return self;
}
- (id) initWithInitializer: (EOMKKDInitializer*)initializer
objects: (id*)objects
{
EOFLOGObjectFnStart();
if ((self = [self initWithInitializer: initializer]))
{
EOFLOGObjectLevelArgs(@"EOMKKD", @"suite objects=%p initializer=%p",
objects, _MKKDInitializer);
if (objects)
{
int i;
int count = [_MKKDInitializer count];
EOFLOGObjectLevelArgs(@"EOMKKD", @"count=%d", count);
for (i = 0; i < count; i++)
{
EOFLOGObjectLevelArgs(@"EOMKKD", @"%d=%p (old=%p)",
i, objects[i], _values[i]);
ASSIGN(_values[i], objects[i]);
}
}
}
EOFLOGObjectLevel(@"EOMKKD", @"END");
return self;
}
// This is the designated initializer
- (id) initWithObjects: (id*)objects
forKeys: (id*)keys
count: (unsigned int)count
{
//OK
EOMKKDInitializer *initializer = nil;
EOFLOGObjectFnStart();
if (count > 0)
{
NSAssert(keys, @"No keys array");
NSAssert(count > 0, @"No keys");
initializer = [[[EOMKKDInitializer alloc] initWithKeys: keys
count: count] autorelease];
NSAssert(initializer, @"No Initializer");
EOFLOGObjectLevel(@"EOMKKD", @"suite");
ASSIGN(_MKKDInitializer, initializer);
_values = NSZoneMalloc([self zone], count * sizeof(id));
if (objects)
{
int i;
for (i = 0; i < count; i++)
{
ASSIGN(_values[i], objects[i]);
}
}
else
{
memset(_values, 0, count * sizeof(id));
}
}
return self;
}
- (void) dealloc
{
EOFLOGObjectLevelArgs(@"EOMKKD", @"Deallocate EOMKKDDictionary %p", self);
if (_values)
{
int i;
unsigned int count = [_MKKDInitializer count];
for (i = 0; i < count; i++)
{
DESTROY(_values[i]);
}
NSZoneFree([self zone], _values);
}
DESTROY(_MKKDInitializer);
DESTROY(_extraData);
[super dealloc];
}
- (unsigned int) count
{
NSAssert(_MKKDInitializer, @"No _MKKDInitializer");
return [_MKKDInitializer count];
}
- (id) objectForKey: (NSString*)key
{
id object = nil;
unsigned int index;
// EOFLOGObjectFnStart();
NSAssert(_MKKDInitializer, @"No _MKKDInitializer");
index = [_MKKDInitializer indexForKey: key];
// EOFLOGObjectLevelArgs(@"EOMKKD", @"index=%d", index);
if (index == NSNotFound)
{
if (_extraData)
object = [_extraData objectForKey: key];
}
else
{
NSAssert2(index < [_MKKDInitializer count], @"bad index %d (count=%u)",
index, [_MKKDInitializer count]);
object = _values[index];
}
// EOFLOGObjectLevelArgs(@"EOMKKD",@"object=%p",object);
// EOFLOGObjectFnStop();
return object;
}
- (void) setObject: (id)object
forKey: (NSString*)key
{
unsigned int index;
NSAssert(_MKKDInitializer, @"No _MKKDInitializer");
index = [_MKKDInitializer indexForKey: key];
if (index == NSNotFound)
{
if (!_extraData)
_extraData = [NSMutableDictionary new];
[_extraData setObject: object
forKey: key];
}
else
{
NSAssert2(index < [_MKKDInitializer count], @"bad index %d (count=%u)",
index, [_MKKDInitializer count]);
ASSIGN(_values[index], object);
}
}
- (void) removeObjectForKey: (NSString*)key
{
unsigned int index;
NSAssert(_MKKDInitializer, @"No _MKKDInitializer");
index = [_MKKDInitializer indexForKey: key];
if (index == NSNotFound)
{
if (_extraData)
[_extraData removeObjectForKey: key];
}
else
{
NSAssert2(index < [_MKKDInitializer count], @"bad index %d (count=%u)",
index, [_MKKDInitializer count]);
DESTROY(_values[index]);
}
}
- (BOOL) containsObjectsNotIdenticalTo: (id)object
{
BOOL result = NO;
int i;
unsigned int count = [_MKKDInitializer count];
for (i = 0; !result && i < count; i++)
{
if (_values[i] != object)
{
if (isNilOrEONull(_values[i]))
result =! isNilOrEONull(object);
else if (isNilOrEONull(object))
result = YES;
else
result = ![_values[i] isEqual: object];
}
}
EOFLOGObjectLevelArgs(@"EOMKKD", @"result = %s", (result ? "YES" : "NO"));
return result;
}
- (void)addEntriesFromDictionary: (NSDictionary*)dictionary
{
NSEnumerator *e = [dictionary keyEnumerator];
id key;
while ((key = [e nextObject]))
{
if (![self objectForKey: key]) //Don't overwrite already present values ?
{
[self setObject: [dictionary objectForKey: key]
forKey: key];
}
}
}
- (NSEnumerator*) keyEnumerator
{
EOMKKDKeyEnumerator *MKKDEnum;
MKKDEnum = [[[EOMKKDKeyEnumerator alloc] initWithTarget: self] autorelease];
return MKKDEnum;
}
- (EOMKKDInitializer*) eoMKKDInitializer
{
return _MKKDInitializer;
}
- (NSMutableDictionary*)extraData
{
return _extraData;
}
- (NSString*)debugDescription
{
NSString *dscr;
int i;
int count;
id *keys;
dscr = [NSString stringWithFormat: @"<%s %p - KV=",
object_get_class_name(self),
(void*)self];
count = [_MKKDInitializer count];
keys = [_MKKDInitializer keys];
for (i = 0; i < count; i++)
dscr = [dscr stringByAppendingFormat: @"%@=%@\n", keys[i], _values[i]];
dscr = [dscr stringByAppendingFormat: @"extraDatas:%@", _extraData];
dscr = [dscr stringByAppendingString: @">"];
return dscr;
}
- (BOOL)hasKey: (id)key
{
if ([_MKKDInitializer hasKey: key])
return YES;
else if ([_extraData objectForKey: key])
return YES;
else
return NO;
}
@end