![]() |
API 0.9.5
|
00001 /* 00002 * CPExpression_constant.j 00003 * 00004 * Portions based on NSExpression_constant.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 00025 00026 @implementation CPExpression_constant : CPExpression 00027 { 00028 id _value; 00029 } 00030 00031 - (id)initWithValue:(id)value 00032 { 00033 self = [super initWithExpressionType:CPConstantValueExpressionType]; 00034 00035 if (self) 00036 _value = value; 00037 00038 return self; 00039 } 00040 00041 - (BOOL)isEqual:(id)object 00042 { 00043 if (self === object) 00044 return YES; 00045 00046 if (object.isa != self.isa || [object expressionType] != [self expressionType] || ![[object constantValue] isEqual:[self constantValue]]) 00047 return NO; 00048 00049 return YES; 00050 } 00051 00052 - (id)constantValue 00053 { 00054 return _value; 00055 } 00056 00057 - (id)expressionValueWithObject:(id)object context:(CPDictionary)context 00058 { 00059 return _value; 00060 } 00061 00062 - (CPString)description 00063 { 00064 if ([_value isKindOfClass:[CPString class]]) 00065 return @"\"" + _value + @"\""; 00066 00067 return [_value description]; 00068 } 00069 00070 @end 00071 00072 var CPConstantValueKey = @"CPConstantValue"; 00073 00074 @implementation CPExpression_constant (CPCoding) 00075 00076 - (id)initWithCoder:(CPCoder)coder 00077 { 00078 var value = [coder decodeObjectForKey:CPConstantValueKey]; 00079 return [self initWithValue:value]; 00080 } 00081 00082 - (void)encodeWithCoder:(CPCoder)coder 00083 { 00084 [coder encodeObject:_value forKey:CPConstantValueKey]; 00085 } 00086 00087 @end