61 lines
1.2 KiB
Objective-C
61 lines
1.2 KiB
Objective-C
//
|
|
// MPParsedElement.m
|
|
// MathPad
|
|
//
|
|
// Created by Kim Wittenburg on 05.09.14.
|
|
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
|
//
|
|
|
|
#import "MPParsedElement.h"
|
|
|
|
@implementation MPParsedElement
|
|
|
|
- (instancetype)init
|
|
{
|
|
self = [super init];
|
|
if (self) {
|
|
_summands = [[NSMutableArray alloc] init];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (double)standaloneValue
|
|
{
|
|
if (self.isFactor) {
|
|
return self.factor;
|
|
}
|
|
return self.prefixMultiplicator + [[self.summands valueForKeyPath:@"@sum.self"] doubleValue];
|
|
}
|
|
|
|
- (BOOL)isValidElementAtBeginning
|
|
{
|
|
return NO;
|
|
}
|
|
|
|
- (BOOL)isValidElementInBetween
|
|
{
|
|
return YES;
|
|
}
|
|
|
|
- (BOOL)isValidElementAtEnd
|
|
{
|
|
return NO;
|
|
}
|
|
|
|
#pragma mark NSCopying
|
|
- (id)copyWithZone:(NSZone *)zone
|
|
{
|
|
MPParsedElement *copy = [[MPParsedElement allocWithZone:zone] init];
|
|
copy.isFactor = self.isFactor;
|
|
copy.factor = self.factor;
|
|
copy.summands = self.summands.mutableCopy;
|
|
copy.prefixMultiplicator = self.prefixMultiplicator;
|
|
copy.hasPrefixMultiplicator = self.hasPrefixMultiplicator;
|
|
copy.prefixOperatorExplicit = self.prefixOperatorExplicit;
|
|
copy.suffixMultiplicator = self.suffixMultiplicator;
|
|
copy.hasSuffixMultiplicator = self.hasSuffixMultiplicator;
|
|
return copy;
|
|
}
|
|
|
|
@end
|