//
// 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: Simon Chamberland
// Project Manager: Froduald Kabanza
//

#include "stdafx.h"
#include "TotalTimeExp.h"

using namespace planning;

TotalTimeExp TotalTimeExp::s_instance;

/// <summary>
/// Creates a new "total-time" expression.
/// </summary>
TotalTimeExp::TotalTimeExp()
{
  _markAsStatic();
  _setHashCode(_calculateHashCode());
}

/// <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>
double TotalTimeExp::evaluate(const IClosedWorld* world, const Bindings* bindings) const
{
  const IDurativeClosedWorld* durativeWorld = dynamic_cast<const IDurativeClosedWorld*>(world);
  assert(durativeWorld != NULL);
  return durativeWorld->getTime();
}

void TotalTimeExp::_output(std::ostream& out) const
{
  out << "total-time";
}

const IExp* TotalTimeExp::_internalApply(const Bindings* bindings) const
{
  return this;
}

int TotalTimeExp::_internalCompareTo(const IExp& other) const
{
  return 0;
}
