12#include "vipra/logging/logging.hpp"
13#include "vipra/modules.hpp"
14#include "vipra/special_modules/parameters.hpp"
18template <
typename module_t>
20 std::unique_ptr<std::remove_cvref_t<module_t>> module;
24template <
typename module_t>
25inline auto load_module(std::string
const& name, std::string
const& installDir,
28 using mod_t = std::remove_cvref_t<module_t>;
29 using make_module_t = mod_t* (*)();
34 if ( type == Modules::Type::PedInput || type == Modules::Type::MapInput )
35 path = installDir +
"/input/lib" + name +
".so";
37 path = installDir +
'/' + Modules::to_string(type) +
"/lib" + name +
".so";
39 if ( ! std::filesystem::exists(path) ) {
41 throw std::runtime_error(
"Module Not Found");
46 void* module = dlopen(path.c_str(), RTLD_LAZY);
48 if ( module ==
nullptr ) {
49 std::cerr <<
"module not found at: " << path <<
'\n';
51 throw std::runtime_error(
"Unable to load module");
55 auto func =
reinterpret_cast<make_module_t
>(dlsym(module,
"create_module"));
56 auto configFunc =
reinterpret_cast<config_module_t
>(dlsym(module,
"setup_module"));
59 if ( func ==
nullptr ) {
60 std::cerr <<
"create_module not found in: " << path <<
'\n';
61 throw std::runtime_error(
"Module Missing VIPRA_REGISTER_MODULE");
64 if ( configFunc ==
nullptr ) {
65 std::cerr <<
"setup_module not found in: " << path <<
'\n';
66 throw std::runtime_error(
"Module Missing VIPRA_REGISTER_MODULE");
71 std::unique_ptr<mod_t> mod;
76 std::cerr <<
"Module not created, Error thrown in Module Construction\n";
77 throw std::runtime_error(
"Unable to create Module");
80 if ( mod.get() ==
nullptr ) {
81 std::cerr <<
"Module not created\n";
82 throw std::runtime_error(
"Unable to create Module");
89 std::function<void(void*, Parameters&, VIPRA::Random::Engine&)>(configFunc)};
static VIPRA_INLINE void error(fmt::format_string< param_ts... > message, param_ts &&... params)
Calls the provided Logger with Level DEBUG.
Definition logging.hpp:102
static VIPRA_INLINE void debug(fmt::format_string< param_ts... > message, param_ts &&... params)
Calls the provided Logger with Level DEBUG.
Definition logging.hpp:85
Definition parameters.hpp:20
Psuedo Random number engine.
Definition random.hpp:22
Definition module_loading.hpp:19