EInit: move template definition to cpp file

and use explicit template instantation to generate necessary symbols.

this allows not pulling in error macros in header
This commit is contained in:
Arne Morten Kvarving 2021-04-23 14:38:18 +02:00
parent 007fdc73aa
commit 7fd4d2bd9f
2 changed files with 36 additions and 30 deletions

View File

@ -19,7 +19,6 @@
#ifndef OPM_IO_EINIT_HPP
#define OPM_IO_EINIT_HPP
#include <opm/common/ErrorMacros.hpp>
#include <opm/io/eclipse/EclFile.hpp>
#include <array>
@ -52,35 +51,7 @@ public:
protected:
template <typename T>
const std::vector<T>& ImplgetInitData(const std::string& name, const std::string& grid_name = "global")
{
int arr_ind = get_array_index(name, grid_name);
if constexpr (std::is_same_v<T, int>)
return getImpl(arr_ind, INTE, inte_array, "integer");
if constexpr (std::is_same_v<T, float>)
return getImpl(arr_ind, REAL, real_array, "float");
if constexpr (std::is_same_v<T, double>)
return getImpl(arr_ind, DOUB, doub_array, "double");
if constexpr (std::is_same_v<T, bool>)
return getImpl(arr_ind, LOGI, logi_array, "bool");
if constexpr (std::is_same_v<T, std::string>)
{
if (array_type[arr_ind] == Opm::EclIO::CHAR)
return getImpl(arr_ind, array_type[arr_ind], char_array, "char");
if (array_type[arr_ind] == Opm::EclIO::C0NN)
return getImpl(arr_ind, array_type[arr_ind], char_array, "c0nn");
OPM_THROW(std::runtime_error, "Array not of type CHAR or C0nn");
}
OPM_THROW(std::runtime_error, "type not supported");
}
const std::vector<T>& ImplgetInitData(const std::string& name, const std::string& grid_name = "global");
private:
std::array<int, 3> global_nijk;

View File

@ -157,5 +157,40 @@ std::vector<EclFile::EclEntry> EInit::list_arrays() const
return array_list;
}
template <typename T>
const std::vector<T>& EInit::ImplgetInitData(const std::string& name, const std::string& grid_name)
{
int arr_ind = get_array_index(name, grid_name);
if constexpr (std::is_same_v<T, int>)
return getImpl(arr_ind, INTE, inte_array, "integer");
if constexpr (std::is_same_v<T, float>)
return getImpl(arr_ind, REAL, real_array, "float");
if constexpr (std::is_same_v<T, double>)
return getImpl(arr_ind, DOUB, doub_array, "double");
if constexpr (std::is_same_v<T, bool>)
return getImpl(arr_ind, LOGI, logi_array, "bool");
if constexpr (std::is_same_v<T, std::string>)
{
if (array_type[arr_ind] == Opm::EclIO::CHAR)
return getImpl(arr_ind, array_type[arr_ind], char_array, "char");
if (array_type[arr_ind] == Opm::EclIO::C0NN)
return getImpl(arr_ind, array_type[arr_ind], char_array, "c0nn");
OPM_THROW(std::runtime_error, "Array not of type CHAR or C0nn");
}
OPM_THROW(std::runtime_error, "type not supported");
}
template const std::vector<int>& EInit::ImplgetInitData(const std::string& name, const std::string& grid_name);
template const std::vector<float>& EInit::ImplgetInitData(const std::string& name, const std::string& grid_name);
template const std::vector<double>& EInit::ImplgetInitData(const std::string& name, const std::string& grid_name);
template const std::vector<bool>& EInit::ImplgetInitData(const std::string& name, const std::string& grid_name);
}} // namespace Opm::EclIO