//
//  EXPTableElement.m
//  dde
//
//  Created by ashley on 05/11/2007.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "EXPTableElement.h"
#import "EXPExpression.h"
#import "EXPSpline.h"

@implementation EXPTableElement

+ (int) storageSize
{
	return sizeof(EXPSpline *)/sizeof(short int);
}

- (id) init
{
	self = [super init];
	
	if (self!=nil) {
		_xPoints = [[NSMutableArray alloc] init];
		_yPoints = [[NSMutableArray alloc] init];
	}
	
	return self;
}

- (void) setXPoints:(id)xPoints
{
	[xPoints retain];
	[_xPoints release];
	_xPoints = xPoints;
}

- (id) xPoints
{
	return _xPoints;
}

- (void) addXPoint:(id)xPoint
{
	[[self xPoints] addObject:xPoint];
}

- (void) setYPoints:(id)yPoints
{
	[yPoints retain];
	[_yPoints release];
	_yPoints = yPoints;
}

- (id) yPoints
{
	return _yPoints;
}

- (void) addYPoint:(id)yPoint
{
	[[self yPoints] addObject:yPoint];
}

- (int) nPoints
{
	return [[self yPoints] count];
}

- (void) setIsRegular:(BOOL)isRegular
{
	_isRegular = isRegular;
}

- (BOOL) isRegular
{
	return _isRegular;
}

- (void) setXMin:(id)xMin
{
	[xMin retain];
	[_xMin release];
	_xMin = xMin;
}

- (id) xMin
{
	return _xMin;
}

- (void) setXMax:(id)xMax
{
	[xMax retain];
	[_xMax release];
	_xMax = xMax;
}

- (id) xMax
{
	return _xMax;
}

- (void) setInterpType:(int)interpType
{
	_interpType = interpType;
}

- (int) interpType
{
	return _interpType;
}

- (void) setExpressions:(id)expressions
{
	NSLog(@"setExpressions: %@", self);
}

- (NSString *)elementType
{
	return @"table";
}

- (EXPExpressionType) expressionType
{
	return doubleType;
}

- (NSString *)description
{
	NSMutableString *desc = [[NSMutableString alloc] initWithString:[self name]];
	[desc appendString:@"("];
	
	NSArray *xPoints = [self xPoints];
	NSArray *yPoints = [self yPoints];
	int i;
	for(i=0; i<[self nPoints]; i++) {
		NSString *xp = [[xPoints objectAtIndex:i] description];
		NSString *yp = [[yPoints objectAtIndex:i] description];
		if (i>0) {
			[desc appendString:@", "];
		}
		[desc appendFormat:@"{%@, %@}", xp, yp];
	}
	
	[desc appendString:@")"];

	return desc;
}

- (void) dealloc
{
	[_xPoints release];
	[_yPoints release];
	[_xMin release];
	[_xMax release];
	[super dealloc];
}

@end