![]() |
API 0.9.5
|
00001 /* 00002 * CPExpression.j 00003 * 00004 * Created by cacaodev. 00005 * Copyright 2010. 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 00026 CPConstantValueExpressionType = 0; 00030 CPEvaluatedObjectExpressionType = 1; 00034 CPVariableExpressionType = 2; 00038 CPKeyPathExpressionType = 3; 00042 CPFunctionExpressionType = 4; 00046 CPAggregateExpressionType = 5; 00050 CPSubqueryExpressionType = 6; 00054 CPUnionSetExpressionType = 7; 00058 CPIntersectSetExpressionType = 8; 00062 CPMinusSetExpressionType = 9; 00063 00077 @implementation CPExpression : CPObject 00078 { 00079 int _type; 00080 } 00081 00082 // Initializing an Expression 00088 - (id)initWithExpressionType:(int)type 00089 { 00090 _type = type; 00091 00092 return self; 00093 } 00094 00095 //Creating an Expression for a Value 00101 + (CPExpression)expressionForConstantValue:(id)value 00102 { 00103 return [[CPExpression_constant alloc] initWithValue:value]; 00104 } 00105 00110 + (CPExpression)expressionForEvaluatedObject 00111 { 00112 return [CPExpression_self evaluatedObject]; 00113 } 00114 00120 + (CPExpression)expressionForVariable:(CPString)string 00121 { 00122 return [[CPExpression_variable alloc] initWithVariable:string]; 00123 } 00124 00130 + (CPExpression)expressionForKeyPath:(CPString)keyPath 00131 { 00132 return [[CPExpression_keypath alloc] initWithKeyPath:keyPath]; 00133 } 00134 00140 + (CPExpression)expressionForAggregate:(CPArray)collection 00141 { 00142 return [[CPExpression_aggregate alloc] initWithAggregate:collection]; 00143 } 00144 00151 + (CPExpression)expressionForUnionSet:(CPExpression)left with:(CPExpression)right 00152 { 00153 return [[CPExpression_set alloc] initWithType:CPUnionSetExpressionType left:left right:right]; 00154 } 00155 00162 + (CPExpression)expressionForIntersectSet:(CPExpression)left with:(CPExpression)right 00163 { 00164 return [[CPExpression_set alloc] initWithType:CPIntersectSetExpressionType left:left right:right]; 00165 } 00166 00173 + (CPExpression)expressionForMinusSet:(CPExpression)left with:(CPExpression)right 00174 { 00175 return [[CPExpression_set alloc] initWithType:CPMinusSetExpressionType left:left right:right]; 00176 } 00177 00178 // Creating an Expression for a Function 00226 + (CPExpression)expressionForFunction:(CPString)function_name arguments:(CPArray)parameters 00227 { 00228 return [[CPExpression_function alloc] initWithSelector:CPSelectorFromString(function_name) arguments:parameters]; 00229 } 00230 00240 + (CPExpression)expressionForFunction:(CPExpression)target selectorName:(CPString)selectorName arguments:(CPArray)parameters 00241 { 00242 return [[CPExpression_function alloc] initWithTarget:target selector:CPSelectorFromString(selectorName) arguments:parameters]; 00243 } 00244 00252 + (CPExpression)expressionForSubquery:(CPExpression)expression usingIteratorVariable:(CPString)variable predicate:(CPPredicate)predicate 00253 { 00254 return [[CPExpression_subquery alloc] initWithExpression:expression usingIteratorVariable:variable predicate:predicate]; 00255 } 00256 00257 // Getting Information About an Expression 00263 - (int)expressionType 00264 { 00265 return _type; 00266 } 00267 00273 - (id)constantValue 00274 { 00275 _CPRaiseInvalidAbstractInvocation(self, _cmd); 00276 return nil; 00277 } 00278 00284 - (CPString)variable 00285 { 00286 _CPRaiseInvalidAbstractInvocation(self, _cmd); 00287 return nil; 00288 } 00289 00295 - (CPString)keyPath 00296 { 00297 _CPRaiseInvalidAbstractInvocation(self, _cmd); 00298 return nil; 00299 } 00300 00306 - (CPString)function 00307 { 00308 _CPRaiseInvalidAbstractInvocation(self, _cmd); 00309 return nil; 00310 } 00311 00317 - (CPArray)arguments 00318 { 00319 _CPRaiseInvalidAbstractInvocation(self, _cmd); 00320 return nil; 00321 } 00322 00328 - (id)collection 00329 { 00330 _CPRaiseInvalidAbstractInvocation(self, _cmd); 00331 return nil; 00332 } 00333 00339 - (CPPredicate)predicate 00340 { 00341 _CPRaiseInvalidAbstractInvocation(self, _cmd); 00342 return nil; 00343 } 00344 00350 - (CPExpression)operand 00351 { 00352 _CPRaiseInvalidAbstractInvocation(self, _cmd); 00353 return nil; 00354 } 00355 00361 - (CPExpression)leftExpression 00362 { 00363 _CPRaiseInvalidAbstractInvocation(self, _cmd); 00364 return nil; 00365 } 00366 00372 - (CPExpression)rightExpression 00373 { 00374 _CPRaiseInvalidAbstractInvocation(self, _cmd); 00375 return nil; 00376 } 00377 00378 - (CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables 00379 { 00380 return self; 00381 } 00382 00383 @end 00384