Program Listing for File applicator.hpp

Return to documentation for file (cosm/interactors/applicator.hpp)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include "rcppsw/ds/type_map.hpp"
#include "rcppsw/types/timestep.hpp"

#include "cosm/cosm.hpp"

/*******************************************************************************
 * Namespaces/Decls
 ******************************************************************************/
namespace cosm::interactors {

/*******************************************************************************
 * Class Definitions
 ******************************************************************************/
template <class TBaseController,
          template <class TDerivedController, class...>
          class TInteractor,
          class... Args>
class applicator {
 public:
  applicator(TBaseController* const controller, const rtypes::timestep& t)
      : mc_timestep(t), m_controller(controller) {}

  /* Not move/copy constructable/assignable by default */
  applicator(const applicator&) = delete;
  const applicator& operator=(const applicator&) = delete;
  applicator(applicator&&) = delete;
  applicator& operator=(applicator&&) = delete;

  template <typename TDerivedController>
  auto operator()(TInteractor<TDerivedController, Args...>& interactor) const
      -> decltype(interactor(std::declval<TDerivedController&>(),
                             std::declval<const rtypes::timestep&>())) {
    return interactor(*static_cast<TDerivedController*>(m_controller),
                      mc_timestep);
  }

 private:
  /* clang-format off */
  const rtypes::timestep mc_timestep;

  TBaseController* const m_controller;
  /* clang-format on */
};

} /* namespace cosm::interactors */