//
//  EXPDimensionElement.m
//  dde
//
//  Created by Ashley on 23/07/2007.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "EXPDimensionElement.h"
#import "EXPDimensionItemElement.h"
#import "EXPParser.h"

@implementation EXPDimensionElement

- (id) init
{
	self = [super init];
	if (self!=nil) {
		_dimensionList = [[NSMutableArray alloc] init];
		_isOrderedDimension = NO;
		_lowerBound = 0;
		_upperBound = 0;
	}
	
	return self;
}

- (void) setOrderedDimension:(BOOL)isOrderedDimension
{
	_isOrderedDimension = isOrderedDimension;
}

- (BOOL) isOrderedDimension
{
	return _isOrderedDimension;
}

- (void) setLowerBound:(int)lowerBound
{
	_lowerBound = lowerBound;
}

- (int) lowerBound
{
	return _lowerBound;
}

- (void) setUpperBound:(int)upperBound
{
	_upperBound = upperBound;
}

- (int) upperBound
{
	return _upperBound;
}

- (void) addItem:(id)item
{
	[_dimensionList addObject:item];
}

- (id) dimensionList
{
	return _dimensionList;
}

- (unsigned int) indexOfItem:(id)item
{
	unsigned int index = [[self dimensionList] indexOfObject:item];
	return index;
}

- (int) nElements
{
	int n;
	if ([self isOrderedDimension]) {
		n = [self upperBound] - [self lowerBound] + 1;
	} else {
		n = [[self dimensionList] count];
	}
	
	return n;
}

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

- (BOOL) isConstant
{
	return NO;
}

- (EXPExpressionType) expressionType
{
	return dimensionType;
}

+ (int) storageSize
{
	return 2;
}

- (NSString *) description
{
	NSMutableString *desc = [[NSMutableString alloc] initWithString:@"EXPDimensionElement: "];
	[desc appendString:[self name]];
	NSArray *dimensionList = [self dimensionList];
	int i;
	for(i=0; i<[dimensionList count]; i++) {
		EXPDimensionItemElement *item = [dimensionList objectAtIndex:i];
		[desc appendString:@" "];
		[desc appendString:[item name]];
	}
	NSString *str = [NSString stringWithString:desc];
	[desc release];
	return str;
}

- (void) dealloc
{
	[_dimensionList release];
	[super dealloc];
}

@end