MoCSI API Reference
Loading...
Searching...
No Matches
StaticModuleContainer.h
Go to the documentation of this file.
1#ifndef STATIC_MODULE_CONTAINER_H
2#define STATIC_MODULE_CONTAINER_H
3
4#include <exception>
5#include <memory>
6#include <string>
7
9#include "GenericSubmodule.h"
10#include "ModuleFactory.h"
11#include "SimulationClassBase.h"
12
20template <typename T>
22{
23 private:
24 static inline std::vector<std::shared_ptr<GenericManagingModule<T>>> m_all_modules{};
25 static inline std::vector<std::shared_ptr<GenericSubmodule<T>>> m_all_submodules{};
26
27 // Since this is a static container, this variable denotes whether the modules are created
28 // or the vector is empty
29 static inline bool m_modules_created{false};
30
31 public:
39 {
40 try
41 {
43 sim_ptr,
44 sim_ptr->m_simulation_config.getStringVectorParameters("managing_modules"));
45 }
46 catch (const BadInput&)
47 {
49 }
50 m_all_submodules =
52 m_modules_created = true;
53 }
54
63 static bool isInitialized() { return m_modules_created; }
64
71 static std::vector<std::shared_ptr<GenericManagingModule<T>>>&
73 {
74 return m_all_modules;
75 }
76
82 static std::vector<std::shared_ptr<GenericSubmodule<T>>>& getAllSelectedSubmodules()
83 {
84 return m_all_submodules;
85 }
86
93 static std::shared_ptr<GenericManagingModule<T>> getSelectedManagingModule(
94 const std::string& key)
95 {
96 for (auto& module_ptr : m_all_modules)
97 {
98 if (key == module_ptr->getNameLocal())
99 {
100 return module_ptr;
101 }
102 }
103 std::cerr << "[StaticModuleContainer]: Requested managing module is not loaded, please "
104 "make sure it was loaded!";
105 throw std::runtime_error(
106 "[StaticModuleContainer]: Requested managing module is not loaded, please make "
107 "sure it was loaded!");
108 }
109
116 static std::shared_ptr<GenericSubmodule<T>> getSelectedSubmodule(const std::string& key)
117 {
118 for (auto& submodule_ptr : m_all_submodules)
119 {
120 if (key == submodule_ptr->getNameLocal())
121 {
122 return submodule_ptr;
123 }
124 }
125 std::cerr << "[StaticModuleContainer]: Requested submodule is not loaded, please make "
126 "sure it was loaded!";
127 throw std::runtime_error(
128 "[StaticModuleContainer]: Requested submodule is not loaded, please make sure it "
129 "was loaded!");
130 }
131};
132#endif
This error class inherits from std::exception and marks faulty parameter or CL inputs....
Definition IniParser.h:71
Concrete implementation of a matrix class representing a Compressed Sparse Rows (CSR) matrix....
Definition CsrMatrix.h:35
static std::vector< std::shared_ptr< GenericManagingModule< T > > > createAllSelectedManagingModules(SimulationClassBase< T > *sim_pointer, const std::vector< std::string > &list_of_mananging_modules_to_load)
Only creates instances of managing modules that have been specified by the user. (This allows only ha...
Definition ModuleFactory.h:195
static std::vector< std::shared_ptr< GenericSubmodule< T > > > createAllSelectedSubmodules(SimulationClassBase< T > *sim_pointer, const std::vector< std::shared_ptr< GenericManagingModule< T > > > &loaded_managing_modules)
Only creates submodules that are used within the simulation. Iteratively requests the submodule list ...
Definition ModuleFactory.h:224
static std::vector< std::shared_ptr< GenericManagingModule< T > > > createAllManagingModules(SimulationClassBase< T > *sim_pointer)
Creates every module in the module registry.
Definition ModuleFactory.h:153
Class that creates all modules and allows access to the module pointers in static contexts....
Definition StaticModuleContainer.h:22
static std::vector< std::shared_ptr< GenericSubmodule< T > > > & getAllSelectedSubmodules()
Get all selected submodules (static).
Definition StaticModuleContainer.h:82
static std::shared_ptr< GenericManagingModule< T > > getSelectedManagingModule(const std::string &key)
Get a specified managing module.
Definition StaticModuleContainer.h:93
StaticModuleContainer(SimulationClassBase< T > *sim_ptr)
Construct a new Static Module Container object. Also creates all modules (all selected modules as soo...
Definition StaticModuleContainer.h:38
static std::vector< std::shared_ptr< GenericManagingModule< T > > > & getAllSelectedManagingModules()
Get all selected managing modules (static).
Definition StaticModuleContainer.h:72
static std::shared_ptr< GenericSubmodule< T > > getSelectedSubmodule(const std::string &key)
Get the specified submodule.
Definition StaticModuleContainer.h:116
static bool isInitialized()
Getter function for the m_modules_created boolean. Is set to true, if this module has been created (o...
Definition StaticModuleContainer.h:63