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/MPExpression.h
Kim Wittenburg 60760b8b3d Internal Redesign:
- Combined MPExpression and MPMutableExpression
- Abstracted children of MPExpression into MPExpressionElement protocol
- Abstracted most of MPExpressionLayout and MPFunctionLayout into common superclass MPLayout
2014-08-11 13:57:48 +02:00

84 lines
2.7 KiB
Objective-C

//
// MPExpression.h
// MathPad
//
// Created by Kim Wittenburg on 10.08.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
@import Foundation;
#import "NSString+MPExpressionElement.h"
@class MPExpression, MPFunction, MPRangePath;
@protocol MPExpressionElement;
@interface MPExpression : NSObject <NSCopying, NSCoding>
#pragma mark Creation Methods
- (instancetype)init; // Convenience
- (instancetype)initWithElement:(id<MPExpressionElement>)element; // Convenience
- (instancetype)initWithElements:(NSArray *)elements; // Designated Initializer
#pragma mark Working With the Expression Tree
@property (nonatomic, weak) MPFunction *parent; // Set automatically, nil for root expression
- (void)fixElements; // Called automatically, removes empty elements, joins subsequent strings
#pragma mark Primitive Methods
- (NSUInteger)length;
- (NSUInteger)numberOfElements;
- (id<MPExpressionElement>)elementAtIndex:(NSUInteger)index;
- (NSArray *)elementsInRange:(NSRange)range;
- (NSUInteger)indexOfElement:(id<MPExpressionElement>)element;
- (void)replaceElementsInRange:(NSRange)range withElements:(NSArray *)elements;
// TODO: - (NSUInteger)indexOfElementAtLocation:(NSUInteger)location;
- (double)doubleValue; // Evaluates Expression
#pragma mark Notifications
// All notification methods should create a new rangePath with the receiver's index added to the beginning of the path and then ascend the message to it's parent
// TODO: More notifications
- (void)didChangeElementsInRangePath:(MPRangePath *)rangePath
replacementLength:(NSUInteger)replacementLength;
#pragma mark Basic NSObject Methods
- (BOOL)isEqualToExpression:(MPExpression *)anExpression;
- (NSString *)description;
- (NSUInteger)hash;
@end
@interface MPExpression (MPExpressionExtension)
#pragma mark Working With the Expression Tree
- (id)elementAtIndexPath:(NSIndexPath *)indexPath; // Returns an MPExpression or id<MPExpressionElement>
- (NSArray *)elementsInRangePath:(MPRangePath *)rangePath;
#pragma mark Working With Expressions
- (MPExpression *)subexpressionFromLocation:(NSUInteger)from;
- (MPExpression *)subexpressionToLocation:(NSUInteger)to;
- (MPExpression *)subexpressionWithRange:(NSRange)range;
#pragma mark Mutating Expressions
- (void)appendElement:(id<MPExpressionElement>)anElement;
- (void)appendElements:(NSArray *)elements;
- (void)insertElement:(id<MPExpressionElement>)anElement atLocation:(NSUInteger)index;
- (void)insertElements:(NSArray *)elements atLocation:(NSUInteger)index;
- (void)deleteElementsInRange:(NSRange)range;
#pragma mark Evaluating Expressions
- (float)floatValue;
- (int)intValue;
- (NSInteger)integerValue;
- (long long)longLongValue;
#pragma mark Querying Expressions
- (NSArray *)elements;
@end