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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# CLion folders
/.idea
/cmake-build-*

# guided_examples products
/docs/guided_examples/*/build*
/docs/guided_examples/flake.lock

# Avoid adding symlinks
/support/ides/clion/*

# Products of SimoSim
Simo.log
statistics.yaml

*.DS_Store
9 changes: 8 additions & 1 deletion include/Simo/module/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ class SIMO_PUBLIC Module {

Log::Logger& get_logger() { return logger; }

protected:
/// Create a new statistic of type T
template <typename T, typename... Args>
T& create_statistic(Args... args) {
Expand All @@ -179,8 +178,16 @@ class SIMO_PUBLIC Module {
return out_ref;
}

template <typename T, typename... Args>
T& create_child(Args... args) {
children.emplace_back(std::make_unique<T>(std::forward<Args>(args)...));
return *children.back();
}

protected:
Statistics::StatStorage statistics;
std::unordered_map<std::string, std::unique_ptr<Port>> ports;
std::vector<std::unique_ptr<Module>> children;
Log::Logger logger;

private:
Expand Down
9 changes: 7 additions & 2 deletions tests/module/ModuleTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,17 @@ BOOST_AUTO_TEST_CASE(StdoutLogSetupEnablesLogger) {
BOOST_CHECK_EQUAL(logger.enabled(), true);
}

BOOST_AUTO_TEST_CASE(NameOfChild) {
BOOST_AUTO_TEST_CASE(ModuleChild) {
Simo::Context ctx;
Simo::Parameters p;
Simo::Module m;
p.name("root");
const auto status = m.initialize(ctx, p);
auto& child = m.create_child<Simo::Module>();
auto child_name = m.name_of_child("child");
BOOST_CHECK_EQUAL(child_name, "root/child");
Simo::Parameters p_child;
p_child.name(child_name);
auto child_status = child.initialize(ctx, p_child);
BOOST_CHECK_EQUAL(child_status.success(), true);
BOOST_CHECK_EQUAL(p_child.name(), "root/child");
}