/*! * \file CyclopsModules.h * \date 2019/11/05 * * \author Lin, Chi * Contact: lin.chi@hzleaper.com * * * \note */ #ifndef __CyclopsModules_h_ #define __CyclopsModules_h_ #include "CyclopsCommon.h" #include "CyclopsVersion.h" #include class ICyclopsModule; class ICyclopsModuleInstance { public: virtual ~ICyclopsModuleInstance() = 0; typedef std::shared_ptr Ptr; }; class CyclopsModules { public: static bool registerModule(const char* moduleName, ICyclopsModule* moduleFactory); static ICyclopsModule* getModule(const char* moduleName); static CYCLOPS_DLLSPEC ICyclopsModuleInstance::Ptr getManagedInstance(const char* moduleName, const char* instanceName); static CYCLOPS_DLLSPEC bool deleteManagedInstance(const char* moduleName, const char* instanceName); static CYCLOPS_DLLSPEC bool updateManagedInstance(const char* moduleName, const char* instanceName, ICyclopsModuleInstance::Ptr newInstance); static CYCLOPS_DLLSPEC ICyclopsModuleInstance::Ptr getStandaloneInstance(const char* moduleName); }; #include template inline std::shared_ptr GetModuleInstance(const std::string& instanceName) { #ifdef CYCLOPS_LIB return T::getInstance(instanceName); #else return std::dynamic_pointer_cast(CyclopsModules::getManagedInstance( typeid(T).name(), instanceName.c_str())); #endif // CYCLOPS_LIB } template inline bool DeleteModuleInstance(const std::string& instanceName) { #ifdef CYCLOPS_LIB return T::deleteInstance(instanceName); #else return CyclopsModules::deleteManagedInstance(typeid(T).name(), instanceName.c_str()); #endif // CYCLOPS_LIB } template inline bool UpdateModuleInstance(const std::string& instanceName, std::shared_ptr newInstance) { #ifdef CYCLOPS_LIB return T::updateInstance(instanceName); #else return CyclopsModules::updateManagedInstance(typeid(T).name(), instanceName.c_str(), std::static_pointer_cast(newInstance)); #endif // CYCLOPS_LIB } template inline std::shared_ptr GetModuleInstance() { #ifdef CYCLOPS_LIB return std::make_shared(); #else return std::dynamic_pointer_cast(CyclopsModules::getStandaloneInstance(typeid(T).name())); #endif // CYCLOPS_LIB } #endif // CyclopsModules_h_