mirror of
https://github.com/gnustep/libs-gdl2.git
synced 2025-04-23 05:00:46 +00:00
* EOControl/EOAndQualifier.m: Added documentation.
([EOAndQualifier +qualifierWithQualifiers:]), ([EOAndQualifier -initWithQualifiers:]): Synchronize implementation. ([EOAndQualifier -initWithQualifierArray:]): Change ASSIGN to ASSIGNCOPY when setting qualifier array (insuring immutability). ([EOAndQualifier -copyWithZone:]): remove (use implementation from superclass). * EOControl/EOKeyComparisonQualifier.m: Added documentation. ([EOKeyComparisonQualifier +qualifierWithLeftKey:operatorSelector:rightKey:]): Use AUTORELEASE() instead of -autorelease. ([EOKeyComparisonQualifier -initWithLeftKey:operatorSelector:rightKey:]): Use ASSIGNCOPY instead of ASSIGN to insure immutable keys. Added comment about possible selector assertion. ([EOKeyComparisonQualifier -copyWithZone:]): remove (use implementation from superclass). ([EOKeyComparisonQualifier -evaluateWithObject:]): Try to call the receivers selector before attempting to fallback on other mechanisms to evaluate the object. Adjusted local variable names and fixed fallback Equal, NotEqual and Contains comparisons. ([EOKeyComparisonQualifier -description]): Fall back to NSStringFromSelector() if +stringForOperatorSelector returns nil. * EOControl/EOKeyValueQualifier.m: Added documentation ([EOKeyValueQualifier +qualifierWithKey:operatorSelector:value:]): Use AUTORELEASE() instead of -autorelease. ([EOKeyValueQualifier -initWithKey:operatorSelector:value:]): Use ASSIGNCOPY instead of ASSIGN to insure immutable key. Added comment about possible selector assertion. ([EOKeyValueQualifier -copyWithZone:]): remove (use implementation from superclass). ([EOKeyValueQualifier -evaluateWithObject:]): Try to call the receivers selector before attempting to fallback on other mechanisms to evaluate the object. Adjusted local variable names and fixed fallback Equal, NotEqual and Contains comparisons. ([EOKeyValueQualifier -description]): Fall back to NSStringFromSelector() if +stringForOperatorSelector returns nil. * EOControl/EONotQualifier.m: Added documentation. ([EONotQualifier -copyWithZone:]): remove (use implementation from superclass). ([EONotQualifier -evaluateWithObject:]): Implemented. * EOControl/EOOrQualifier.m: Added documentation. ([EOOrQualifier +qualifierWithQualifiers:]), ([EOORQualifier -initWithQualifiers:]): Synchronize implementation. ([EOOrQualifier -copyWithZone:]): remove (use implementation from superclass). ([EOOrQualifier -evaluateWithObject:]): Corrected implementation. * EOControl/EOQualifier.m: Added documentation ([EOQualifier +initialize]), (getKey()): Replace autorelease with AUTORELEASE(). ([EOQualifier -copyWithZone:]): RETAIN() instead of NSCopyObject(). ([EOQualifier +variableWithKey:]): Corrected implementation. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@15952 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
63fe01e58e
commit
ee408db764
7 changed files with 390 additions and 173 deletions
60
ChangeLog
60
ChangeLog
|
@ -1,3 +1,63 @@
|
|||
2003-02-13 David Ayers <d.ayers@inode.at>
|
||||
|
||||
* EOControl/EOAndQualifier.m: Added documentation.
|
||||
([EOAndQualifier +qualifierWithQualifiers:]),
|
||||
([EOAndQualifier -initWithQualifiers:]): Synchronize implementation.
|
||||
([EOAndQualifier -initWithQualifierArray:]): Change ASSIGN to
|
||||
ASSIGNCOPY when setting qualifier array (insuring immutability).
|
||||
([EOAndQualifier -copyWithZone:]): remove (use implementation from
|
||||
superclass).
|
||||
|
||||
* EOControl/EOKeyComparisonQualifier.m: Added documentation.
|
||||
([EOKeyComparisonQualifier
|
||||
+qualifierWithLeftKey:operatorSelector:rightKey:]): Use
|
||||
AUTORELEASE() instead of -autorelease.
|
||||
([EOKeyComparisonQualifier
|
||||
-initWithLeftKey:operatorSelector:rightKey:]): Use ASSIGNCOPY
|
||||
instead of ASSIGN to insure immutable keys. Added comment about
|
||||
possible selector assertion.
|
||||
([EOKeyComparisonQualifier -copyWithZone:]): remove (use
|
||||
implementation from superclass).
|
||||
([EOKeyComparisonQualifier -evaluateWithObject:]): Try to call the
|
||||
receivers selector before attempting to fallback on other
|
||||
mechanisms to evaluate the object. Adjusted local variable names
|
||||
and fixed fallback Equal, NotEqual and Contains comparisons.
|
||||
([EOKeyComparisonQualifier -description]): Fall back to
|
||||
NSStringFromSelector() if +stringForOperatorSelector returns nil.
|
||||
|
||||
* EOControl/EOKeyValueQualifier.m: Added documentation
|
||||
([EOKeyValueQualifier +qualifierWithKey:operatorSelector:value:]): Use
|
||||
AUTORELEASE() instead of -autorelease.
|
||||
([EOKeyValueQualifier -initWithKey:operatorSelector:value:]): Use
|
||||
ASSIGNCOPY instead of ASSIGN to insure immutable key. Added
|
||||
comment about possible selector assertion.
|
||||
([EOKeyValueQualifier -copyWithZone:]): remove (use implementation
|
||||
from superclass).
|
||||
([EOKeyValueQualifier -evaluateWithObject:]): Try to call the
|
||||
receivers selector before attempting to fallback on other
|
||||
mechanisms to evaluate the object. Adjusted local variable names
|
||||
and fixed fallback Equal, NotEqual and Contains comparisons.
|
||||
([EOKeyValueQualifier -description]): Fall back to
|
||||
NSStringFromSelector() if +stringForOperatorSelector returns nil.
|
||||
|
||||
* EOControl/EONotQualifier.m: Added documentation.
|
||||
([EONotQualifier -copyWithZone:]): remove (use implementation from
|
||||
superclass).
|
||||
([EONotQualifier -evaluateWithObject:]): Implemented.
|
||||
|
||||
* EOControl/EOOrQualifier.m: Added documentation.
|
||||
([EOOrQualifier +qualifierWithQualifiers:]),
|
||||
([EOORQualifier -initWithQualifiers:]): Synchronize implementation.
|
||||
([EOOrQualifier -copyWithZone:]): remove (use implementation from
|
||||
superclass).
|
||||
([EOOrQualifier -evaluateWithObject:]): Corrected implementation.
|
||||
|
||||
* EOControl/EOQualifier.m: Added documentation
|
||||
([EOQualifier +initialize]), (getKey()): Replace autorelease with
|
||||
AUTORELEASE().
|
||||
([EOQualifier -copyWithZone:]): RETAIN() instead of NSCopyObject().
|
||||
([EOQualifier +variableWithKey:]): Corrected implementation.
|
||||
|
||||
2003-02-06 David Ayers <d.ayers@inode.at>
|
||||
|
||||
* EOAccess/EOModel.m
|
||||
|
|
|
@ -49,12 +49,21 @@ RCS_ID("$Id$")
|
|||
|
||||
@implementation EOAndQualifier
|
||||
|
||||
+ (EOQualifier *)qualifierWithQualifierArray: (NSArray *)array
|
||||
/**
|
||||
* Returns an autoreleased EOAndQualifier consisting of the provided array of
|
||||
* qualifiers. This method calls [EOAndQualifier-initWithQualifierArray:].
|
||||
*/
|
||||
+ (EOQualifier *) qualifierWithQualifierArray: (NSArray *)array
|
||||
{
|
||||
return AUTORELEASE([[self alloc] initWithQualifierArray: array]);
|
||||
}
|
||||
|
||||
+ (EOQualifier *)qualifierWithQualifiers: (EOQualifier *)qualifiers, ...
|
||||
/**
|
||||
* Returns an autoreleased EOAndQualifier consisting of the provided
|
||||
* nil terminated list of qualifiers. This method calls
|
||||
* [EOAndQualifier-initWithQualifierArray:].
|
||||
*/
|
||||
+ (EOQualifier *) qualifierWithQualifiers: (EOQualifier *)qualifiers, ...
|
||||
{
|
||||
NSMutableArray *qualArray = [NSMutableArray array];
|
||||
EOQualifier *tmpId;
|
||||
|
@ -62,10 +71,9 @@ RCS_ID("$Id$")
|
|||
|
||||
va_start(ap, qualifiers);
|
||||
|
||||
for (tmpId = qualifiers; tmpId != nil;)
|
||||
for (tmpId = qualifiers; tmpId != nil; tmpId = va_arg(ap, id))
|
||||
{
|
||||
[qualArray addObject: tmpId];
|
||||
tmpId = va_arg(ap, id);
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
|
@ -73,6 +81,11 @@ RCS_ID("$Id$")
|
|||
return AUTORELEASE([[self alloc] initWithQualifierArray: qualArray]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the receiver with the provided
|
||||
* nil terminated list of qualifiers. This method calls
|
||||
* [EOAndQualifier-initWithQualifierArray:].
|
||||
*/
|
||||
- (id) initWithQualifiers: (EOQualifier *)qualifiers, ...
|
||||
{
|
||||
NSMutableArray *qualArray = [NSMutableArray array];
|
||||
|
@ -81,10 +94,9 @@ RCS_ID("$Id$")
|
|||
|
||||
va_start(ap, qualifiers);
|
||||
|
||||
for (tmpId = qualifiers; tmpId != nil;)
|
||||
for (tmpId = qualifiers; tmpId != nil; tmpId = va_arg(ap, id))
|
||||
{
|
||||
[qualArray addObject: tmpId];
|
||||
tmpId = va_arg(ap, id);
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
|
@ -92,11 +104,14 @@ RCS_ID("$Id$")
|
|||
return [self initWithQualifierArray: qualArray];
|
||||
}
|
||||
|
||||
/** <init />
|
||||
* Initializes the receiver with the provided array of qualifiers.
|
||||
*/
|
||||
- (id) initWithQualifierArray: (NSArray *)array
|
||||
{
|
||||
if ((self = [self init]))
|
||||
{
|
||||
ASSIGN(_qualifiers, array);
|
||||
ASSIGNCOPY(_qualifiers, array);
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -109,20 +124,20 @@ RCS_ID("$Id$")
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the recievers array of qualifiers.
|
||||
*/
|
||||
- (NSArray *)qualifiers
|
||||
{
|
||||
return _qualifiers;
|
||||
}
|
||||
|
||||
- (id)copyWithZone: (NSZone *)zone
|
||||
{
|
||||
EOAndQualifier *qual = [[EOAndQualifier allocWithZone: zone] init];
|
||||
|
||||
qual->_qualifiers = [_qualifiers copyWithZone: zone];
|
||||
|
||||
return qual;
|
||||
}
|
||||
|
||||
/**
|
||||
* EOQualifierEvaluation protocol
|
||||
* Returns YES if all of the receivers qualifiers return YES to
|
||||
* [EOQualifierEvaluation-evaluateWithObjects:] with object. This method
|
||||
* returns NO as soon as the first qualifier retuns NO.
|
||||
*/
|
||||
- (BOOL)evaluateWithObject: (id)object
|
||||
{
|
||||
NSEnumerator *qualifiersEnum;
|
||||
|
|
|
@ -47,24 +47,40 @@ RCS_ID("$Id$")
|
|||
|
||||
@implementation EOKeyComparisonQualifier
|
||||
|
||||
+ (EOQualifier *)qualifierWithLeftKey: (NSString *)leftKey
|
||||
operatorSelector: (SEL)selector
|
||||
rightKey: (id)rightKey
|
||||
/**
|
||||
* Returns an autoreleased EOKeyComparisonQualifier using leftKey, selector
|
||||
* and right key. The selector should take a single id as an argument and
|
||||
* return a BOOL value. This method calls
|
||||
* [EOKeyComparisonQualifier-initWithLeftKey:operatorSelectot:rightKey:].
|
||||
*/
|
||||
+ (EOQualifier *) qualifierWithLeftKey: (NSString *)leftKey
|
||||
operatorSelector: (SEL)selector
|
||||
rightKey: (id)rightKey
|
||||
{
|
||||
return [[[self alloc] initWithLeftKey: leftKey
|
||||
operatorSelector: selector
|
||||
rightKey: rightKey] autorelease];
|
||||
return AUTORELEASE([[self alloc] initWithLeftKey: leftKey
|
||||
operatorSelector: selector
|
||||
rightKey: rightKey]);
|
||||
}
|
||||
|
||||
- initWithLeftKey: (NSString *)leftKey
|
||||
operatorSelector: (SEL)selector
|
||||
rightKey: (id)rightKey
|
||||
/** <init />
|
||||
* Initializes the receiver with a copy of leftKey, selector and a copy of
|
||||
* rightKey. The selector should take a single id as an argument and return a
|
||||
* BOOL value.
|
||||
*/
|
||||
- (id) initWithLeftKey: (NSString *)leftKey
|
||||
operatorSelector: (SEL)selector
|
||||
rightKey: (id)rightKey
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
/*Ayers (09-02-2002): Maybe we should assert the correct signature
|
||||
but we currently don't have the object which should implement it.
|
||||
Assertion during evaluation (i.e. when we have an object) could be
|
||||
too expensive.*/
|
||||
|
||||
_selector = selector;
|
||||
ASSIGN(_leftKey, leftKey);
|
||||
ASSIGN(_rightKey, rightKey);
|
||||
ASSIGNCOPY(_leftKey, leftKey);
|
||||
ASSIGNCOPY(_rightKey, rightKey);
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -78,94 +94,140 @@ RCS_ID("$Id$")
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
- (SEL)selector
|
||||
/**
|
||||
* Returns the selector used by the receiver during in-memory evaluation.
|
||||
* The selector should take a single id as an argument and return a BOOL value.
|
||||
* (More docs to follow for EOQualifierSQLGeneration.)
|
||||
*/
|
||||
- (SEL) selector
|
||||
{
|
||||
return _selector;
|
||||
}
|
||||
|
||||
- (NSString *)leftKey
|
||||
/**
|
||||
* Returns the key with which the receiver obtains the left value during
|
||||
* in-memory evaluation. (More docs to follow for EOQualifierSQLGeneration.)
|
||||
*/
|
||||
- (NSString *) leftKey
|
||||
{
|
||||
return _leftKey;
|
||||
}
|
||||
|
||||
- (NSString *)rightKey
|
||||
/**
|
||||
* Returns the key with which the receiver obtains the right value during
|
||||
* in-memory evaluation. (More docs to follow for EOQualifierSQLGeneration.)
|
||||
*/
|
||||
- (NSString *) rightKey
|
||||
{
|
||||
return _rightKey;
|
||||
}
|
||||
|
||||
- (id)copyWithZone: (NSZone *)zone
|
||||
/**
|
||||
* EOQualifierEvaluation protocol<br/>
|
||||
* Evaluates the object according to the receivers definition. First the left
|
||||
* value is obtained by invoking valueForKey: on the provided object with the
|
||||
* receivers leftKey and the right value by invoking valueForKey: with the
|
||||
* recievers rightKey. If the left value implements the receivers selector,
|
||||
* this method returns the return value of the invocation of this method with
|
||||
* the right value as the parameter.<br/>
|
||||
* If the left object doesn't implement the receivers selector, but the
|
||||
* selector of the reciever is one of:<br/>
|
||||
+ <list>
|
||||
* EOQualifierOperatorEqual
|
||||
* EOQualifierOperatorNotEqual
|
||||
* EOQualifierOperatorLessThan
|
||||
* EOQualifierOperatorGreaterThan
|
||||
* EOQualifierOperatorLessThanOrEqual
|
||||
* EOQualifierOperatorGreaterThanOrEqual
|
||||
* EOQualifierOperatorContains
|
||||
* EOQualifierOperatorLike
|
||||
* EOQualifierOperatorCaseInsensitiveLike
|
||||
* </list>
|
||||
* then GDL2 tries to evaluate the qualifier by invoking
|
||||
* isEqual:, compare:, rangeOfString: respectively and interpreting the
|
||||
* results accoring to the selector. In the case of
|
||||
* EOQualifierOperatorCaseInsensitiveLike, the values are converted using
|
||||
* uppercaseString for evaluation.<br/>
|
||||
* Both 'Like' fallback implementations are currently implemented by using
|
||||
* isEqual: and do not yet take the ? and * wildcards into account.<br/>
|
||||
* If the receivers selector is neither implemented by the left value nor
|
||||
* corresponds to one of the EOQualifierOperators, this method simply
|
||||
* returns NO.
|
||||
*/
|
||||
- (BOOL) evaluateWithObject: (id)object
|
||||
{
|
||||
EOKeyComparisonQualifier *qual = [[EOKeyComparisonQualifier
|
||||
allocWithZone: zone] init];
|
||||
id leftVal, rightVal;
|
||||
BOOL (*imp)(id, SEL, id);
|
||||
|
||||
qual->_selector = _selector;
|
||||
qual->_leftKey = [_leftKey copyWithZone: zone];
|
||||
qual->_rightKey = [_rightKey copyWithZone: zone];
|
||||
|
||||
return qual;
|
||||
}
|
||||
|
||||
- (BOOL)evaluateWithObject: (id)object
|
||||
{
|
||||
id leftKey, rightKey;
|
||||
|
||||
leftKey = [object valueForKey: _leftKey];
|
||||
rightKey = [object valueForKey: _rightKey];
|
||||
leftVal = [object valueForKey: _leftKey];
|
||||
rightVal = [object valueForKey: _rightKey];
|
||||
|
||||
imp = (BOOL (*)(id, SEL, id))[leftVal methodForSelector: _selector];
|
||||
if (imp != NULL)
|
||||
{
|
||||
return (*imp) (leftVal, _selector, rightVal);
|
||||
}
|
||||
if (sel_eq(_selector, EOQualifierOperatorEqual) == YES)
|
||||
{
|
||||
return [leftKey isEqual: rightKey] == NSOrderedSame;
|
||||
return [leftVal isEqual: rightVal];
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorNotEqual) == YES)
|
||||
{
|
||||
return [leftKey isEqual: rightKey] != NSOrderedSame;
|
||||
return ([leftVal isEqual: rightVal]?NO:YES);
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorLessThan) == YES)
|
||||
{
|
||||
return [(NSObject *)leftKey compare: rightKey] == NSOrderedAscending;
|
||||
return [leftVal compare: rightVal] == NSOrderedAscending;
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorGreaterThan) == YES)
|
||||
{
|
||||
return [(NSObject *)leftKey compare: rightKey] == NSOrderedDescending;
|
||||
return [leftVal compare: rightVal] == NSOrderedDescending;
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorLessThanOrEqualTo) == YES)
|
||||
{
|
||||
return [(NSObject *)leftKey compare: rightKey] != NSOrderedDescending;
|
||||
return [leftVal compare: rightVal] != NSOrderedDescending;
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorGreaterThanOrEqualTo) == YES)
|
||||
{
|
||||
return [(NSObject *)leftKey compare: rightKey] != NSOrderedAscending;
|
||||
return [leftVal compare: rightVal] != NSOrderedAscending;
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorContains) == YES)
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
|
||||
return NO;
|
||||
return [leftVal rangeOfString: rightVal].location != NSNotFound;
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorLike) == YES)
|
||||
{
|
||||
NSEmitTODO(); //TODO
|
||||
return [leftKey isEqual: rightKey]
|
||||
return [leftVal isEqual: rightVal]
|
||||
== NSOrderedSame;
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorCaseInsensitiveLike) == YES)
|
||||
{
|
||||
NSEmitTODO(); //TODO
|
||||
return [[leftKey uppercaseString] isEqual: [rightKey uppercaseString]]
|
||||
return [[leftVal uppercaseString] isEqual: [rightVal uppercaseString]]
|
||||
== NSOrderedSame;
|
||||
}
|
||||
|
||||
/*Ayers (09-02-2002): Maybe we should raise instead of returning NO.*/
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
/**
|
||||
* Returns a human readable representation of the receiver.
|
||||
*/
|
||||
- (NSString *) description
|
||||
{
|
||||
return [NSString stringWithFormat:@"<%s %p - %@ %@ %@>",
|
||||
object_get_class_name(self),
|
||||
(void*)self,
|
||||
_leftKey,
|
||||
[isa stringForOperatorSelector:_selector],
|
||||
_rightKey];
|
||||
NSString *selectorString;
|
||||
selectorString = [isa stringForOperatorSelector: _selector];
|
||||
if (selectorString == nil)
|
||||
{
|
||||
selectorString = NSStringFromSelector(_selector);
|
||||
}
|
||||
return [NSString stringWithFormat:@"<%s %p - %@ %@ %@>",
|
||||
object_get_class_name(self),
|
||||
(void*)self,
|
||||
_leftKey,
|
||||
selectorString,
|
||||
_rightKey];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -50,31 +50,45 @@ RCS_ID("$Id$")
|
|||
|
||||
@implementation EOKeyValueQualifier
|
||||
|
||||
+ (EOKeyValueQualifier *)qualifierWithKey: (NSString *)key
|
||||
operatorSelector: (SEL)selector
|
||||
value: (id)value
|
||||
/**
|
||||
* Returns an autoreleased EOKeyValueQualifier using key, selector and value.
|
||||
* The selector should take a single id as an argument an return a BOOL value.
|
||||
* This method calls [EOKeyValueQualifier-initWithKey:operatorSelectot:value:].
|
||||
*/
|
||||
+ (EOKeyValueQualifier *) qualifierWithKey: (NSString *)key
|
||||
operatorSelector: (SEL)selector
|
||||
value: (id)value
|
||||
{
|
||||
return [[[self alloc] initWithKey: key
|
||||
operatorSelector: selector
|
||||
value: value] autorelease];
|
||||
return AUTORELEASE([[self alloc] initWithKey: key
|
||||
operatorSelector: selector
|
||||
value: value]);
|
||||
}
|
||||
|
||||
- initWithKey: (NSString *)key
|
||||
operatorSelector: (SEL)selector
|
||||
value: (id)value
|
||||
/** <init />
|
||||
* Initializes the receiver with a copy of leftKey, selector and a copy of
|
||||
* rightKey. The selector should take a single id as an argument an return a
|
||||
* BOOL value.
|
||||
*/
|
||||
- (id) initWithKey: (NSString *)key
|
||||
operatorSelector: (SEL)selector
|
||||
value: (id)value
|
||||
{
|
||||
//OK
|
||||
if ((self = [super init]))
|
||||
{
|
||||
/*Ayers (09-02-2002): Maybe we should assert the correct signature
|
||||
but we currently don't have the object which should implement it.
|
||||
Assertion during evaluation (i.e. when we have an object) could be
|
||||
too expensive.*/
|
||||
|
||||
_selector = selector;
|
||||
ASSIGN(_key, key);
|
||||
ASSIGNCOPY(_key, key);
|
||||
ASSIGN(_value, value);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
- (void) dealloc
|
||||
{
|
||||
DESTROY(_key);
|
||||
DESTROY(_value);
|
||||
|
@ -82,101 +96,138 @@ operatorSelector: (SEL)selector
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
- (SEL)selector
|
||||
/**
|
||||
* Returns the selector used by the receiver during in-memory evaluation.
|
||||
* The selector should take a single id as an argument an return a BOOL value.
|
||||
* (More docs to follow for EOQualifierSQLGeneration.)
|
||||
*/
|
||||
- (SEL) selector
|
||||
{
|
||||
return _selector;
|
||||
}
|
||||
|
||||
- (NSString *)key
|
||||
/**
|
||||
* Returns the key with which the receiver obtains the value to compare with
|
||||
* receivers value during in-memory evaluation. (More docs to follow for
|
||||
* EOQualifierSQLGeneration.)
|
||||
*/
|
||||
- (NSString *) key
|
||||
{
|
||||
return _key;
|
||||
}
|
||||
|
||||
- (id)value
|
||||
/**
|
||||
* Returns the value with which the receiver compares the value obtained from
|
||||
* the provided object during in-memory evaluation. (More docs to follow for
|
||||
* EOQualifierSQLGeneration.)
|
||||
*/
|
||||
- (id) value
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
- (id)copyWithZone: (NSZone *)zone
|
||||
/**
|
||||
* EOQualifierEvaluation protocol<br/>
|
||||
* Evaluates the object according to the receivers definition. First the
|
||||
* provided objects value object is obtained by invoking valueForKey: on it
|
||||
* with the receivers key. If the value object implements the receivers
|
||||
* selector, this method returns the return value of the invocation of this
|
||||
* method with the receivers value as the parameter.<br/>
|
||||
* If the value object doesn't implement the receivers selector, but the
|
||||
* selector of the reciever is one of:<br/>
|
||||
+ <list>
|
||||
* EOQualifierOperatorEqual
|
||||
* EOQualifierOperatorNotEqual
|
||||
* EOQualifierOperatorLessThan
|
||||
* EOQualifierOperatorGreaterThan
|
||||
* EOQualifierOperatorLessThanOrEqual
|
||||
* EOQualifierOperatorGreaterThanOrEqual
|
||||
* EOQualifierOperatorContains
|
||||
* EOQualifierOperatorLike
|
||||
* EOQualifierOperatorCaseInsensitiveLike
|
||||
* </list>
|
||||
* then GDL2 tries to evaluate the qualifier by invoking
|
||||
* isEqual:, compare:, rangeOfString: respectively and interpreting the
|
||||
* results accoring to the selector. In the case of
|
||||
* EOQualifierOperatorCaseInsensitiveLike, the values are converted using
|
||||
* uppercaseString for evaluation.<br/>
|
||||
* Both 'Like' fallback implementations are currently implemented by using
|
||||
* isEqual: and do not yet take the ? and * wildcards into account.<br/>
|
||||
* If the receivers selector is neither implemented by the left value nor
|
||||
* corresponds to one of the EOQualifierOperators, this method simply
|
||||
* returns NO.
|
||||
*/
|
||||
- (BOOL) evaluateWithObject: (id)object
|
||||
{
|
||||
EOKeyValueQualifier *qual = [[EOKeyValueQualifier allocWithZone: zone] init];
|
||||
id val;
|
||||
BOOL (*imp)(id, SEL, id);
|
||||
|
||||
qual->_selector = _selector;
|
||||
ASSIGN(qual->_key, _key); //Don't copy it [_key copyWithZone:zone];
|
||||
ASSIGN(qual->_value, _value); //Don't copy it: if this is a generic record, it isn't copyable [_value copyWithZone:zone];
|
||||
|
||||
return qual;
|
||||
}
|
||||
|
||||
- (BOOL)evaluateWithObject: (id)object
|
||||
{
|
||||
id key;
|
||||
|
||||
key = [object valueForKey: _key];
|
||||
val = [object valueForKey: _key];
|
||||
|
||||
imp = (BOOL (*)(id, SEL, id))[val methodForSelector: _selector];
|
||||
if (imp != NULL)
|
||||
{
|
||||
return (*imp) (val, _selector, _value);
|
||||
}
|
||||
if (sel_eq(_selector, EOQualifierOperatorEqual) == YES)
|
||||
{
|
||||
return [(NSString *)key compare: _value] == NSOrderedSame;
|
||||
return [val isEqual: _value];
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorNotEqual) == YES)
|
||||
{
|
||||
return [(NSString *)key compare: _value] != NSOrderedSame;
|
||||
return ([val isEqual: _value]?NO:YES);
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorLessThan) == YES)
|
||||
{
|
||||
return [(NSString *)key compare: _value] == NSOrderedAscending;
|
||||
return [val compare: _value] == NSOrderedAscending;
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorGreaterThan) == YES)
|
||||
{
|
||||
return [(NSString *)key compare: _value] == NSOrderedDescending;
|
||||
return [val compare: _value] == NSOrderedDescending;
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorLessThanOrEqualTo) == YES)
|
||||
{
|
||||
return [(NSString *)key compare: _value] != NSOrderedDescending;
|
||||
return [val compare: _value] != NSOrderedDescending;
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorGreaterThanOrEqualTo) == YES)
|
||||
{
|
||||
return [(NSString *)key compare: _value] != NSOrderedAscending;
|
||||
return [val compare: _value] != NSOrderedAscending;
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorContains) == YES)
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return [val rangeOfString: _value].location != NSNotFound;
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorLike) == YES)
|
||||
{
|
||||
NSEmitTODO(); //TODO
|
||||
return [key isEqual: _value] == NSOrderedSame;
|
||||
return [val isEqual: _value] == NSOrderedSame;
|
||||
}
|
||||
else if (sel_eq(_selector, EOQualifierOperatorCaseInsensitiveLike) == YES)
|
||||
{
|
||||
NSEmitTODO(); //TODO
|
||||
return [[key uppercaseString] isEqual: [_value uppercaseString]]
|
||||
return [[val uppercaseString] isEqual: [_value uppercaseString]]
|
||||
== NSOrderedSame;
|
||||
}
|
||||
|
||||
/*Ayers (09-02-2002): Maybe we should raise instead of returning NO.*/
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
/**
|
||||
* Returns a human readable representation of the receiver.
|
||||
*/
|
||||
- (NSString *) description
|
||||
{
|
||||
/* //TODO revoir
|
||||
NSString *dscr=nil;
|
||||
int i=0;
|
||||
dscr = [NSString stringWithFormat:@"<%s %p - %@ %@ (%@)%@>",
|
||||
object_get_class_name(self),
|
||||
(void*)self,
|
||||
_key,
|
||||
NSStringFromSelector(_selector),
|
||||
NSStringFromClass([_value class]),
|
||||
_value];
|
||||
return dscr;
|
||||
*/
|
||||
|
||||
NSString *selectorString;
|
||||
selectorString = [isa stringForOperatorSelector: _selector];
|
||||
if (selectorString == nil)
|
||||
{
|
||||
selectorString = NSStringFromSelector(_selector);
|
||||
}
|
||||
return [NSString stringWithFormat:@"<%s %p - %@ %@ (%@)'%@'>",
|
||||
object_get_class_name(self),
|
||||
(void*)self,
|
||||
_key,
|
||||
[isa stringForOperatorSelector:_selector],
|
||||
selectorString,
|
||||
NSStringFromClass([_value class]),
|
||||
_value];
|
||||
}
|
||||
|
|
|
@ -44,11 +44,18 @@ RCS_ID("$Id$")
|
|||
|
||||
@implementation EONotQualifier
|
||||
|
||||
/**
|
||||
* Returns an autoreleased EONotQualifier referencing qualifiers. This method
|
||||
* calls [EONotQualifier-initWithQualifier:].
|
||||
*/
|
||||
+ (EOQualifier *)qualifierWithQualifier: (EOQualifier *)qualifier
|
||||
{
|
||||
return [[[self alloc] initWithQualifier: qualifier] autorelease];
|
||||
}
|
||||
|
||||
/** <init />
|
||||
* Initializes the receiver with the provided qualifier.
|
||||
*/
|
||||
- initWithQualifier: (EOQualifier *)qualifier
|
||||
{
|
||||
self = [super init];
|
||||
|
@ -58,25 +65,23 @@ RCS_ID("$Id$")
|
|||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the qualifier the reciever negates.
|
||||
*/
|
||||
- (EOQualifier *)qualifier
|
||||
{
|
||||
return _qualifier;
|
||||
}
|
||||
|
||||
- (id)copyWithZone: (NSZone *)zone
|
||||
{
|
||||
EONotQualifier *qual = [[EONotQualifier alloc] init];
|
||||
|
||||
qual->_qualifier = [_qualifier copyWithZone: zone];
|
||||
|
||||
return qual;
|
||||
}
|
||||
|
||||
/**
|
||||
* EOQualifierEvaluation protocol
|
||||
* Returns YES if qualifier the receivers refernces returns NO on
|
||||
* [EOQualifierEvaluation-evaluateWithObjects:] with object. Returns NO
|
||||
* otherwise.
|
||||
*/
|
||||
- (BOOL)evaluateWithObject: (id)object
|
||||
{
|
||||
//TODO
|
||||
[self notImplemented: _cmd];
|
||||
return NO;
|
||||
return ([_qualifier evaluateWithObject: object] ? NO : YES);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -47,12 +47,21 @@ RCS_ID("$Id$")
|
|||
|
||||
@implementation EOOrQualifier
|
||||
|
||||
+ (EOQualifier *)qualifierWithQualifierArray: (NSArray *)array
|
||||
/**
|
||||
* Returns an autoreleased EOAndQualifier consisting of the provided array of
|
||||
* qualifiers. This method calls [EOOrQualifier-initWithQualifierArray:].
|
||||
*/
|
||||
+ (EOQualifier *) qualifierWithQualifierArray: (NSArray *)array
|
||||
{
|
||||
return [[[self alloc] initWithQualifierArray: array] autorelease];
|
||||
}
|
||||
|
||||
+ (EOQualifier *)qualifierWithQualifiers: (EOQualifier *)qualifiers, ...
|
||||
/**
|
||||
* Returns an autoreleased EOAndQualifier consisting of the provided
|
||||
* nil terminated list of qualifiers. This method calls
|
||||
* [EOOrQualifier-initWithQualifierArray:].
|
||||
*/
|
||||
+ (EOQualifier *) qualifierWithQualifiers: (EOQualifier *)qualifiers, ...
|
||||
{
|
||||
NSMutableArray *qualArray = [NSMutableArray array];
|
||||
EOQualifier *tmpId;
|
||||
|
@ -60,41 +69,43 @@ RCS_ID("$Id$")
|
|||
|
||||
va_start(ap, qualifiers);
|
||||
|
||||
for (tmpId = qualifiers; tmpId != nil;)
|
||||
for (tmpId = qualifiers; tmpId != nil; tmpId = va_arg(ap, id))
|
||||
{
|
||||
[qualArray addObject: tmpId];
|
||||
tmpId = va_arg(ap, id);
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
|
||||
return [[[self alloc] initWithQualifierArray: qualArray] autorelease];
|
||||
return AUTORELEASE([[self alloc] initWithQualifierArray: qualArray]);
|
||||
}
|
||||
|
||||
- initWithQualifiers: (EOQualifier *)qualifiers, ...
|
||||
/**
|
||||
* Initializes the receiver with the provided
|
||||
* nil terminated list of qualifiers. This method calls
|
||||
* [EOOrQualifier-initWithQualifierArray:].
|
||||
*/
|
||||
- (id) initWithQualifiers: (EOQualifier *)qualifiers, ...
|
||||
{
|
||||
if ((self = [super init]))
|
||||
NSMutableArray *qualArray = [NSMutableArray array];
|
||||
EOQualifier *tmpId;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, qualifiers);
|
||||
|
||||
for (tmpId = qualifiers; tmpId != nil; tmpId = va_arg(ap, id))
|
||||
{
|
||||
va_list ap;
|
||||
id tmpId;
|
||||
NSMutableArray *qualArray = [NSMutableArray array];
|
||||
|
||||
va_start(ap, qualifiers);
|
||||
|
||||
[qualArray addObject: qualifiers];
|
||||
|
||||
for (tmpId = va_arg(ap, id); tmpId != nil; tmpId = va_arg(ap, id))
|
||||
[qualArray addObject: va_arg(ap, id)];
|
||||
|
||||
va_end(ap);
|
||||
|
||||
ASSIGN(_qualifiers, qualArray);
|
||||
[qualArray addObject: tmpId];
|
||||
}
|
||||
|
||||
return self;
|
||||
va_end(ap);
|
||||
|
||||
return [self initWithQualifierArray: qualArray];
|
||||
}
|
||||
|
||||
- initWithQualifierArray: (NSArray *)array
|
||||
/** <init />
|
||||
* Initializes the receiver with the provided array of qualifiers.
|
||||
*/
|
||||
- (id) initWithQualifierArray: (NSArray *)array
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
|
@ -104,28 +115,28 @@ RCS_ID("$Id$")
|
|||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
- (void) dealloc
|
||||
{
|
||||
DESTROY(_qualifiers);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSArray *)qualifiers
|
||||
/**
|
||||
* Returns the recievers array of qualifiers.
|
||||
*/
|
||||
- (NSArray *) qualifiers
|
||||
{
|
||||
return _qualifiers;
|
||||
}
|
||||
|
||||
- (id)copyWithZone: (NSZone *)zone
|
||||
{
|
||||
EOOrQualifier *qual = [[EOOrQualifier allocWithZone: zone] init];
|
||||
|
||||
qual->_qualifiers = [_qualifiers copyWithZone: zone];
|
||||
|
||||
return qual;
|
||||
}
|
||||
|
||||
- (BOOL)evaluateWithObject: (id)object
|
||||
/**
|
||||
* EOQualifierEvaluation protocol
|
||||
* Returns NO if all of the receivers qualifiers return NO to
|
||||
* [EOQualifierEvaluation-evaluateWithObjects:] with object. This method
|
||||
* returns YES as soon as the first qualifier retuns YES.
|
||||
*/
|
||||
- (BOOL) evaluateWithObject: (id)object
|
||||
{
|
||||
NSEnumerator *qualifiersEnum;
|
||||
EOQualifier *qualifier;
|
||||
|
@ -133,11 +144,11 @@ RCS_ID("$Id$")
|
|||
qualifiersEnum = [_qualifiers objectEnumerator];
|
||||
while ((qualifier = [qualifiersEnum nextObject]))
|
||||
{
|
||||
if ([qualifier evaluateWithObject: object] == NO)
|
||||
return NO;
|
||||
if ([qualifier evaluateWithObject: object] == YES)
|
||||
return YES;
|
||||
}
|
||||
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (id) qualifierMigratedFromEntity: (id)param0
|
||||
|
|
|
@ -81,6 +81,10 @@ RCS_ID("$Id$")
|
|||
|
||||
@implementation EOQualifier
|
||||
|
||||
/**
|
||||
* Returns an autoreleased qualifier which is constructed by calling
|
||||
* [EOQualifier+qualifierWithQualifierFormat:varargList:]
|
||||
*/
|
||||
+ (EOQualifier *)qualifierWithQualifierFormat: (NSString *)qualifierFormat, ...
|
||||
{
|
||||
EOQualifier *qualifier = nil;
|
||||
|
@ -335,7 +339,8 @@ static id getKey(const char **cFormat, const char **s, BOOL *isKeyValue,
|
|||
|
||||
if (classString)
|
||||
{
|
||||
key = [[[NSClassFromString(classString) alloc] initWithString: key] autorelease];
|
||||
key = AUTORELEASE([[NSClassFromString(classString) alloc]
|
||||
initWithString: key]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -503,7 +508,8 @@ static Class whichQualifier(const char **cFormat, const char **s)
|
|||
if (qualifierArray != nil)
|
||||
{
|
||||
[qualifierArray addObject:qualifier];
|
||||
qualifier = AUTORELEASE([[qualifierClass alloc] initWithQualifierArray:qualifierArray]);
|
||||
qualifier = AUTORELEASE([[qualifierClass alloc]
|
||||
initWithQualifierArray: qualifierArray]);
|
||||
qualifierArray = nil;
|
||||
}
|
||||
|
||||
|
@ -710,9 +716,16 @@ static Class whichQualifier(const char **cFormat, const char **s)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NSCopying protocol
|
||||
* EOQualifiers are immutable. Returns the receiver after retaining it.<br\>
|
||||
* If you wish to gain memory locality, you should recrate the qualifier
|
||||
* from scratch insuring that all referenced objects are also local to the new
|
||||
* zone.
|
||||
*/
|
||||
- (id)copyWithZone: (NSZone *)zone
|
||||
{
|
||||
return NSCopyObject(self, 0, zone);
|
||||
return RETAIN(self);
|
||||
}
|
||||
|
||||
- (EOQualifier *)qualifierByApplyingBindings: (id)bindings
|
||||
|
@ -786,7 +799,7 @@ static Class whichQualifier(const char **cFormat, const char **s)
|
|||
|
||||
+ (EOQualifierVariable *)variableWithKey: (NSString *)key
|
||||
{
|
||||
return [EOQualifierVariable variableWithKey: key];
|
||||
return AUTORELEASE([[self alloc] initWithKey: key]);
|
||||
}
|
||||
|
||||
- (EOQualifierVariable *)initWithKey: (NSString *)key
|
||||
|
|
Loading…
Reference in a new issue