Internal Redesign:
- Combined MPExpression and MPMutableExpression - Abstracted children of MPExpression into MPExpressionElement protocol - Abstracted most of MPExpressionLayout and MPFunctionLayout into common superclass MPLayout
This commit is contained in:
@@ -2,124 +2,82 @@
|
||||
// MPExpression.h
|
||||
// MathPad
|
||||
//
|
||||
// Created by Kim Wittenburg on 17.04.14.
|
||||
// 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;
|
||||
|
||||
extern NSString *MPAdditionOperator;
|
||||
extern NSString *MPSubtractionOperator;
|
||||
extern NSString *MPMultiplicationOperator;
|
||||
extern NSString *MPDivisionOperator;
|
||||
|
||||
@interface MPExpression : NSObject <NSCopying, NSMutableCopying, NSCoding>
|
||||
@interface MPExpression : NSObject <NSCopying, NSCoding>
|
||||
|
||||
#pragma mark Creation Methods
|
||||
|
||||
- (instancetype)initWithSymbols:(NSArray *)symbols;
|
||||
- (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
|
||||
|
||||
@property (nonatomic, weak) MPFunction *parent; // Documentation: Do not set, may be nil
|
||||
|
||||
- (void)fixSymbols;
|
||||
- (void)fixElements; // Called automatically, removes empty elements, joins subsequent strings
|
||||
|
||||
#pragma mark Primitive Methods
|
||||
|
||||
- (NSUInteger)numberOfSymbols;
|
||||
- (id)symbolAtIndex:(NSUInteger)index; // Either an NSString or a MPFunction (which can be mutated)
|
||||
- (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 (MPExpressionExtensionMethods)
|
||||
|
||||
+ (NSArray *)operators;
|
||||
|
||||
#pragma mark Creation Methods
|
||||
|
||||
- (id)init;
|
||||
- (instancetype)initWithString:(NSString *)aString;
|
||||
- (instancetype)initWithFunction:(MPFunction *)aFunction;
|
||||
|
||||
+ (instancetype)expression;
|
||||
+ (instancetype)expressionWithString:(NSString *)aString;
|
||||
+ (instancetype)expressionWithFunction:(MPFunction *)aFunction;
|
||||
+ (instancetype)expressionWithSymbols:(NSArray *)symbols;
|
||||
@interface MPExpression (MPExpressionExtension)
|
||||
|
||||
#pragma mark Working With the Expression Tree
|
||||
|
||||
- (NSUInteger)indexOfSymbol:(id)symbol;
|
||||
- (id)symbolAtIndexPath:(NSIndexPath *)indexPath; // May also return MPExpression
|
||||
- (id)elementAtIndexPath:(NSIndexPath *)indexPath; // Returns an MPExpression or id<MPExpressionElement>
|
||||
- (NSArray *)elementsInRangePath:(MPRangePath *)rangePath;
|
||||
|
||||
#pragma mark Working With Expressions
|
||||
|
||||
- (NSUInteger)length;
|
||||
|
||||
- (MPExpression *)subexpressionFromIndex:(NSUInteger)from;
|
||||
- (MPExpression *)subexpressionToIndex:(NSUInteger)to;
|
||||
- (MPExpression *)subexpressionFromLocation:(NSUInteger)from;
|
||||
- (MPExpression *)subexpressionToLocation:(NSUInteger)to;
|
||||
- (MPExpression *)subexpressionWithRange:(NSRange)range;
|
||||
|
||||
- (BOOL)isEqualToExpression:(MPExpression *)anExpression;
|
||||
|
||||
- (MPExpression *)expressionByAppendingString:(NSString *)aString;
|
||||
- (MPExpression *)expressionByAppendingFunction:(MPFunction *)aFunction;
|
||||
- (MPExpression *)expressionByAppendingExpression:(MPExpression *)anExpression;
|
||||
- (MPExpression *)expressionByAppendingSymbols:(NSArray *)symbols;
|
||||
#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 an Expression's Contents
|
||||
|
||||
- (NSArray *)symbols;
|
||||
|
||||
- (NSString *)description;
|
||||
|
||||
- (NSUInteger)hash;
|
||||
|
||||
@end
|
||||
|
||||
@interface MPExpression (MPChangeNotificationExtension)
|
||||
|
||||
- (void)symbolsChangedInRangePath:(MPRangePath *)rangePath replacementLength:(NSUInteger)length;
|
||||
|
||||
@end
|
||||
|
||||
@interface MPMutableExpression : MPExpression
|
||||
|
||||
- (void)replaceSymbolsInRange:(NSRange)range
|
||||
withSymbols:(NSArray *)symbols;
|
||||
|
||||
@end
|
||||
|
||||
@interface MPMutableExpression (MPMutableExpressionExtensionMethods)
|
||||
|
||||
- (void)insertString:(NSString *)aString
|
||||
atIndex:(NSUInteger)loc;
|
||||
- (void)insertFunction:(MPFunction *)aFunction
|
||||
atIndex:(NSUInteger)loc;
|
||||
- (void)insertExpression:(MPExpression *)anExpression
|
||||
atIndex:(NSUInteger)loc;
|
||||
- (void)insertSymbols:(NSArray *)symbols
|
||||
atIndex:(NSUInteger)loc;
|
||||
|
||||
- (void)deleteSymbolsInRange:(NSRange)range;
|
||||
|
||||
- (void)appendString:(NSString *)aString;
|
||||
- (void)appendFunction:(MPFunction *)aFunction;
|
||||
- (void)appendExpression:(MPExpression *)anExpression;
|
||||
- (void)appendSymbols:(NSArray *)symbols;
|
||||
|
||||
- (void)setString:(NSString *)aString;
|
||||
- (void)setFunction:(MPFunction *)aFunction;
|
||||
- (void)setExpression:(MPExpression *)anExpression;
|
||||
- (void)setSymbols:(NSArray *)symbols;
|
||||
#pragma mark Querying Expressions
|
||||
- (NSArray *)elements;
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user