//
// 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 _OBJECT_PARAMETER_VARIABLE_H
#define _OBJECT_PARAMETER_VARIABLE_H

#include "../ITerm.h"

#include <string>
#include <assert.h>

namespace planning
{
  /// <summary>
  /// An object parameter variable is a parameter variable which must be assigned a constant value.
  /// </summary>
  class ObjectParameterVariable : public ITerm // : ParameterVariable, ObjectVariable
  {
  public:
    /// <summary>
    /// Creates a new object parameter variable with the specified name and typeset.
    /// </summary>
    /// <param name="name">The name of the new parameter variable.</param>
    /// <param name="typeSet">The typeset of the new parameter variable.</param>
    ObjectParameterVariable(const std::string& name, Type* 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;

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

    typedef Type::object_const_iterator object_const_iterator;

    object_const_iterator domainBegin() const
    {
      return m_type->domainBegin();
    }

    object_const_iterator domainEnd() const
    {
      return m_type->domainEnd();
    }

  protected:
    virtual void _output(std::ostream& out) const;

    virtual size_t _calculateHashCode() const
    {
      return reinterpret_cast<size_t>(this);
    }

    virtual const IExp* _internalApply(const Bindings* bindings) const;

    virtual int _internalCompareTo(const IExp& other) const;

  private:
    const std::string m_name;

    Type* m_type;
    
    //Const member prevent the use of the assignement operator
    ObjectParameterVariable& operator=(const ObjectParameterVariable&);

    ///// <summary>
    ///// Evaluates this term in the specified open world.
    ///// An object parameter variable evaluates to the constant to which it is bound.
    ///// </summary>
    ///// <param name="world">The evaluation world.</param>
    ///// <param name="bindings">A set of variable bindings.</param>
    ///// <returns>The constant to which this variable is bound.</returns>
    //public override FuzzyConstantExp Evaluate(IReadOnlyOpenWorld world, ILocalBindings bindings)
    //{
    //  return new FuzzyConstantExp(bindings.GetBinding(this));
    //}

    ///// <summary>
    ///// Simplifies this term by evaluating its known expression parts.
    ///// An object parameter variable simplifies to the constant to which it is bound.
    ///// </summary>
    ///// <param name="world">The evaluation world.</param>
    ///// <param name="bindings">A set of variable bindings.</param>
    ///// <returns>The constant to which this variable is bound.</returns>
    //public override TermValue Simplify(IReadOnlyOpenWorld world, ILocalBindings bindings)
    //{
    //  return new TermValue(bindings.GetBinding(this));
    //}

    ///// <summary>
    ///// Evaluates this term in the specified closed world.
    ///// An object parameter variable evaluates to the constant to which it is bound.
    ///// </summary>
    ///// <param name="world">The evaluation world.</param>
    ///// <param name="bindings">A set of variable bindings.</param>
    ///// <returns>The constant to which this variable is bound.</returns>
    //public override ConstantExp Evaluate(IReadOnlyClosedWorld world, ILocalBindings bindings)
    //{
    //  return new ConstantExp(bindings.GetBinding(this));
    //}

    ///// <summary>
    ///// Substitutes all occurrences of the variables that occur in this
    ///// expression by their corresponding bindings.
    ///// </summary>
    ///// <param name="bindings">A set of variable bindings.</param>
    ///// <returns>A substituted copy of this expression.</returns>
    //public override IExp Apply(IParameterBindings bindings)
    //{
    //  Constant binding;
    //  if (bindings.TryGetBinding(this, out binding))
    //  {
    //    return binding;
    //  }
    //  else
    //  {
    //    return this;
    //  }
    //}

    ///// <summary>
    ///// Returns true if this variable is free, false it is bound.
    ///// </summary>
    ///// <returns>Whether this variable is free.</returns>
    //public override bool IsFree()
    //{
    //  return this.m_isFree;
    //}

    //#region IComparable<ObjectParameterVariable> Members

    ///// <summary>
    ///// Compares this object parameter variable with another object parameter variable.
    ///// </summary>
    ///// <param name="other">The other variable to compare this variable to.</param>
    ///// <returns>An integer representing the total order relation between the two variables.
    ///// </returns>
    //public int CompareTo(ObjectParameterVariable other)
    //{
    //  return this.m_name.CompareTo(other.m_name);
    //}

    //#endregion
  };
}

#endif