//
// 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.
//
// 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 _NUMBER_H
#define _NUMBER_H

#include "../INumericExp.h"

namespace planning
{
  /// <summary>
  /// A number is an invariable numeric expression.
  /// </summary>
  class Number : public INumericExp
  {
  public:
    /// <summary>
    /// Creates a new number with the specified value.
    /// </summary>
    /// <param name="value">The value of the number.</param>
    Number(double value)
      : m_value(value)
    {
      _setHashCode(_calculateHashCode());
    }

    virtual double evaluate(const IClosedWorld* world, const Bindings* bindings) const
    {
      unused(world);
      unused(bindings);

      return m_value;
    }

  protected:
    virtual void _output(std::ostream& out) const
    {
      out << m_value;
    }

    virtual size_t _calculateHashCode() const
    {
      return size_t(m_value * 8587 + 920345);
    }

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

      return this;
    }

    virtual int _internalCompareTo(const IExp& other) const
    {
      const Number& number = dynamic_cast<const Number&>(other);

      return m_value == number.m_value;
    }

  private:
    /// <summary>
    /// The value of this number.
    /// </summary>
    const double m_value;

    Number & operator=(const Number &);
    Number(const Number &);
  };
}

#endif