//
//  EXPStateElement.m
//  XMLTest
//
//  Created by Ashley on 11/04/2007.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "EXPStateElement.h"
//#import "EXPAssemblerConstants.h"
#import "EXPVirtualMachine.h"
#import "EXPParser.h"
#import "EXPExpression.h"
#import "EXPUnaryOp.h"
#import "EXPBinOp.h"
#import "EXPError.h"

@implementation EXPStateElement

- (id) init
{
	self = [super init];
	if (self!=nil) {
		_inflows = [[NSMutableArray alloc] init];
		_outflows = [[NSMutableArray alloc] init];
		
		_isdelayVariable = NO;
		
		_scaleFactor = 0.0;
	}
	
	return self;
}

- (void) setOutflows:(id)outflows
{
	[outflows retain];
	[_outflows release];
	_outflows = outflows;
}

- (id) outflows
{
	return _outflows;
}

- (void) addOutflow:(EXPElement *)outflow
{
	if (outflow!=nil) {
		[[self outflows] addObject:outflow];
	}
}

- (void) setInflows:(id)inflows
{
	[inflows retain];
	[_inflows release];
	_inflows = inflows;
}

- (id) inflows
{
	return _inflows;
}

- (void) addInflow:(EXPElement *)inflow
{
	if (inflow!=nil) {
		[[self inflows] addObject:inflow];
	}
}

- (void) setIsDelayVariable:(BOOL)isDelayVariable
{
	_isdelayVariable = isDelayVariable;
}

- (BOOL) isDelayVariable
{
	return _isdelayVariable;
}

- (void) setDelayNumber:(int)delayNumber
{
	_delayNumber = delayNumber;
}

- (int) delayNumber
{
	return _delayNumber;
}

- (void) setScale:(double)scaleFactor
{
	_scaleFactor = scaleFactor;
}

- (double) scaleFactor
{
	return _scaleFactor;
}

- (double) value
{
	double answer = 0.0;
	return answer;
}

- (void) setGradientAddress:(int)address
{
	_gradientAddress = address;
}

- (int) gradientAddress
{
	return _gradientAddress;
}

- (int) maxPrimes
{
	return 0;
}

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

- (NSString *)description
{
	return [NSString stringWithFormat:@"EXPStateElement '%@'", [self name]];
}

/* - (id) retain
{
	printf("EXPStateElement retain: name = %s\n", [[self name] UTF8String]);
	return [super retain];
}

- (void) release
{
	printf("EXPStateElement release: name = %s retainCount = %d\n", [[self name] UTF8String], [self retainCount]);
	[super release];
}   */

- (void) dump
{
	[super dump];
	
	NSArray *inflows = [self inflows];
	int i;
	for(i=0; i<[inflows count]; i++) {
		[[inflows objectAtIndex:i] dump];
	}
	
	NSArray *outflows = [self outflows];
	for(i=0; i<[outflows count]; i++) {
		[[outflows objectAtIndex:i] dump];
	}
}

- (void) dealloc
{
//	printf("EXPStateElement - (void) dealloc\n");
	[_inflows release];
	[_outflows release];
	[super dealloc];
}

@end