/*
** SellaNMS
** $Id: policy_statement_term.cxx,v 1.7 2005/12/01 05:57:59 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 const char rcsid[] = "$Id: policy_statement_term.cxx,v 1.7 2005/12/01 05:57:59 sella Exp $";

#include "policy_statement_term.h"
#include "policy_statement_from.h"
#include "policy_statement_then.h"

PolicyStatementTerm::PolicyStatementTerm() {
}

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

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

PolicyStatementTerm::~PolicyStatementTerm() {
}

Term const& PolicyStatementTerm::operator=(Term const &src) {
	PolicyStatementTerm *real_src = (PolicyStatementTerm*) &src;

	return operator=(*real_src);
}

PolicyStatementTerm const& PolicyStatementTerm::operator=(PolicyStatementTerm const &src) {
	/* Wipe object. */
	this->clear();
	Term::clear();

	/* Parent first. */
	Term::operator=(src);

	/* Do object specifics. */
	return *this;
}

RESULT PolicyStatementTerm::getAppliedMapStatements(slist<string> &map_names) {
	RESULT result = SUCCESS;

	if (this->from != NULL) {
		if (((PolicyStatementFrom *)(this->from))->getAppliedMapStatements(map_names) != SUCCESS) {
			result = FAILURE;
		}
	}
	if (this->then != NULL) {
		if (((PolicyStatementThen *)(this->then))->getAppliedMapStatements(map_names) != SUCCESS) {
			result = FAILURE;
		}
	} else {
		LMSG("WARNING: term %s has no then clause.", this->getName().c_str());
	}
	return result;
}

RESULT PolicyStatementTerm::setCompiledStatements(hash_map<string, PolicyStatement> *policies, hash_map<string, MapStatement> *maps) {
	RESULT result = SUCCESS;

	if (this->from != NULL) {
		if ((((PolicyStatementFrom *)(this->from))->setCompiledStatements(policies, maps)) != SUCCESS) {
			result = FAILURE;
		}
	}

	if (this->then != NULL) {
		if (((PolicyStatementThen *)(this->then))->setCompiledStatements(policies, maps) != SUCCESS) {
			result = FAILURE;
		}
	}
	return result;
}

From *PolicyStatementTerm::getNewFromClause() const {
	return new PolicyStatementFrom();
}

Then *PolicyStatementTerm::getNewThenClause() const {
	return new PolicyStatementThen();
}

RESULT PolicyStatementTerm::getReferencedVariables(slist<variable_t> &referenced) {
	RESULT result = SUCCESS;

	if (this->from) {
		result = ((PolicyStatementFrom *)(this->from))->getReferencedVariables(referenced);
	}
	// TODO: then clause formatting

	return result;
}

RESULT PolicyStatementTerm::applyFormatStatement(FormatStatement &format) {
	RESULT result = SUCCESS;

	if (this->from) {
		result = ((PolicyStatementFrom *)(this->from))->applyFormatStatement(format);
	}
	// TODO: then clause formatting

	if (result == FAILURE) {
		LMSG("Policy: syntax error in term %s.", this->getName().c_str());
	}
	return result;
}

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