home *** CD-ROM | disk | FTP | other *** search
- // EOQualifier.h
- // Copyright (c) 1994, NeXT Software, Inc. All rights reserved.
- //
- // Abstract Qualifier Class, qualifiers are not model specific and
- // have no reference to a model so that they may be generally applied
- // throughout the framework. EOQualifier methods that do need to
- // reference a model (such as SQL generation) must be able to access
- // a model through one of their parameters
- //
- // The following classes are offered:
- // EOQualifier - abstract superclass
- // EOKeyValueQualifier - e.g. "weight > 150"
- // EOAndQualifier - conjoin other qualifiers
- // EOOrQualifier
- // EONotQualifier
- // EOKeyComparisonQualifier - e.g. "name = wife.name
- // And in EOAccess:
- // EOSQLQualifier - for SQL to used in WHERE clause. Cannot
- // be applied to objects in memory
- //
- #import <Foundation/Foundation.h>
-
- @class EOClassDescription;
-
- @interface EOQualifier : NSObject <NSCopying>
- {
- }
-
- + (EOQualifier *)qualifierWithQualifierFormat:(NSString *)qualifierFormat, ...;
- // This factory method parses the qualifierFormat and creates an EOQualifier.
- // No verification is performed to insure the correctness of keys referred to
- // by the qualifier format string.
- //
- // This generates a tree of the basic qualifier types.
- // E.g. a format of "firstName = 'joe' AND department = %@" would
- // generate an EOAndQualifier with two sub EOKeyValueQualifiers.
- //
- // This method raises if format contains any syntax error.
-
- + (EOQualifier *)qualifierWithQualifierFormat:(NSString *)format arguments:(NSArray *)args;
-
- - (NSException *)validateKeysWithRootClassDescription:(EOClassDescription *)classDesc;
- // This method validates that a qualifier contains keys and key paths that
- // belong to or originate from classDesc. This method returns an exception if an
- // unknown key is found, otherwise it returns nil to indicate that the keys contained
- // by the qualifier are valid.
-
- + (NSString *)stringForOperatorSelector:(SEL)selector;
- + (SEL)operatorSelectorForString:(NSString *)string;
- // Used for parsing and printing of qualifiers
-
- @end
-
- //
- // All qualifiers that can be evaluated in memory implement this protocol
- //
- @protocol EOQualifierEvaluation
- - (BOOL)evaluateWithObject:object;
- // returns YES if argument satifies the qualifier, NO otherwise.
- @end
-
- // The following selectors are used when parsing an EOQualifier format.
- // The following methods correspond to the following operators: =, <=, <, >=, >,
- // !=, contains, and like.
- @interface NSObject (EORelationalSelectors)
- - (BOOL)isEqualTo:(id)object;
- // Implemented using isEqual:. Returns NO if receiever is nil.
- - (BOOL)isLessThanOrEqualTo:(id)object;
- // Implemented using compare. Returns NO if receiver is nil.
- - (BOOL)isLessThan:(id)object;
- // Implemented using compare. Returns NO if receiver is nil.
- - (BOOL)isGreaterThanOrEqualTo:(id)object;
- // Implemented using compare. Returns NO if receiver is nil.
- - (BOOL)isGreaterThan:(id)object;
- // Implemented using compare. Returns NO if receiver is nil.
- - (BOOL)isNotEqualTo:(id)object;
- // Implemented using compare. Returns NO if receiver is nil.
- - (BOOL)doesContain:(id)object;
- // Returns nil if receiver is not an NSArray or if array doesn't contain object.
- - (BOOL)isLike:(NSString *)object;
- // argument should be a string using simple shell wildcards (* and ?).
- // (e.g. "Stev*" or "N?XT").
- // Returns NO if receiver is not an NSString.
-
- @end
-
- //
- // Constants so users will get compiler warnings if they make a spelling error
- //
- #define EOQualifierOperatorEqual @selector(isEqualTo:)
- #define EOQualifierOperatorNotEqual @selector(isNotEqualTo:)
- #define EOQualifierOperatorLessThan @selector(isLessThan:)
- #define EOQualifierOperatorGreaterThan @selector(isGreaterThan:)
- #define EOQualifierOperatorLessThanOrEqualTo @selector(isLessThanOrEqualTo:)
- #define EOQualifierOperatorGreaterThanOrEqualTo @selector(isGreaterThanOrEqualTo:)
- #define EOQualifierOperatorContains @selector(doesContain:)
- #define EOQualifierOperatorLike @selector(isLike:)
-
- //
- // Comparison between the named property of an object and the supplied
- // value. When applying in memory, the EOKeyValueCoding protocol method
- // valueForKeyPath: is used to extract the value for comparison.
- // When used to generate SQL, the key should be a valid property name
- // of the root entity for the qualifier (or a valid attribute path).
- //
- @interface EOKeyValueQualifier:EOQualifier <EOQualifierEvaluation, NSCoding>
- {
- SEL _selector;
- NSString *_key;
- id _value;
- }
- - initWithKey:(NSString *)key operatorSelector:(SEL)selector value:(id)value;
- - (SEL)selector;
- - (NSString *)key;
- - (id)value;
- @end
-
- //
- // Comparison between the two named properties of an object.
- // When applying in memory, the EOKeyValueCoding protocol method
- // valueForKeyPath: is used to extract the values for comparison.
- // When used to generate SQL, the keys should be a valid property name
- // of the root entity for the qualifier (or a valid attribute path).
- //
- @interface EOKeyComparisonQualifier:EOQualifier <EOQualifierEvaluation, NSCoding>
- {
- SEL _selector;
- NSString *_leftKey;
- NSString *_rightKey;
- }
- - initWithLeftKey:(NSString *)leftKey operatorSelector:(SEL)selector rightKey:(id)rightKey;
- - (SEL)selector;
- - (NSString *)leftKey;
- - (NSString *)rightKey;
- @end
-
- //
- // Contains a number of qualifiers. When the evaluateWithObject: method is invoked
- // on this object it evaluates each of its qualifiers until one of them returns NO.
- // If one does return NO, then this qualifier will return NO immediately, otherwise
- // if all of the qualifiers return YES, this qualifier returns YES.
- //
- @interface EOAndQualifier : EOQualifier <EOQualifierEvaluation, NSCoding>
- {
- NSArray *_qualifiers;
- }
- - initWithQualifiers:(EOQualifier *)qualifiers, ...;
- - initWithQualifierArray:(NSArray *)array;
-
- - (NSArray *)qualifiers;
- @end
-
- //
- // Contains a number of qualifiers. When the evaluateWithObject: method is invoked
- // on this object it evaluates each of its qualifiers until one of them returns YES.
- // If one does return YES, then this qualifier will return YES immediately, otherwise
- // if all of the qualifiers return NO, this qualifier returns NO.
- //
- @interface EOOrQualifier:EOQualifier <EOQualifierEvaluation, NSCoding>
- {
- NSArray *_qualifiers;
- }
- - initWithQualifiers:(EOQualifier *)qualifiers, ...;
- - initWithQualifierArray:(NSArray *)array;
-
- - (NSArray *)qualifiers;
- @end
-
- //
- // Contains one qualifier. When this qualifier is evaluated it returns the inverse
- // of the result obtained by evaluating the contained qualifier.
- //
- @interface EONotQualifier:EOQualifier <EOQualifierEvaluation, NSCoding>
- {
- EOQualifier *_qualifier;
- }
- - initWithQualifier:(EOQualifier *)qualifier;
-
- - (EOQualifier *)qualifier;
- @end
-
- //
- // Convenience method to apply a qualifier in memory
- //
- @interface NSArray (EOQualifierExtras)
- - (NSArray *)filteredArrayUsingQualifier:(EOQualifier *)qualifier;
- @end
-