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/MPFunction.h
2014-10-13 23:53:04 +02:00

69 lines
2.0 KiB
Objective-C

//
// MPFunction.h
// MathPad
//
// Created by Kim Wittenburg on 18.04.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
@import Foundation;
#import "MPExpressionElement.h"
#import "MPParseError.h"
#define MPFunctionAccessorImplementation(Accessor, variableName) \
- (void)set##Accessor:(MPExpression *)value \
{ \
variableName.parent = nil; \
variableName = value; \
variableName.parent = self; \
[self didChangeChildAtIndex:[self indexOfChild:variableName]]; \
}
@class MPFunction, MPExpression, MPRangePath;
@interface MPFunction : NSObject <NSCoding, NSCopying, MPExpressionElement>
#pragma mark Creation Methods
- (instancetype)init;
#pragma mark Properties
// Subclasses should define accessor properties for all sub expressions, which, in the setter, should send didChangeElementAtRangePath:replacementLength: to self with a replacement length of 1.
#pragma mark Working With the Expression Tree
@property (nonatomic, weak) MPExpression *parent; // Documentation: Do not set
- (MPExpression *)rootExpression;
- (NSIndexPath *)indexPath;
- (NSArray *)childrenAccessors; // Override
- (NSUInteger)numberOfChildren;
- (MPExpression *)childAtIndex:(NSUInteger)index;
- (void)setChild:(MPExpression *)child
atIndex:(NSUInteger)index;
- (NSArray *)children; // Indexes must equal the ones from the other methods
- (NSUInteger)indexOfChild:(MPExpression *)child;
- (id)elementAtIndexPath:(NSIndexPath *)indexPath;
#pragma mark Evaluating Functions
- (BOOL)validate:(MPParseError *__autoreleasing *)error; // Override
- (NSDecimalNumber *)evaluate; // Override
#pragma mark Messages
- (void)didChangeElementsInRangePath:(MPRangePath *)rangePath
replacementLength:(NSUInteger)replacementLength;
- (void)didChangeChildAtIndex:(NSUInteger)index;
#pragma mark Working With Functions
// - (BOOL)isEqualToFunction:(MPFunction *)aFunction; // Override
- (NSString *)description; // Should be overridden
- (NSUInteger)hash;
- (id)copyWithZone:(NSZone *)zone;
@end