//===-- deluxe/DeluxeExecutionPolicy.cpp ------------------------*- C++ -*-===//
//
//                                 The RoSA Framework
//
// Distributed under the terms and conditions of the Boost Software License 1.0.
// See accompanying file LICENSE.
//
// If you did not receive a copy of the license file, see
// http://www.boost.org/LICENSE_1_0.txt.
//
//===----------------------------------------------------------------------===//
///
/// \file deluxe/DeluxeExecutionPolicy.cpp
///
/// \author David Juhasz (david.juhasz@tuwien.ac.at)
///
/// \date 2019
///
/// \brief Implementation for rosa/deluxe/DeluxeExecutionPolicy.h.
///
//===----------------------------------------------------------------------===//

#include "rosa/deluxe/DeluxeExecutionPolicy.h"
#include "rosa/deluxe/DeluxeSystem.hpp"

#include "executionpolicies/Decimation.h"
#include "executionpolicies/AwaitAll.h"
#include "executionpolicies/AwaitAny.h"

namespace rosa {
namespace deluxe {

std::unique_ptr<DeluxeExecutionPolicy>
DeluxeExecutionPolicy::decimation(const size_t D) {
  return std::unique_ptr<DeluxeExecutionPolicy>(new Decimation(D));
}

std::unique_ptr<DeluxeExecutionPolicy>
DeluxeExecutionPolicy::awaitAll(const std::set<size_t> &S) {
  return std::unique_ptr<DeluxeExecutionPolicy>(new AwaitAll(S));
}

std::unique_ptr<DeluxeExecutionPolicy>
DeluxeExecutionPolicy::awaitAny(const std::set<size_t> &S) {
  return std::unique_ptr<DeluxeExecutionPolicy>(new AwaitAny(S));
}

bool DeluxeExecutionPolicy::isDeluxeAgent(const AgentHandle H, const DeluxeSystem &S) const noexcept {
  return S.isDeluxeAgent(H);
}

size_t DeluxeExecutionPolicy::numberOfDeluxeAgentInputs(
    const AgentHandle H, const DeluxeSystem &S) const noexcept {
  auto A = S.getDeluxeAgent(H);
  return A ? A->NumberOfInputs : 0;
}

} // End namespace deluxe
} // End namespace rosa

namespace std {

string to_string(const rosa::deluxe::DeluxeExecutionPolicy &EP) {
  return EP.dump();
}

ostream &operator<<(ostream &OS,
                    const rosa::deluxe::DeluxeExecutionPolicy &EP) {
  OS << to_string(EP);
  return OS;
}

} // End namespace std
