135 lines
2.1 KiB
Objective-C
135 lines
2.1 KiB
Objective-C
//
|
|
// MPFunction.m
|
|
// MathPad
|
|
//
|
|
// Created by Kim Wittenburg on 18.04.14.
|
|
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
|
//
|
|
|
|
#import "MPFunction.h"
|
|
|
|
@implementation MPFunction
|
|
|
|
#pragma mark Creation Methods
|
|
|
|
- (instancetype)init
|
|
{
|
|
self = [super init];
|
|
if (self) {
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark Children
|
|
|
|
- (NSUInteger)numberOfChildren
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
- (MPExpression *)childAtIndex:(NSUInteger)index
|
|
{
|
|
return nil;
|
|
}
|
|
|
|
- (void)setChild:(MPExpression *)child atIndex:(NSUInteger)index
|
|
{}
|
|
|
|
#pragma mark Evaluating Functions
|
|
|
|
- (double)doubleValue
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
#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 Children
|
|
|
|
- (NSArray *)children
|
|
{
|
|
NSUInteger childCount = [self numberOfChildren];
|
|
NSMutableArray *children = [[NSMutableArray alloc] initWithCapacity:childCount];
|
|
for (NSInteger i = 0; i < childCount; i++) {
|
|
[children addObject:[self childAtIndex:i]];
|
|
}
|
|
return [children copy];
|
|
}
|
|
|
|
#pragma mark Evaluating Functions
|
|
|
|
- (float)floatValue
|
|
{
|
|
return (float)[self doubleValue];
|
|
}
|
|
|
|
- (int)intValue
|
|
{
|
|
return (int)[self doubleValue];
|
|
}
|
|
|
|
- (NSInteger)integerValue
|
|
{
|
|
return (NSInteger)[self doubleValue];
|
|
}
|
|
|
|
- (long long)longLongValue
|
|
{
|
|
return (long long)[self doubleValue];
|
|
}
|
|
|
|
- (NSString *)description
|
|
{
|
|
return @"[]";
|
|
}
|
|
|
|
- (NSUInteger)hash
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
@end |