//
// Copyright (c) 2009 Froduald Kabanza and the Université de Sherbrooke.
// Use of this software is permitted for non-commercial research purposes, and
// it may be copied or applied only for that use. All copies must include this
// copyright message.
// 
// This is a research prototype that has not gone through intensive tests and
// is delivered as is. It may still contain bugs. Froduald Kabanza and the
// Université de Sherbrooke disclaim any responsibility for damage that may be
// caused by using it.
//
// Please note that some files were inspired in part by the PDDL4J library:
// http://www.math-info.univ-paris5.fr/~pellier/software/software.php 
//
// Implementation: Simon Chamberland
// Project Manager: Froduald Kabanza
//

#include "stdafx.h"
#include "FunctionExp.h"

using namespace planning;

double FunctionExp::evaluate(const IClosedWorld* world, const Bindings* bindings) const
{
  return calculate(evaluated_argument_const_iterator(m_arguments.begin(), EvaluateExpression<INumericExp>(world, bindings)),
                   evaluated_argument_const_iterator(m_arguments.end(), EvaluateExpression<INumericExp>(world, bindings)));   
}

//size_t FunctionExp::getArity() const
//{
//  return m_arguments.size();
//}

void FunctionExp::_output(std::ostream& out) const
{
  out << "(" << m_image;
  for (const_iterator it = m_arguments.begin();
       it != m_arguments.end();
       ++it)
  {
    out << " " << **it;
  }
  out << ")";
}

int FunctionExp::_internalCompareTo(const IExp& other) const
{
  const FunctionExp& exp = dynamic_cast<const FunctionExp&>(other);

  COMPARE(m_arguments, exp.m_arguments);

  return 0;
}
