//
// 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_FLUENT_H
#define _OBJECT_FLUENT_H

#include "Fluent.h"
#include "ObjectFluentApplication.h"

namespace planning
{
  /// <summary>
  /// A numeric fluent is a described formula which is associated with a numeric value.
  /// </summary>
  class ObjectFluent : public Fluent
  {
  public:
    template <class Iterator>
    ObjectFluent(const std::string& name, Type *type, Iterator argumentsBegin, 
                 Iterator argumentsEnd, Attributes attributes)
      : Fluent(name, argumentsBegin, argumentsEnd, attributes), m_type(type)
    {
      assert(m_type != NULL);
    }
    
    ObjectFluent(const std::string& name, Type *type, ObjectParameterVariable* argument, 
                 Attributes attributes)
      : Fluent(name, &argument, &argument + 1, attributes), m_type(type)
    {
      assert(m_type != NULL);
    }

    template <class Iterator>
    ObjectFluentApplication* getFormulaApplication(Iterator argumentsBegin, 
                                                   Iterator argumentsEnd) const
    {
      return dynamic_cast<ObjectFluentApplication*>(
        RootFormula::getFormulaApplication(argumentsBegin, argumentsEnd));
    }

    template <class Iterator>
    const ObjectFluentApplication* evaluateArguments(Iterator argumentsBegin,
                                                     Iterator argumentsEnd,
                                                     const IClosedWorld* world, 
                                                     const Bindings* bindings) const
    {
      return dynamic_cast<const ObjectFluentApplication*>(
        RootFormula::evaluateArguments(argumentsBegin, argumentsEnd, world, bindings));
    }

    static const TypeId UniqueTypeId;

    const Type* getType() const {
      return m_type;
    }

  protected:
    template <class TermIterator>
    ObjectFluentApplication* instantiate(TermIterator begin, TermIterator end) const
    {
      return dynamic_cast<ObjectFluentApplication*>(Fluent::instantiate(begin, end));
    }

    /// <summary>
    /// Instantiates a formula application associated with this numeric fluent.
    /// </summary>
    /// <param name="arguments">Arguments of the formula application to instantiate.</param>
    /// <returns>A new numeric fluent application associated with this numeric fluent.</returns>
    virtual ObjectFluentApplication* instantiate(const ITerm** arguments) const;

  public:
    Type* m_type;

  };
}

#endif