//
// 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
//

#include "stdafx.h"
#include "AndEffect.h"
#include "../../World/IDurativeClosedWorld.h"
#include "../UnaryFunctions.h"

#include <assert.h>

using namespace planning;

const std::string AndEffect::s_image = "and";

/// <summary>
/// Updates the specified world with this effect.
/// A conjunction of effects sequentially updates the world with each internal effect.
/// </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>
void AndEffect::update(const IClosedWorld* evaluationWorld, 
                       IDurativeClosedWorld* updateWorld, 
                       const Bindings* bindings, 
                       const ActionContext* actionContext) const
{
  for (const_iterator it = m_elements.begin(); 
       it != m_elements.end();
       ++it)
  {
    (*it)->update(evaluationWorld, updateWorld, bindings, actionContext);
  }
}


const IExp* AndEffect::_internalApply(const Bindings* bindings) const
{
  return new AndEffect(m_elements.size(),
                       boost::transform_iterator<ApplyBindings<IEffect>, const_iterator>(m_elements.begin(), bindings), 
                       boost::transform_iterator<ApplyBindings<IEffect>, const_iterator>(m_elements.end(), bindings));
}
