Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/pluginplay/module/module_class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,14 @@ bool Module::ready() const {
template<typename T>
void Module::change_input(const type::key& key, T&& value) {
assert_not_locked_();
if(!inputs().count(key)) {
std::string msg = " does not have input \"" + key + "\"";
if(has_name())
msg = "Module \"" + get_name() + "\"" + msg;
else
msg = "Unnamed module" + msg;
throw std::out_of_range(msg);
}
get_input_(key).change(std::forward<T>(value));
}

Expand Down
8 changes: 7 additions & 1 deletion include/pluginplay/module_manager/module_manager_class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ class ModuleManager {
*/
type::size size() const noexcept;

/** @brief Used to add a new module to the list
*
* @tparam ModuleType The type of the module being added. This type must be
* constructible with no arguments and must inherit from
* ModuleBase.
* @param module_key
*/
template<typename ModuleType>
void add_module(type::key module_key);

Expand All @@ -108,7 +115,6 @@ class ModuleManager {
* @param module_key
* @param base
*/

void add_module(type::key module_key, module_base_ptr base);

///@{
Expand Down
8 changes: 8 additions & 0 deletions src/pluginplay/module/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ void Module::lock() { m_pimpl_->lock(); }

void Module::change_submod(type::key key, std::shared_ptr<Module> new_module) {
assert_not_locked_();
if(!submods().count(key)) {
std::string msg = " does not have submodule \"" + key + "\"";
if(has_name())
msg = "Module \"" + get_name() + "\"" + msg;
else
msg = "Unnamed module" + msg;
throw std::out_of_range(msg);
}
m_pimpl_->submods().at(key).change(new_module);
}

Expand Down
1 change: 1 addition & 0 deletions tests/cxx/unit_tests/pluginplay/catch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
#include <catch2/catch_approx.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_exception.hpp>
16 changes: 13 additions & 3 deletions tests/cxx/unit_tests/pluginplay/module/module_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@ TEST_CASE("Module : change_input") {
}
SECTION("Throws if input does not exist") {
auto mod = make_module<NotReadyModule>();
REQUIRE_THROWS_AS(mod->change_input("Not a key", 3), std::out_of_range);
REQUIRE_THROWS_WITH(mod->change_input("Not a key", 3),
"Unnamed module does not have input \"Not a key\"");
mod->set_name("Test");
REQUIRE_THROWS_WITH(
mod->change_input("Not a key", 3),
"Module \"Test\" does not have input \"Not a key\"");
}
SECTION("Throws if value is wrong type") {
auto mod = make_module<NotReadyModule>();
Expand All @@ -316,8 +321,13 @@ TEST_CASE("Module : change_submod") {
REQUIRE_THROWS_AS(p.change_submod(key, value), std::runtime_error);
}
SECTION("Throws if request does not exist") {
REQUIRE_THROWS_AS(mod->change_submod("Not a key", value),
std::out_of_range);
REQUIRE_THROWS_WITH(
mod->change_submod("Not a key", value),
"Unnamed module does not have submodule \"Not a key\"");
mod->set_name("Test");
REQUIRE_THROWS_WITH(
mod->change_submod("Not a key", value),
"Module \"Test\" does not have submodule \"Not a key\"");
}
SECTION("Throws if value is wrong type") {
auto mod2 = make_module<NotReadyModule>();
Expand Down
Loading