//
// 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 and it 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.
//
// Implementation: Daniel Castonguay
// Project Manager: Froduald Kabanza
//
#ifndef _TOTAL_TIME_EXP_H
#define _TOTAL_TIME_EXP_H

#include "../INumericExp.h"
#include "../../World/IDurativeClosedWorld.h"

namespace planning
{
  /// <summary>
  /// Represents the "total-time" expression of the PDDL language.
  /// </summary>
  class TotalTimeExp : public INumericExp
  {
  public:
    static const TotalTimeExp* getInstance();

    /// <summary>
    /// Evaluates this numeric expression in the specified open 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, unknown, or the resulting numeric value.</returns>
    /// <exception cref="PDDLParser.Exception.BindingException">A BindingException is thrown if an attempt
    /// is made to evaluate an unbound variable.</exception>
    /// <exception cref="PDDLParser.Exception.NumericException">A NumericException is thrown if an 
    /// illegal operation is performed (like a division by zero).</exception>
    virtual double evaluate(const IClosedWorld* world, const Bindings* bindings) const;

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

    virtual size_t _calculateHashCode() const
    {
      return 848050;
    }

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

    virtual int _internalCompareTo(const IExp& other) const;

  private:
    static TotalTimeExp s_instance;

    /// <summary>
    /// Creates a new "total-time" expression.
    /// </summary>
    TotalTimeExp();
  };
}

#endif