Archived
1

Added some methods to „Working With the Expression Tree“ section

This commit is contained in:
Kim Wittenburg
2014-04-23 03:10:17 +02:00
parent 24c53bde2e
commit 3c944f3fc0
4 changed files with 57 additions and 5 deletions

View File

@@ -9,6 +9,8 @@
#import "MPFunction.h"
#import "MPExpression.h"
#import "NSIndexPath+MPRemoveFirstIndex.h"
@implementation MPFunction
#pragma mark Creation Methods
@@ -90,7 +92,7 @@
@implementation MPFunction (MPFunctionExtensionMethods)
#pragma mark Children
#pragma mark Working With the Expression Tree
- (NSArray *)children
{
@@ -102,6 +104,26 @@
return [children copy];
}
- (NSUInteger)indexOfChild:(MPExpression *)child
{
NSUInteger index = 0;
for (; index < [self numberOfChildren]; index++) {
if ([[self childAtIndex:index] isEqualToExpression:child]) {
return index;
}
}
return NSNotFound;
}
- (id)symbolAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.length == 0) {
return self;
}
MPExpression *child = [self childAtIndex:[indexPath indexAtPosition:0]];
return [child symbolAtIndexPath:[indexPath indexPathByRemovingFirstIndex]];
}
#pragma mark Evaluating Functions
- (float)floatValue