Archived
1
This repository has been archived on 2022-08-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
mathpad/MathPad/MPParenthesisFunction.m
Kim Wittenburg 19a40c2907 Added Function Chooser as a Popover
Improved Evaluation
Added Parenthesis Function
2014-09-28 23:52:29 +02:00

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