Added MPExpression and MPFunction Interfaces
This commit is contained in:
103
MathPad/MPExpression.h
Normal file
103
MathPad/MPExpression.h
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
//
|
||||||
|
// MPExpression.h
|
||||||
|
// MathPad
|
||||||
|
//
|
||||||
|
// Created by Kim Wittenburg on 17.04.14.
|
||||||
|
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
@class MPExpression, MPFunction;
|
||||||
|
|
||||||
|
@interface MPExpression : NSObject <NSCopying, NSMutableCopying, NSCoding>
|
||||||
|
|
||||||
|
#pragma mark Creation Methods
|
||||||
|
|
||||||
|
- (instancetype)initWithSymbols:(NSArray *)symbols;
|
||||||
|
|
||||||
|
#pragma mark Primitive Methods
|
||||||
|
|
||||||
|
- (NSUInteger)numberOfSymbols;
|
||||||
|
- (id)symbolAtIndex:(NSUInteger)index; // Either an NSString or a MPFunction
|
||||||
|
|
||||||
|
- (double)doubleValue; // Evaluates Expression
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface MPExpression (MPExpressionExtensionMethods)
|
||||||
|
|
||||||
|
#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;
|
||||||
|
|
||||||
|
#pragma mark Working with Expressions
|
||||||
|
|
||||||
|
- (NSUInteger)length;
|
||||||
|
|
||||||
|
- (MPExpression *)subexpressionFromIndex:(NSUInteger)from;
|
||||||
|
- (MPExpression *)subexpressionToIndex:(NSUInteger)to;
|
||||||
|
- (MPExpression *)subexpressionWithRange:(NSRange)range;
|
||||||
|
|
||||||
|
- (BOOL)isEqualToExpression:(MPExpression *)anExpression;
|
||||||
|
|
||||||
|
// TODO: prefix and suffix operator
|
||||||
|
/*
|
||||||
|
- (BOOL)hasPrefix:(NSString *)aString;
|
||||||
|
- (BOOL)hasSuffix:(NSString *)aString;
|
||||||
|
*/
|
||||||
|
|
||||||
|
- (MPExpression *)expressionByAppendingString:(NSString *)aString;
|
||||||
|
- (MPExpression *)expressionByAppendingFunction:(MPFunction *)aFunction;
|
||||||
|
- (MPExpression *)expressionByAppendingExpression:(MPExpression *)anExpression;
|
||||||
|
- (MPExpression *)expressionByAppendingSymbols:(NSArray *)symbols;
|
||||||
|
|
||||||
|
#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 MPMutableExpression : MPExpression
|
||||||
|
|
||||||
|
- (void)replaceSymbolsInRange:(NSRange)range withExpression:(MPExpression *)anExpression;
|
||||||
|
|
||||||
|
@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;
|
||||||
|
|
||||||
|
@end
|
||||||
47
MathPad/MPFunction.h
Normal file
47
MathPad/MPFunction.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
//
|
||||||
|
// MPFunction.h
|
||||||
|
// MathPad
|
||||||
|
//
|
||||||
|
// Created by Kim Wittenburg on 18.04.14.
|
||||||
|
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
@class MPFunction, MPExpression;
|
||||||
|
|
||||||
|
@interface MPFunction : NSObject
|
||||||
|
|
||||||
|
#pragma mark Creation Methods
|
||||||
|
|
||||||
|
- (instancetype)init;
|
||||||
|
|
||||||
|
#pragma mark Children
|
||||||
|
|
||||||
|
- (NSUInteger)numberOfChildren;
|
||||||
|
- (MPExpression *)childAtIndex;
|
||||||
|
- (void)setChild:(MPExpression *)child atIndex:(NSUInteger)index;
|
||||||
|
|
||||||
|
#pragma mark Evaluating Functions
|
||||||
|
|
||||||
|
- (double)doubleValue;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface MPFunction (MPFunctionExtensionMethods)
|
||||||
|
|
||||||
|
#pragma mark Children
|
||||||
|
|
||||||
|
- (NSArray *)children;
|
||||||
|
|
||||||
|
#pragma mark Evaluating Expressions
|
||||||
|
|
||||||
|
- (float)floatValue;
|
||||||
|
- (int)intValue;
|
||||||
|
- (NSInteger)integerValue;
|
||||||
|
- (long long)longLongValue;
|
||||||
|
- (NSString *)stringValue;
|
||||||
|
|
||||||
|
- (NSString *)description;
|
||||||
|
|
||||||
|
- (NSUInteger)hash;
|
||||||
|
|
||||||
|
@end
|
||||||
Reference in New Issue
Block a user