Skip to content
Snippets Groups Projects
Select Git revision
  • 3a5b28168fb1009d59712fbfd13b36a841e8fdf3
  • develop default protected
  • feature/variational-hydro
  • origin/stage/bouguettaia
  • feature/gmsh-reader
  • feature/reconstruction
  • save_clemence
  • feature/kinetic-schemes
  • feature/local-dt-fsi
  • feature/composite-scheme-sources
  • feature/composite-scheme-other-fluxes
  • feature/serraille
  • feature/composite-scheme
  • hyperplastic
  • feature/polynomials
  • feature/gks
  • feature/implicit-solver-o2
  • feature/coupling_module
  • feature/implicit-solver
  • feature/merge-local-dt-fsi
  • master protected
  • v0.5.0 protected
  • v0.4.1 protected
  • v0.4.0 protected
  • v0.3.0 protected
  • v0.2.0 protected
  • v0.1.0 protected
  • Kidder
  • v0.0.4 protected
  • v0.0.3 protected
  • v0.0.2 protected
  • v0 protected
  • v0.0.1 protected
33 results

FunctionArgumentConverter.hpp

Blame
  • FunctionArgumentConverter.hpp 1.22 KiB
    #ifndef FUNCTION_ARGUMENT_CONVERTER_HPP
    #define FUNCTION_ARGUMENT_CONVERTER_HPP
    
    #include <DataVariant.hpp>
    #include <node_processor/ExecutionPolicy.hpp>
    
    class IFunctionArgumentConverter
    {
     public:
      virtual DataVariant convert(ExecutionPolicy& exec_policy, DataVariant&& value) = 0;
    
      virtual ~IFunctionArgumentConverter() = default;
    };
    
    template <typename ExpectedValueType, typename ProvidedValueType>
    class FunctionArgumentConverter final : public IFunctionArgumentConverter
    {
     private:
      size_t m_argument_id;
    
     public:
      DataVariant
      convert(ExecutionPolicy& exec_policy, DataVariant&& value)
      {
        if constexpr (std::is_same_v<ExpectedValueType, ProvidedValueType>) {
          exec_policy.currentContext()[m_argument_id] = std::move(value);
        } else if constexpr (std::is_same_v<ExpectedValueType, std::string>) {
          exec_policy.currentContext()[m_argument_id] = std::move(std::to_string(std::get<ProvidedValueType>(value)));
        } else {
          exec_policy.currentContext()[m_argument_id] =
            std::move(static_cast<ExpectedValueType>(std::get<ProvidedValueType>(value)));
        }
        return {};
      }
    
      FunctionArgumentConverter(size_t argument_id) : m_argument_id{argument_id} {}
    };
    
    #endif   // FUNCTION_ARGUMENT_CONVERTER_HPP