forked from natikgadzhi/XNMaths
-
Notifications
You must be signed in to change notification settings - Fork 1
/
XNFunction.m
66 lines (56 loc) · 1.51 KB
/
XNFunction.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// XNFunction.m
//
// Provides XNFunction class implementation.
// XNFunction is a one double function of one double argument.
//
// It currently uses (not optimized) GCMathParser to parse string expressions.
//
// First created for assignation 3.1 2009.
//
// Created by Нат Гаджибалаев on 07.11.09.
// Copyright 2009 Нат Гаджибалаев. All rights reserved.
//
#import "XNFunction.h"
#import "GCMathParser.h"
#import "XNLineData.h"
@implementation XNFunction
@synthesize expression;
#pragma mark -
#pragma mark Class methods init
+ (XNFunction*) functionWithExpression: (NSString*)aExpression
{
return [[XNFunction alloc] initWithExpression:aExpression];
}
#pragma mark -
#pragma mark Initialization
- (XNFunction*) initWithExpression: (NSString*) aExpression;
{
self = [super init];
parser = [[GCMathParser parser] retain];
expression = [aExpression copy];
return self;
}
#pragma mark -
#pragma mark Deallocation method
- (void) dealloc
{
[expression release];
[parser release];
[super dealloc];
}
#pragma mark -
#pragma mark Value getters
- (CGFloat) valueWithFloat: (CGFloat) a_X
{
//TODO: Optimize this. Read GCMathParser first.
[parser setSymbolValue: a_X forKey: @"x"];
return (CGFloat)[parser evaluate: expression];
}
#pragma mark -
#pragma mark Private (data related)
- (XNLineData *) createLineDataInRange: (XNFloatRange*)range withQuality: (NSUInteger) lineQuality
{
return [[XNLineData alloc] initWithFunction:self inRange: range withQuality:lineQuality];
}
@end