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

#include "../Exp/Formula/Described/FluentApplication.h"
#include "../Utils/Utils.h"

#include <stdexcept>

namespace planning
{
  /// <summary>
  /// An UndefinedFluentException is thrown if an attempt is made to read the value
  /// of an undefined fluent (numeric or object).
  /// </summary>
  class UndefinedFluentException : public std::domain_error
  {
  public:
    /// <summary>
    /// Creates a new UndefinedFluentException with a specific fluent application.
    /// </summary>
    /// <param name="cause">The fluent application that caused the exception.</param>
    UndefinedFluentException(const FluentApplication* cause)
      : std::domain_error(buildErrorMessage(cause)), m_cause(cause)
    {
    }

    UndefinedFluentException()
      : std::domain_error("Undefined fluent"), m_cause(NULL)
    {
    }

  private:

    static std::string buildErrorMessage(const FluentApplication* cause)
    {
      std::string error = toString(cause);
      error.append(" is undefined");

      return error;
    }

    const FluentApplication* m_cause;
  };
}

#endif