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

#include "../QuantifiedExp.h"
#include "../IEffect.h"

namespace planning
{
  /// <summary>
  /// This class represents a universally quantified effect.
  /// </summary>
  class ForallEffect : public QuantifiedExp<IEffect>
  {
  public:
    /// <summary>
    /// Creates a new universally quantified effect.
    /// </summary>
    /// <param name="vars">The quantified variables.</param>
    /// <param name="body">The body of the quantified effect.</param>
    template <class Iterator>
    ForallEffect(Iterator variablesBegin, Iterator variablesEnd, const IEffect* body)
      : QuantifiedExp<IEffect>(s_image, variablesBegin, variablesEnd, body)
    {
      INITIALIZE_HASH_CODE();
    }
    
    /// <summary>
    /// Updates the specified world with this effect.
    /// A universal effect updates the world for all substitutions of its quantified variables.
    /// </summary>
    /// <param name="evaluationWorld">The world to evaluate conditions against.</param>
    /// <param name="updateWorld">The world to update.</param>
    /// <param name="bindings">A set of variable bindings.</param>
    /// <param name="actionContext">The action evaluation context.</param>
    virtual void update(const IClosedWorld* evaluationWorld, 
                        IDurativeClosedWorld* updateWorld, 
                        const Bindings* bindings, 
                        const ActionContext* actionContext) const;

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

    virtual size_t _calculateHashCode() const
    {
      return CALCULATE_HASH_CODE(QuantifiedExp)
           + 88102003;
    }

    virtual IEffect* _generateGroundExp() const;

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

  private:
    static const std::string s_image;

    ///// <summary>
    ///// Creates an expression equivalent to this universally quantified effect.
    ///// </summary>
    ///// <returns>An expression equivalent to this universally quantified effect.</returns>
    //protected override IEffect GenerateEquivalentExp()
    //{
    //  return new AndEffect(GetBodySubstitutions());
    //}

    ///// <summary>
    ///// Retrieves all the described formulas modified by this effect.
    ///// </summary>
    ///// <returns>All the described formulas modified by this effect.</returns>
    //public HashSet<DescribedFormula> GetModifiedDescribedFormulas()
    //{
    //  return this.GetEquivalentExp().GetModifiedDescribedFormulas();
    //}
  };
}

#endif