Drastic Simplification of MPFunction subclass implementations
This commit is contained in:
@@ -12,49 +12,18 @@
|
||||
|
||||
@implementation MPParenthesisFunction
|
||||
|
||||
+ (NSString *)localizedFunctionName
|
||||
{
|
||||
return NSLocalizedString(@"Parenthesis", @"Name of Parenthesis Function");
|
||||
}
|
||||
MPFunctionAccessorImplementation(Expression, _expression)
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_expression = [[MPExpression alloc] init];
|
||||
_expression.parent = self;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
//- (void)setExpression:(MPExpression *)expression
|
||||
//{
|
||||
// _expression.parent = nil;
|
||||
// _expression = expression;
|
||||
// _expression.parent = self;
|
||||
//}
|
||||
|
||||
- (void)setExpression:(MPExpression *)expression
|
||||
- (NSArray *)childrenAccessors
|
||||
{
|
||||
_expression.parent = nil;
|
||||
_expression = expression;
|
||||
_expression.parent = self;
|
||||
}
|
||||
|
||||
- (NSUInteger)numberOfChildren
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (MPExpression *)childAtIndex:(NSUInteger)index
|
||||
{
|
||||
return index == 0 ? self.expression : nil;
|
||||
}
|
||||
|
||||
- (void)setChild:(MPExpression *)child
|
||||
atIndex:(NSUInteger)index
|
||||
{
|
||||
if (index == 0) {
|
||||
self.expression = child;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *)children
|
||||
{
|
||||
return @[self.expression];
|
||||
return @[@"expression"];
|
||||
}
|
||||
|
||||
- (MPTerm *)parseWithError:(MPParseError *__autoreleasing *)error
|
||||
@@ -64,27 +33,9 @@
|
||||
error:error];
|
||||
}
|
||||
|
||||
- (NSDecimalNumber *)evaluateWithError:(MPParseError *__autoreleasing *)error
|
||||
{
|
||||
return [self.expression evaluateWithError:error];
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"(%@)", self.expression.description];
|
||||
}
|
||||
|
||||
- (NSUInteger)hash
|
||||
{
|
||||
#warning Unimplemented Method
|
||||
return [super hash] * self.expression.hash;
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)zone
|
||||
{
|
||||
MPParenthesisFunction *copy = [[MPParenthesisFunction allocWithZone:zone] init];
|
||||
copy.expression = self.expression.copy;
|
||||
return copy;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user