API  0.9.6
 All Classes Files Functions Variables Macros Groups Pages
CPExpression.j
Go to the documentation of this file.
1 /*
2  * CPExpression.j
3  *
4  * Created by cacaodev.
5  * Copyright 2010.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 
63 
77 @implementation CPExpression : CPObject
78 {
79  int _type;
80 }
81 
82 // Initializing an Expression
88 - (id)initWithExpressionType:(int)type
89 {
90  _type = type;
91 
92  return self;
93 }
94 
95 //Creating an Expression for a Value
101 + (CPExpression)expressionForConstantValue:(id)value
102 {
103  return [[_CPConstantValueExpression alloc] initWithValue:value];
104 }
105 
110 + (CPExpression)expressionForEvaluatedObject
111 {
112  return [_CPSelfExpression evaluatedObject];
113 }
114 
120 + (CPExpression)expressionForVariable:(CPString)string
121 {
122  return [[_CPVariableExpression alloc] initWithVariable:string];
123 }
124 
130 + (CPExpression)expressionForKeyPath:(CPString)keyPath
131 {
132  return [[_CPKeyPathExpression alloc] initWithKeyPath:keyPath];
133 }
134 
140 + (CPExpression)expressionForAggregate:(CPArray)collection
141 {
142  return [[_CPAggregateExpression alloc] initWithAggregate:collection];
143 }
144 
151 + (CPExpression)expressionForUnionSet:(CPExpression)left with:(CPExpression)right
152 {
153  return [[_CPSetExpression alloc] initWithType:CPUnionSetExpressionType left:left right:right];
154 }
155 
162 + (CPExpression)expressionForIntersectSet:(CPExpression)left with:(CPExpression)right
163 {
164  return [[_CPSetExpression alloc] initWithType:CPIntersectSetExpressionType left:left right:right];
165 }
166 
173 + (CPExpression)expressionForMinusSet:(CPExpression)left with:(CPExpression)right
174 {
175  return [[_CPSetExpression alloc] initWithType:CPMinusSetExpressionType left:left right:right];
176 }
177 
178 // Creating an Expression for a Function
226 + (CPExpression)expressionForFunction:(CPString)function_name arguments:(CPArray)parameters
227 {
228  return [[_CPFunctionExpression alloc] initWithSelector:CPSelectorFromString(function_name) arguments:parameters];
229 }
230 
240 + (CPExpression)expressionForFunction:(CPExpression)target selectorName:(CPString)selectorName arguments:(CPArray)parameters
241 {
242  return [[_CPFunctionExpression alloc] initWithTarget:target selector:CPSelectorFromString(selectorName) arguments:parameters];
243 }
244 
252 + (CPExpression)expressionForSubquery:(CPExpression)expression usingIteratorVariable:(CPString)variable predicate:(CPPredicate)predicate
253 {
254  return [[_CPSubqueryExpression alloc] initWithExpression:expression usingIteratorVariable:variable predicate:predicate];
255 }
256 
257 // Getting Information About an Expression
263 - (int)expressionType
264 {
265  return _type;
266 }
267 
273 - (id)constantValue
274 {
275  _CPRaiseInvalidAbstractInvocation(self, _cmd);
276  return nil;
277 }
278 
284 - (CPString)variable
285 {
286  _CPRaiseInvalidAbstractInvocation(self, _cmd);
287  return nil;
288 }
289 
295 - (CPString)keyPath
296 {
297  _CPRaiseInvalidAbstractInvocation(self, _cmd);
298  return nil;
299 }
300 
306 - (CPString)function
307 {
308  _CPRaiseInvalidAbstractInvocation(self, _cmd);
309  return nil;
310 }
311 
317 - (CPArray)arguments
318 {
319  _CPRaiseInvalidAbstractInvocation(self, _cmd);
320  return nil;
321 }
322 
328 - (id)collection
329 {
330  _CPRaiseInvalidAbstractInvocation(self, _cmd);
331  return nil;
332 }
333 
339 - (CPPredicate)predicate
340 {
341  _CPRaiseInvalidAbstractInvocation(self, _cmd);
342  return nil;
343 }
344 
350 - (CPExpression)operand
351 {
352  _CPRaiseInvalidAbstractInvocation(self, _cmd);
353  return nil;
354 }
355 
361 - (CPExpression)leftExpression
362 {
363  _CPRaiseInvalidAbstractInvocation(self, _cmd);
364  return nil;
365 }
366 
372 - (CPExpression)rightExpression
373 {
374  _CPRaiseInvalidAbstractInvocation(self, _cmd);
375  return nil;
376 }
377 
378 - (CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables
379 {
380  return self;
381 }
382 
383 @end
384