home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / EODEV.Z / EOQualifier.h < prev    next >
Encoding:
Text File  |  1996-09-11  |  6.9 KB  |  188 lines

  1. // EOQualifier.h
  2. // Copyright (c) 1994, NeXT Software, Inc. All rights reserved.
  3. //
  4. // Abstract Qualifier Class, qualifiers are not model specific and
  5. // have no reference to a model so that they may be generally applied
  6. // throughout the framework. EOQualifier methods that do need to
  7. // reference a model (such as SQL generation) must be able to access
  8. // a model through one of their parameters
  9. //
  10. // The following classes are offered:
  11. //   EOQualifier             - abstract superclass
  12. //     EOKeyValueQualifier    - e.g. "weight > 150"
  13. //     EOAndQualifier           - conjoin other qualifiers
  14. //     EOOrQualifier
  15. //     EONotQualifier
  16. //     EOKeyComparisonQualifier    - e.g. "name = wife.name
  17. // And in EOAccess:
  18. //     EOSQLQualifier           - for SQL to used in WHERE clause.  Cannot
  19. //                                be applied to objects in memory
  20. //
  21. #import <Foundation/Foundation.h>
  22.  
  23. @class EOClassDescription;
  24.  
  25. @interface EOQualifier : NSObject <NSCopying>
  26. {
  27. }
  28.  
  29. + (EOQualifier *)qualifierWithQualifierFormat:(NSString *)qualifierFormat, ...;
  30.     // This factory method parses the qualifierFormat and creates an EOQualifier.
  31.     // No verification is performed to insure the correctness of keys referred to
  32.     // by the qualifier format string.
  33.     //
  34.     // This generates a tree of the basic qualifier types.
  35.     // E.g. a format of "firstName = 'joe' AND department = %@" would
  36.     // generate an EOAndQualifier with two sub EOKeyValueQualifiers.
  37.     //
  38.     // This method raises if format contains any syntax error.
  39.  
  40. + (EOQualifier *)qualifierWithQualifierFormat:(NSString *)format arguments:(NSArray *)args;
  41.  
  42. - (NSException *)validateKeysWithRootClassDescription:(EOClassDescription *)classDesc;
  43.     // This method validates that a qualifier contains keys and key paths that
  44.     // belong to or originate from classDesc. This method returns an exception if an
  45.     // unknown key is found, otherwise it returns nil to indicate that the keys contained
  46.     // by the qualifier are valid.
  47.  
  48. + (NSString *)stringForOperatorSelector:(SEL)selector;
  49. + (SEL)operatorSelectorForString:(NSString *)string;
  50.     // Used for parsing and printing of qualifiers
  51.  
  52. @end
  53.  
  54. //
  55. // All qualifiers that can be evaluated in memory implement this protocol
  56. //
  57. @protocol EOQualifierEvaluation
  58. - (BOOL)evaluateWithObject:object;
  59.     // returns YES if argument satifies the qualifier, NO otherwise.
  60. @end
  61.  
  62. // The following selectors are used when parsing an EOQualifier format.
  63. // The following methods correspond to the following operators: =, <=, <, >=, >,
  64. // !=, contains, and like.
  65. @interface NSObject (EORelationalSelectors)
  66. - (BOOL)isEqualTo:(id)object;
  67.     // Implemented using isEqual:. Returns NO if receiever is nil.
  68. - (BOOL)isLessThanOrEqualTo:(id)object;
  69.     // Implemented using compare. Returns NO if receiver is nil.
  70. - (BOOL)isLessThan:(id)object;
  71.     // Implemented using compare. Returns NO if receiver is nil.
  72. - (BOOL)isGreaterThanOrEqualTo:(id)object;
  73.     // Implemented using compare. Returns NO if receiver is nil.
  74. - (BOOL)isGreaterThan:(id)object;
  75.     // Implemented using compare. Returns NO if receiver is nil.
  76. - (BOOL)isNotEqualTo:(id)object;
  77.     // Implemented using compare. Returns NO if receiver is nil.
  78. - (BOOL)doesContain:(id)object;
  79.     // Returns nil if receiver is not an NSArray or if array doesn't contain object.
  80. - (BOOL)isLike:(NSString *)object;
  81.     // argument should be a string using simple shell wildcards (* and ?).
  82.     // (e.g. "Stev*" or "N?XT").
  83.     // Returns NO if receiver is not an NSString.
  84.  
  85. @end
  86.  
  87. //
  88. // Constants so users will get compiler warnings if they make a spelling error
  89. //
  90. #define EOQualifierOperatorEqual @selector(isEqualTo:)
  91. #define EOQualifierOperatorNotEqual @selector(isNotEqualTo:)
  92. #define EOQualifierOperatorLessThan @selector(isLessThan:)
  93. #define EOQualifierOperatorGreaterThan @selector(isGreaterThan:)
  94. #define EOQualifierOperatorLessThanOrEqualTo @selector(isLessThanOrEqualTo:)
  95. #define EOQualifierOperatorGreaterThanOrEqualTo @selector(isGreaterThanOrEqualTo:)
  96. #define EOQualifierOperatorContains @selector(doesContain:)
  97. #define EOQualifierOperatorLike @selector(isLike:)
  98.  
  99. //
  100. // Comparison between the named property of an object and the supplied
  101. // value.  When applying in memory, the EOKeyValueCoding protocol method
  102. // valueForKeyPath: is used to extract the value for comparison.
  103. // When used to generate SQL, the key should be a valid property name
  104. // of the root entity for the qualifier (or a valid attribute path).
  105. //
  106. @interface EOKeyValueQualifier:EOQualifier <EOQualifierEvaluation, NSCoding> 
  107. {
  108.    SEL _selector;
  109.    NSString *_key;
  110.    id _value;
  111. }
  112. - initWithKey:(NSString *)key operatorSelector:(SEL)selector value:(id)value;
  113. - (SEL)selector;
  114. - (NSString *)key;
  115. - (id)value;
  116. @end
  117.  
  118. //
  119. // Comparison between the two named properties of an object.
  120. // When applying in memory, the EOKeyValueCoding protocol method
  121. // valueForKeyPath: is used to extract the values for comparison.
  122. // When used to generate SQL, the keys should be a valid property name
  123. // of the root entity for the qualifier (or a valid attribute path).
  124. //
  125. @interface EOKeyComparisonQualifier:EOQualifier <EOQualifierEvaluation, NSCoding>
  126. {
  127.     SEL _selector;
  128.     NSString *_leftKey;
  129.     NSString *_rightKey;
  130. }
  131. - initWithLeftKey:(NSString *)leftKey operatorSelector:(SEL)selector rightKey:(id)rightKey;
  132. - (SEL)selector;
  133. - (NSString *)leftKey;
  134. - (NSString *)rightKey;
  135. @end
  136.  
  137. //
  138. // Contains a number of qualifiers. When the evaluateWithObject: method is invoked
  139. // on this object it evaluates each of its qualifiers until one of them returns NO.
  140. // If one does return NO, then this qualifier will return NO immediately, otherwise
  141. // if all of the qualifiers return YES, this qualifier returns YES.
  142. //
  143. @interface EOAndQualifier : EOQualifier <EOQualifierEvaluation, NSCoding> 
  144. {
  145.     NSArray *_qualifiers;
  146. }
  147. - initWithQualifiers:(EOQualifier *)qualifiers, ...;
  148. - initWithQualifierArray:(NSArray *)array;
  149.  
  150. - (NSArray *)qualifiers;
  151. @end
  152.  
  153. //
  154. // Contains a number of qualifiers. When the evaluateWithObject: method is invoked
  155. // on this object it evaluates each of its qualifiers until one of them returns YES.
  156. // If one does return YES, then this qualifier will return YES immediately, otherwise
  157. // if all of the qualifiers return NO, this qualifier returns NO.
  158. //
  159. @interface EOOrQualifier:EOQualifier <EOQualifierEvaluation, NSCoding>
  160. {
  161.     NSArray *_qualifiers;
  162. }
  163. - initWithQualifiers:(EOQualifier *)qualifiers, ...;
  164. - initWithQualifierArray:(NSArray *)array;
  165.  
  166. - (NSArray *)qualifiers;
  167. @end
  168.  
  169. //
  170. // Contains one qualifier. When this qualifier is evaluated it returns the inverse
  171. // of the result obtained by evaluating the contained qualifier.
  172. //
  173. @interface EONotQualifier:EOQualifier <EOQualifierEvaluation, NSCoding>
  174. {
  175.     EOQualifier *_qualifier;
  176. }
  177. - initWithQualifier:(EOQualifier *)qualifier;
  178.  
  179. - (EOQualifier *)qualifier;
  180. @end
  181.  
  182. //
  183. // Convenience method to apply a qualifier in memory
  184. //
  185. @interface NSArray (EOQualifierExtras)
  186. - (NSArray *)filteredArrayUsingQualifier:(EOQualifier *)qualifier;
  187. @end
  188.