//
// 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
//
#ifndef _I_TERM_H
#define _I_TERM_H

#include "IExp.h"
#include "Term/Type/Type.h"

namespace planning
{
  class Object;
  class Bindings;
  class IClosedWorld;

  /// <summary>
  /// A term is an expression which yields a constant when evaluated.
  /// Evaluation in a closed world returns undefined or the resulting constant.
  /// Evaluation in an open world returns undefined, unknown, or the resulting constant.
  /// </summary>
  class ITerm : public virtual IExp // : public IEvaluableExp
  {
  public:
    const ITerm* apply(const Bindings* bindings) const
    {
      return dynamic_cast<const ITerm*>(IExp::apply(bindings));
    }

    typedef const Object* evaluated_type;

    /// <summary>
    /// Evaluates this term in the specified closed world.
    /// The bindings should not be modified by this call.
    /// </summary>
    /// <param name="world">The evaluation world.</param>
    /// <param name="bindings">A set of variable bindings.</param>
    /// <returns>Undefined, or the constant resulting from the evaluation.</returns>
    /// <exception cref="PDDLParser.Exception.BindingException">A BindingException is thrown if an attempt
    /// is made to evaluate an unbound variable.</exception>
    virtual const Object* evaluate(const IClosedWorld* world, const Bindings* bindings) const = 0;

    /// <summary>
    /// Returns the typeset of this term.
    /// </summary>
    /// <returns>This term's typeset.</returns>
    virtual const Type* getType() const = 0;
  };
}

#endif