API 0.9.5
Foundation/CPPredicate/CPExpression_keypath.j
Go to the documentation of this file.
00001 /*
00002  * CPExpression_keypath.j
00003  *
00004  * Portions based on NSExpression_keypath.m in Cocotron (http://www.cocotron.org/)
00005  * Copyright (c) 2006-2007 Christopher J. W. Lloyd
00006  *
00007  * Created by cacaodev.
00008  * Copyright 2010.
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00023  */
00024 @implementation CPExpression_keypath : CPExpression_function
00025 {
00026     id __doxygen__;
00027 }
00028 
00029 - (id)initWithKeyPath:(CPString)keyPath
00030 {
00031     return [self initWithOperand:[CPExpression expressionForEvaluatedObject] andKeyPath:keyPath];
00032 }
00033 
00034 - (id)initWithOperand:(CPExpression)operand andKeyPath:(CPString)keyPath
00035 {
00036     var arg = [CPExpression expressionForConstantValue:keyPath];
00037     // Cocoa: if it's a direct path selector use valueForKey:
00038     self = [super initWithTarget:operand selector:@selector(valueForKeyPath:) arguments:[arg] type:CPKeyPathExpressionType];
00039 
00040     return self;
00041 }
00042 
00043 - (BOOL)isEqual:(id)object
00044 {
00045     if (object === self)
00046         return YES;
00047 
00048     return ([object keyPath] == [self keyPath]); // If it appears that parsing generates nested keypaths with different targets and same keyPath, comparing -keyPath won't work.
00049 }
00050 
00051 - (CPExpression)pathExpression
00052 {
00053     return [[self arguments] objectAtIndex:0];
00054 }
00055 
00056 - (CPString)keyPath
00057 {
00058     return [[self pathExpression] keyPath];
00059 }
00060 
00061 - (CPString)description
00062 {
00063     var result = "";
00064     if ([_operand expressionType] != CPEvaluatedObjectExpressionType)
00065         result += [_operand description] + ".";
00066     result += [self keyPath];
00067 
00068     return result;
00069 }
00070 
00071 @end
00072 
00073 @implementation CPExpression_constant (KeyPath)
00074 
00075 - (CPString)keyPath
00076 {
00077     return [self constantValue];
00078 }
00079 
00080 @end
 All Classes Files Functions Variables Defines