/*
** SellaNMS
** $Id: format_statement.cxx,v 1.5 2005/05/21 23:10:28 sella Exp $
** Copyright (c) 2001-2005 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

static char rcsid[] = "$Id: format_statement.cxx,v 1.5 2005/05/21 23:10:28 sella Exp $";

#include "format_statement.h"
#include "format_statement_term.h"

FormatStatement::FormatStatement() {
	Statement::Statement();

	this->setType("format-statement");
}

FormatStatement::FormatStatement(Statement const &src) {
	*this = src;
}

FormatStatement::FormatStatement(FormatStatement const &src) {
	*this = src;
}

FormatStatement::~FormatStatement() {
}

Statement const& FormatStatement::operator=(Statement const &src) {
	FormatStatement *real_src = (FormatStatement*) &src;
	
	return operator=(*real_src);
}

FormatStatement const& FormatStatement::operator=(FormatStatement const &src) {
	Statement::operator=(src);

	return *this;
}

Term *FormatStatement::getNewStatementTerm() const {
	return new FormatStatementTerm();
}

/*
 *	Get the names of the map-statements applied to this format-statement.
 *
 *	  Parameters
 *     map_names:  the names of the map-statements applied to this format-statement.
 *
 *   Return Values
 *     SUCCESS: if the map-statement names were successfully returned.
 *     FAILURE: if the map-statement names were not returned.
 */
RESULT FormatStatement::getAppliedMapStatements(slist<string> &map_names) {
	RESULT result = SUCCESS;

	for (slist<Term *>::iterator t = this->terms.begin(); t != this->terms.end(); ++t) {
		if (((FormatStatementTerm *)(*t))->getAppliedMapStatements(map_names) != SUCCESS) {
			result = FAILURE;
		}
	}
	map_names.sort();
	map_names.unique();

	return result;
}

RESULT FormatStatement::setVariableType(unsigned long &type, string &variable) {
	RESULT result = FAILURE;

	for (slist<Term *>::const_iterator t = this->terms.begin(); t != this->terms.end(); ++t) {
		if (((FormatStatementTerm *)(*t))->setVariableType(type, variable) == SUCCESS) {
			result = SUCCESS;
		}
	}

	return result;	
}

RESULT FormatStatement::setVariableFunction(unsigned long &function, string &variable) {
	RESULT result = FAILURE;

	for (slist<Term *>::const_iterator t = this->terms.begin(); t != this->terms.end(); ++t) {
		if (((FormatStatementTerm *)(*t))->setVariableFunction(function, variable) == SUCCESS) {
			result = SUCCESS;
		}
	}

	return result;	
}

/* ADDED */
RESULT FormatStatement::setVariableMap(slist<string> &mapStatements, string &variable) {
	RESULT result = FAILURE;

	for (slist<Term *>::const_iterator t = this->terms.begin(); t != this->terms.end(); ++t) {
		if (((FormatStatementTerm *)(*t))->setVariableMap(mapStatements, variable) == SUCCESS) {
			result = SUCCESS;
		}
	}

	return result;	
}

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim600: fdm=marker
** vim: noet ts=3 sw=3 sts=3
*/
