Skip to content

Commit

Permalink
Return installed reactor (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bidski authored Oct 5, 2023
1 parent b584fa4 commit 5b198ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/PowerPlant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ class PowerPlant {
*
* @tparam T The type of the reactor to build and install
* @tparam level The initial logging level for this reactor to use
*
* @return A reference to the installed reactor
*/
template <typename T>
void install();
T& install();

/**
* @brief Generic submit function for submitting tasks to the thread pool.
Expand Down
4 changes: 3 additions & 1 deletion src/PowerPlant.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ inline PowerPlant::PowerPlant(Configuration config, int argc, const char* argv[]
}

template <typename T>
void PowerPlant::install() {
T& PowerPlant::install() {

// Make sure that the class that we received is a reactor
static_assert(std::is_base_of<Reactor, T>::value, "You must install Reactors");

// The reactor constructor should handle subscribing to events
reactors.push_back(std::make_unique<T>(std::make_unique<Environment>(*this, util::demangle(typeid(T).name()))));

return static_cast<T&>(*reactors.back());
}

// Default emit with no types
Expand Down

0 comments on commit 5b198ee

Please sign in to comment.