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:
@@ -10,12 +10,11 @@
|
||||
#import "MPExpression.h"
|
||||
#import "MPRangePath.h"
|
||||
|
||||
#import "NSIndexPath+MPReverseIndexPath.h"
|
||||
#import "NSIndexPath+MPAdditions.h"
|
||||
|
||||
@implementation MPFunction
|
||||
|
||||
#pragma mark Creation Methods
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
@@ -25,7 +24,6 @@
|
||||
}
|
||||
|
||||
#pragma mark Working With the Expression Tree
|
||||
|
||||
- (NSUInteger)numberOfChildren
|
||||
{
|
||||
return 0;
|
||||
@@ -38,63 +36,10 @@
|
||||
|
||||
- (void)setChild:(MPExpression *)child
|
||||
atIndex:(NSUInteger)index
|
||||
{}
|
||||
|
||||
#pragma mark Evaluating Functions
|
||||
|
||||
- (double)doubleValue
|
||||
{
|
||||
return 0;
|
||||
[self didChangeChildAtIndex:index];
|
||||
}
|
||||
|
||||
#pragma mark Working With Functions
|
||||
|
||||
- (BOOL)isEqual:(id)object
|
||||
{
|
||||
if (self == object) {
|
||||
return YES;
|
||||
}
|
||||
if (object == nil) {
|
||||
return NO;
|
||||
}
|
||||
if (![object isKindOfClass:[MPFunction class]]) {
|
||||
return NO;
|
||||
}
|
||||
return [self isEqualToFunction:(MPFunction *)object];
|
||||
}
|
||||
|
||||
- (BOOL)isEqualToFunction:(MPFunction *)aFunction
|
||||
{
|
||||
return [aFunction isMemberOfClass:[MPFunction class]] && [self isMemberOfClass:[MPFunction class]];
|
||||
}
|
||||
|
||||
#pragma mark - NSCopying
|
||||
|
||||
- (id)copyWithZone:(NSZone *)zone
|
||||
{
|
||||
return [[MPFunction allocWithZone:zone] init];
|
||||
}
|
||||
|
||||
#pragma mark - NSCoding
|
||||
|
||||
- (id)initWithCoder:(NSCoder *)aDecoder
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)aCoder
|
||||
{}
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPFunction (MPFunctionExtensionMethods)
|
||||
|
||||
#pragma mark Working With the Expression Tree
|
||||
|
||||
- (NSArray *)children
|
||||
{
|
||||
NSUInteger childCount = [self numberOfChildren];
|
||||
@@ -116,16 +61,115 @@
|
||||
return NSNotFound;
|
||||
}
|
||||
|
||||
- (id)symbolAtIndexPath:(NSIndexPath *)indexPath
|
||||
- (id)elementAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
if (indexPath.length == 0) {
|
||||
return self;
|
||||
}
|
||||
MPExpression *child = [self childAtIndex:[indexPath indexAtPosition:0]];
|
||||
return [child symbolAtIndexPath:[indexPath indexPathByRemovingFirstIndex]];
|
||||
return [child elementAtIndexPath:[indexPath indexPathByRemovingFirstIndex]];
|
||||
}
|
||||
|
||||
#pragma mark Evaluating Functions
|
||||
- (double)doubleValue
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma mark Notifications
|
||||
- (void)didChangeElementsInRangePath:(MPRangePath *)rangePath
|
||||
replacementLength:(NSUInteger)replacementLength
|
||||
{
|
||||
NSUInteger selfIndex = [self.parent indexOfElement:self];
|
||||
MPRangePath *newPath = rangePath.copy;
|
||||
newPath.location = [newPath.location indexPathByPreceedingIndex:selfIndex];
|
||||
[self.parent didChangeElementsInRangePath:newPath
|
||||
replacementLength:replacementLength];
|
||||
}
|
||||
|
||||
- (void)didChangeChild:(MPExpression *)child
|
||||
{
|
||||
[self didChangeChildAtIndex:[self indexOfChild:child]];
|
||||
}
|
||||
|
||||
- (void)didChangeChildAtIndex:(NSUInteger)index
|
||||
{
|
||||
MPRangePath *path = [[MPRangePath alloc] initWithRange:NSMakeRange(index, 1)];
|
||||
[self didChangeElementsInRangePath:path
|
||||
replacementLength:1];
|
||||
}
|
||||
|
||||
#pragma mark Working With Functions
|
||||
- (BOOL)isEqual:(id)object
|
||||
{
|
||||
if (self == object) {
|
||||
return YES;
|
||||
}
|
||||
if (object == nil) {
|
||||
return NO;
|
||||
}
|
||||
if (![object isKindOfClass:[MPFunction class]]) {
|
||||
return NO;
|
||||
}
|
||||
return [self isEqualToFunction:(MPFunction *)object];
|
||||
}
|
||||
|
||||
- (BOOL)isEqualToFunction:(MPFunction *)aFunction
|
||||
{
|
||||
return [aFunction isMemberOfClass:[MPFunction class]] && [self isMemberOfClass:[MPFunction class]];
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return @"[]";
|
||||
}
|
||||
|
||||
- (NSUInteger)hash
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma mark - NSCopying
|
||||
- (id)copyWithZone:(NSZone *)zone
|
||||
{
|
||||
return [[MPFunction allocWithZone:zone] init];
|
||||
}
|
||||
|
||||
#pragma mark - NSCoding
|
||||
- (id)initWithCoder:(NSCoder *)aDecoder
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
NSArray *children = [aDecoder decodeObject];
|
||||
NSInteger index = 0;
|
||||
for (MPExpression *child in children) {
|
||||
[self setChild:child atIndex:index];
|
||||
++index;
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)aCoder
|
||||
{
|
||||
[aCoder encodeObject:self.children];
|
||||
}
|
||||
|
||||
#pragma mark - MPExpressionElement
|
||||
- (BOOL)isString
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isFunction
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSUInteger)length
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (float)floatValue
|
||||
{
|
||||
@@ -147,26 +191,4 @@
|
||||
return (long long)[self doubleValue];
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return @"[]";
|
||||
}
|
||||
|
||||
- (NSUInteger)hash
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPFunction (MPDisplayExtension)
|
||||
|
||||
- (void)symbolsChangedInRangePath:(MPRangePath *)rangePath replacementLength:(NSUInteger)length
|
||||
{
|
||||
NSUInteger index = [self.parent indexOfSymbol:self];
|
||||
NSIndexPath *newLocation = [rangePath.location indexPathByPrecedingIndex:index];
|
||||
MPRangePath *newRangePath = [[MPRangePath alloc] initWithLocation:newLocation length:rangePath.length];
|
||||
[self.parent symbolsChangedInRangePath:newRangePath replacementLength:length];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user