8 #ifndef CORE_MODULEMANAGER_H_
9 #define CORE_MODULEMANAGER_H_
15 #include <boost/filesystem.hpp>
96 void load(
const boost::filesystem::path& libraryPath);
104 void load(boost::dll::shared_library library);
112 std::vector<std::string> getLoadedModuleNames()
const;
115 std::vector<std::string> getLoadedInterfaces()
const;
124 template<
typename Interface>
126 return getLoadedModels(Interface::interface);
136 std::vector<std::string> getLoadedModels(
const std::string& interface)
const;
149 template<
typename Interface>
150 bool has(
const std::string& model,
const std::string& moduleName =
"")
const {
151 return has(Interface::interface, model, moduleName);
166 bool has(
const std::string& interface,
const std::string& model,
const std::string& moduleName =
"")
const;
187 template<
typename Interface>
188 std::shared_ptr<Interface>
get(
const std::string& model,
const std::string& moduleName =
"")
const {
189 auto any = _get(Interface::interface, model, moduleName);
190 assert(!any.empty() &&
"Contract of a module's get states that the any may not be empty!");
191 return boost::any_cast<std::shared_ptr<Interface>>(any);
208 template<
typename Interface,
typename UnaryPredicate>
209 std::enable_if_t<!std::is_convertible<UnaryPredicate, std::string>::value, std::shared_ptr<Interface>>
210 get(UnaryPredicate&& predicate,
const std::string& moduleName =
"")
const {
216 auto anys = _getAll(Interface::interface, moduleName);
219 throw std::runtime_error(
"There are no models of this interface loaded.");
222 for (
auto& any : anys) {
223 assert(!any.empty() &&
"Contract of a module's get states the any may not be empty!");
224 auto interfacePtr = boost::any_cast<std::shared_ptr<Interface>>(any);
225 assert(interfacePtr &&
"Contract of module's get states the wrapped pointer may not be empty!");
226 if (predicate(interfacePtr)) {
231 throw std::runtime_error(
"No model matches the supplied predicate!");
241 bool moduleLoaded(
const std::string& moduleName)
const;
263 boost::any _get(
const std::string& interface,
const std::string& model,
const std::string& moduleName =
"")
const;
277 std::vector<boost::any> _getAll(
const std::string& interface,
const std::string& moduleName =
"")
const;
282 struct LibraryAndModules;
284 static std::vector<LibraryAndModules> _sources;
static ModuleManager & getInstance()
Static instance getter.
Definition: ModuleManager.h:54
The manager for all dynamically loaded modules.
Definition: ModuleManager.h:44
bool has(const std::string &model, const std::string &moduleName="") const
Checks whether a particular model of an interface is available.
Definition: ModuleManager.h:150
std::vector< std::string > getLoadedModels() const
Announces a list of all loaded models of a particular interface.
Definition: ModuleManager.h:125