91 lines
1.8 KiB
Objective-C
91 lines
1.8 KiB
Objective-C
|
|
//
|
|
// MPParenthesisFunction.m
|
|
// MathPad
|
|
//
|
|
// Created by Kim Wittenburg on 17.09.14.
|
|
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
|
//
|
|
|
|
#import "MPParenthesisFunction.h"
|
|
#import "MPExpressionEvaluator.h"
|
|
|
|
@implementation MPParenthesisFunction
|
|
|
|
+ (NSString *)localizedFunctionName
|
|
{
|
|
return NSLocalizedString(@"Parenthesis", @"Name of Parenthesis Function");
|
|
}
|
|
|
|
- (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;
|
|
}
|
|
|
|
- (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];
|
|
}
|
|
|
|
- (MPTerm *)parseWithError:(MPParseError *__autoreleasing *)error
|
|
{
|
|
MPExpressionEvaluator *evaluator = self.expression.evaluator;
|
|
return [evaluator parseExpectingVariable:NO
|
|
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
|