* EOControl/EOGenericRecord.h

* EOControl/EOGenericRecord.m
rename dictionary to _dictionary
fixed KVC.



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@30650 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Dave Wetzel 2010-06-10 10:40:43 +00:00
parent 4878a85bbe
commit 91c53d83dc
3 changed files with 36 additions and 330 deletions

View file

@ -1,3 +1,9 @@
2010-06-10 David Wetzel <dave@turbocat.de>
* EOControl/EOGenericRecord.h
* EOControl/EOGenericRecord.m
rename dictionary to _dictionary
fixed KVC.
2010-06-09 David Wetzel <dave@turbocat.de> 2010-06-09 David Wetzel <dave@turbocat.de>
* EOAccess/EOSQLExpression.m * EOAccess/EOSQLExpression.m
fix include for less warnings on mac fix include for less warnings on mac

View file

@ -48,7 +48,7 @@
@interface EOGenericRecord : EOCustomObject @interface EOGenericRecord : EOCustomObject
{ {
EOClassDescription *classDescription; EOClassDescription *classDescription;
EOMutableKnownKeyDictionary *dictionary; EOMutableKnownKeyDictionary *_dictionary;
} }
/* Initializing new instances. */ /* Initializing new instances. */

View file

@ -9,6 +9,8 @@
Author: Manuel Guesdon <mguesdon@orange-concept.com> Author: Manuel Guesdon <mguesdon@orange-concept.com>
Date: October 2000 Date: October 2000
Author: David Wetzel <dave@turbocat.de>
$Revision$ $Revision$
$Date$ $Date$
@ -143,9 +145,9 @@ static NSRecursiveLock *allGenericRecordsLock = nil;
// Ayers: Review // Ayers: Review
// We use entity dictionaryForProperties to avoid creation // We use entity dictionaryForProperties to avoid creation
//of new EOMKKDInitializer //of new EOMKKDInitializer
ASSIGN(dictionary,[classDescription dictionaryForInstanceProperties]); ASSIGN(_dictionary,[classDescription dictionaryForInstanceProperties]);
EOFLOGObjectLevelArgs(@"EOGenericRecord", @"Record %p: dictionary=%@", EOFLOGObjectLevelArgs(@"EOGenericRecord", @"Record %p: dictionary=%@",
self, dictionary); self, _dictionary);
}; };
- (id) init - (id) init
@ -188,12 +190,12 @@ static NSRecursiveLock *allGenericRecordsLock = nil;
{ {
EOFLOGObjectLevelArgs(@"EOGenericRecord", EOFLOGObjectLevelArgs(@"EOGenericRecord",
@"Deallocate EOGenericRecord %p (dict=%p)", @"Deallocate EOGenericRecord %p (dict=%p)",
self, dictionary); self, _dictionary);
[[self class] removeDestroyedObject: self]; [[self class] removeDestroyedObject: self];
DESTROY(classDescription); DESTROY(classDescription);
DESTROY(dictionary); DESTROY(_dictionary);
[super dealloc]; [super dealloc];
} }
@ -234,12 +236,12 @@ static const char _c_id[2] = { _C_ID, 0 };
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC", EOFLOGObjectLevelArgs(@"EOGenericRecordKVC",
@"dictionary: %p eoMKKDInitializer: %p", @"dictionary: %p eoMKKDInitializer: %p",
dictionary, _dictionary,
[dictionary eoMKKDInitializer]); [_dictionary eoMKKDInitializer]);
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC", @"dictionary allkeys= %@", EOFLOGObjectLevelArgs(@"EOGenericRecordKVC", @"dictionary allkeys= %@",
[dictionary allKeys]); [_dictionary allKeys]);
if (EOMKKD_hasKeyWithImpPtr(dictionary,NULL,name)) if (EOMKKD_hasKeyWithImpPtr(_dictionary,NULL,name))
{ {
if (type) if (type)
*type = _c_id; *type = _c_id;
@ -277,7 +279,7 @@ static const char _c_id[2] = { _C_ID, 0 };
if (offset == INT_MAX) if (offset == INT_MAX)
{ {
value = EOMKKD_objectForKeyWithImpPtr(dictionary,NULL,aKey); value = EOMKKD_objectForKeyWithImpPtr(_dictionary,NULL,aKey);
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC", @"value %p (class=%@)", EOFLOGObjectLevelArgs(@"EOGenericRecordKVC", @"value %p (class=%@)",
value, [value class]); value, [value class]);
@ -310,9 +312,9 @@ static const char _c_id[2] = { _C_ID, 0 };
if (offset == INT_MAX) if (offset == INT_MAX)
{ {
if (anObject) if (anObject)
EOMKKD_setObjectForKeyWithImpPtr(dictionary,NULL,anObject,aKey); EOMKKD_setObjectForKeyWithImpPtr(_dictionary,NULL,anObject,aKey);
else else
EOMKKD_removeObjectForKeyWithImpPtr(dictionary,NULL,aKey); EOMKKD_removeObjectForKeyWithImpPtr(_dictionary,NULL,aKey);
} }
else else
GSObjCSetVal(self, [aKey UTF8String], anObject, sel, type, size, offset); GSObjCSetVal(self, [aKey UTF8String], anObject, sel, type, size, offset);
@ -761,321 +763,19 @@ inline BOOL infoForInstanceVariableWithImpPtr(id object,GDL2IMP_BOOL* impPtr,
} }
//MG#if !FOUNDATION_HAS_KVC /* Invoked by valueForKey: when it finds no property corresponding to a given key.
- (void) takeValue: (id)anObject forKey: (NSString*)aKey */
- (id)valueForUndefinedKey:(NSString *)key
{ {
SEL sel; return [_dictionary objectForKey:key];
const char *type;
unsigned size;
int off=0;
size = [aKey length];
if (size < 1)
{
[NSException raise: NSInvalidArgumentException
format: @"takeValue:forKey: ... empty key"];
}
else
{
char buf[size+6];
char lo;
char hi;
GDL2IMP_BOOL rtsIMP=NULL;
GDL2IMP_BOOL infoVarIMP=NULL;
// We'll call willChange if we modify ivar directly or call a _setMethod
// otherwise, the setMethod should do it
BOOL shouldCallWillChange=NO; //OXYMIUM
strcpy(buf, "_set");
[aKey getCString: &buf[4]];
lo = buf[4];
hi = toupper(lo);
buf[4] = hi;
buf[size+4] = ':';
buf[size+5] = '\0';
type = NULL;
//Try setKey:
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC",
@"A aKey=%@ Method [setKey:] name=%s",
aKey, &buf[1]);
sel = GSSelectorFromName(&buf[1]);
if (sel == 0 || GDL2_RespondsToSelectorWithImpPtr(self,&rtsIMP,sel) == NO)
{
// Try _setKey:
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC",
@"B aKey=%@ Method [_setKey:] name=%s",
aKey, buf);
sel = GSSelectorFromName(buf);
if (sel != 0 &&
GDL2_RespondsToSelectorWithImpPtr(self,&rtsIMP,sel) == YES)
{
shouldCallWillChange=YES;
}
else
{
sel = 0;
if ([[self class] accessInstanceVariablesDirectly] == YES)
{
// test _key
buf[size+4] = '\0';
buf[3] = '_';
buf[4] = lo;
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC",
@"C aKey=%@ Instance [_key] name=%s",
aKey, &buf[3]);
/*if ([self _infoForInstanceVariableNamed: &buf[3]
stringName: nil
retType: &type
retSize: &size
retOffset: &off]==NO)*/
if (infoForInstanceVariableWithImpPtr(self,&infoVarIMP,
&buf[3], // name
nil, // stringName
&type, // retType
&size, // retSize
&off)==YES) // retOffset
{
// We'll call willChange
shouldCallWillChange=YES;
}
else
{
// Test key
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC",
@"D aKey=%@ Instance [key] name=%s",
aKey, &buf[4]);
/*[self _infoForInstanceVariableNamed: &buf[4]
stringName: aKey
retType: &type
retSize: &size
retOffset: &off];*/
infoForInstanceVariableWithImpPtr(self,&infoVarIMP,
&buf[4], // name
aKey, // stringName
&type, // retType
&size, // retSize
&off); // retOffset
// We'll call willChange
shouldCallWillChange=YES;
}
}
}
}
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC",
@"aKey=%@ sel=%@ offset=%u shouldCallWillChange=%d",
aKey, NSStringFromSelector(sel), off,
shouldCallWillChange);
if (shouldCallWillChange)
[self willChange];
[self _setValueForKey: aKey
object: anObject
selector: sel
type: type
size: size
offset: off];
};
} }
- (id) valueForKey: (NSString*)aKey - (void)setValue:(id)value forUndefinedKey:(NSString *)key
{ {
SEL sel = 0; [_dictionary setObject:value
const char *type = NULL; forKey:key];
unsigned size;
int off = 0;
id value = nil;
size = [aKey length];
if (size < 1)
{
[NSException raise: NSInvalidArgumentException
format: @"valueForKey: ... empty key"];
}
else
{
char buf[size+5];
char lo;
char hi;
GDL2IMP_BOOL rtsIMP=NULL;
GDL2IMP_BOOL infoVarIMP=NULL;
strcpy(buf, "_get");
[aKey getCString: &buf[4]];
lo = buf[4];
hi = toupper(lo);
buf[4] = hi;
// Test getKey
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC", @"A aKey=%@ Method [getKey] name=%s",
aKey, &buf[1]);
sel = GSSelectorFromName(&buf[1]);
if (sel == 0 ||
GDL2_RespondsToSelectorWithImpPtr(self,&rtsIMP,sel) == NO)
{
//Test key
buf[4] = lo;
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC",
@"B aKey=%@ Method [key] name=%s",
aKey, &buf[4]);
sel = GSSelectorFromName(&buf[4]);
if (sel == 0 ||
GDL2_RespondsToSelectorWithImpPtr(self,&rtsIMP,sel) == NO)
{
//Test _getKey
buf[4] = hi;
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC",
@"C aKey=%@ Method [_getKey] name=%s",
aKey, buf);
sel = GSSelectorFromName(buf);
if (sel == 0 ||
GDL2_RespondsToSelectorWithImpPtr(self,&rtsIMP,sel) == NO)
{
// Test _key
buf[3] = '_';
buf[4] = lo;
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC",
@"C aKey=%@ Method [_key] name=%s",
aKey, &buf[3]);
sel = GSSelectorFromName(&buf[3]);
if (sel == 0 ||
GDL2_RespondsToSelectorWithImpPtr(self,&rtsIMP,sel) == NO)
{
sel = 0;
}
}
}
}
if (sel == 0 && [[self class] accessInstanceVariablesDirectly] == YES)
{
// Test _key
buf[3] = '_';
buf[4] = lo;
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC",
@"D aKey=%@ Instance [_key] name=%s",
aKey, &buf[3]);
/*if ([self _infoForInstanceVariableNamed: &buf[3]
stringName: nil
retType: &type
retSize: &size
retOffset: &off]==NO)*/
if (infoForInstanceVariableWithImpPtr(self,&infoVarIMP,
&buf[3], // name
nil, // stringName
&type, // retType
&size, // retSize
&off)==NO) // retOffset
{
// Test key
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC",
@"E aKey=%@ Instance [key] name=%s",
aKey, &buf[4]);
/*[self _infoForInstanceVariableNamed: &buf[4]
stringName: aKey
retType: &type
retSize: &size
retOffset: &off];*/
infoForInstanceVariableWithImpPtr(self,&infoVarIMP,
&buf[4], // name
aKey, // stringName
&type, // retType
&size, // retSize
&off); // retOffset
}
}
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC",
@"aKey=%@ sel=%@ offset=%u",
aKey, NSStringFromSelector(sel), off);
value = [self _getValueForKey: aKey
selector: sel
type: type
size: size
offset: off];
};
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC", @"value: %p (class=%@)",
value, [value class]);
return value;
} }
//MG#else /* FOUNDATION_HAS_KVC */
/*
- (id) handleQueryWithUnboundKey: (NSString *)key
{
id value;
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC",
@"Unbound key named %@",
key);
if (![dictionary hasKey: key])
return [super handleQueryWithUnboundKey: key];
value = [dictionary objectForKey: key];
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC", @"value %p (class=%@)",
value, [value class]);
return value;
}
- (void) handleTakeValue: (id)value forUnboundKey: (NSString *)key
{
EOFLOGObjectLevelArgs(@"EOGenericRecordKVC",
@"Unbound key named %@",
key);
[self willChange];
if (![dictionary hasKey:key])
[super handleTakeValue:value forUnboundKey: key];
if (value)
[dictionary setObject: value
forKey: key];
else
// [dictionary setObject: GDL2_EONull
// forKey: key];
[dictionary removeObjectForKey: key];
}
*/
//MG#endif /* FOUNDATION_HAS_KVC */
/** used in -decription for self toOne or toMany objects to avoid /** used in -decription for self toOne or toMany objects to avoid
infinite loop in description **/ infinite loop in description **/
@ -1083,7 +783,7 @@ infinite loop in description **/
{ {
NSArray *toManyKeys = nil; NSArray *toManyKeys = nil;
NSArray *toOneKeys = nil; NSArray *toOneKeys = nil;
NSEnumerator *enumerator = [dictionary keyEnumerator]; NSEnumerator *enumerator = [_dictionary keyEnumerator];
NSMutableDictionary *dict; NSMutableDictionary *dict;
NSString *key = nil; NSString *key = nil;
id obj = nil; id obj = nil;
@ -1093,11 +793,11 @@ infinite loop in description **/
toManyKeys = [classDescription toManyRelationshipKeys]; toManyKeys = [classDescription toManyRelationshipKeys];
toOneKeys = [classDescription toOneRelationshipKeys]; toOneKeys = [classDescription toOneRelationshipKeys];
dict = [NSMutableDictionary dictionaryWithCapacity: [dictionary count]]; dict = [NSMutableDictionary dictionaryWithCapacity: [_dictionary count]];
while ((key = GDL2_NextObjectWithImpPtr(enumerator,&enumNO))) while ((key = GDL2_NextObjectWithImpPtr(enumerator,&enumNO)))
{ {
obj = EOMKKD_objectForKeyWithImpPtr(dictionary,&ofkIMP,key); obj = EOMKKD_objectForKeyWithImpPtr(_dictionary,&ofkIMP,key);
if (!obj) if (!obj)
GDL2_SetObjectForKeyWithImpPtr(dict,&dictSOFK,@"(null)",key); GDL2_SetObjectForKeyWithImpPtr(dict,&dictSOFK,@"(null)",key);
else else
@ -1122,7 +822,7 @@ infinite loop in description **/
{ {
NSArray *toManyKeys = nil; NSArray *toManyKeys = nil;
NSArray *toOneKeys = nil; NSArray *toOneKeys = nil;
NSEnumerator *enumerator = [dictionary keyEnumerator]; NSEnumerator *enumerator = [_dictionary keyEnumerator];
NSMutableDictionary *dict; NSMutableDictionary *dict;
NSString *key = nil; NSString *key = nil;
id obj = nil; id obj = nil;
@ -1133,11 +833,11 @@ infinite loop in description **/
toManyKeys = [classDescription toManyRelationshipKeys]; toManyKeys = [classDescription toManyRelationshipKeys];
toOneKeys = [classDescription toOneRelationshipKeys]; toOneKeys = [classDescription toOneRelationshipKeys];
dict = [NSMutableDictionary dictionaryWithCapacity: [dictionary count]]; dict = [NSMutableDictionary dictionaryWithCapacity: [_dictionary count]];
while ((key = GDL2_NextObjectWithImpPtr(enumerator,&enumNO))) while ((key = GDL2_NextObjectWithImpPtr(enumerator,&enumNO)))
{ {
obj = EOMKKD_objectForKeyWithImpPtr(dictionary,&ofkIMP,key); obj = EOMKKD_objectForKeyWithImpPtr(_dictionary,&ofkIMP,key);
if (!obj) if (!obj)
GDL2_SetObjectForKeyWithImpPtr(dict,&dictSOFK,@"(null)",key); GDL2_SetObjectForKeyWithImpPtr(dict,&dictSOFK,@"(null)",key);
@ -1211,7 +911,7 @@ infinite loop in description **/
//debug only //debug only
- (NSString *)debugDictionaryDescription - (NSString *)debugDictionaryDescription
{ {
return [dictionary debugDescription]; return [_dictionary debugDescription];
} }
/** should returns an array of property names to exclude from entity /** should returns an array of property names to exclude from entity
@ -1224,7 +924,7 @@ You can override this to exclude properties manually handled by derived object *
return nil; return nil;
}; };
/*dictionary has following entries: /*_dictionary has following entries:
- NSMutableDictionary* processed: processed entries (key=object address, value=size) - NSMutableDictionary* processed: processed entries (key=object address, value=size)
- NSMutableDictionary* summaryNb: objects by class name (key=class name, value=number of objects) - NSMutableDictionary* summaryNb: objects by class name (key=class name, value=number of objects)
- NSMutableDictionary* summarySize: objects by class name (key=class name, value=size) - NSMutableDictionary* summarySize: objects by class name (key=class name, value=size)
@ -1327,7 +1027,7 @@ You can override this to exclude properties manually handled by derived object *
[(NSMutableArray *)props addObjectsFromArray: [(NSMutableArray *)props addObjectsFromArray:
[classDescription toManyRelationshipKeys]]; [classDescription toManyRelationshipKeys]];
size += [self eoGetSize]; size += [self eoGetSize];
size += [dictionary eoGetSize]; size += [_dictionary eoGetSize];
//NSDebugMLog(@"props=%@",props); //NSDebugMLog(@"props=%@",props);