PuginFactory.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef __PUGINFACTORY_HPP_
  2. #define __PUGINFACTORY_HPP_
  3. #include <iostream>
  4. #include "Util/logger.h"
  5. #include <unordered_map>
  6. #include <map>
  7. #include "UtilBase.hpp"
  8. #include <vector>
  9. using namespace toolkit;
  10. using namespace std;
  11. namespace gsd
  12. {
  13. class PuginFactory
  14. {
  15. private:
  16. PuginFactory(){}
  17. public:
  18. using Ptr = std::shared_ptr<PuginFactory>;
  19. /**
  20. * @description: getPtr
  21. * @return {*}
  22. */
  23. static std::shared_ptr<PuginFactory> getPtr(){
  24. static std::shared_ptr<PuginFactory> PuginFactory_ = nullptr;
  25. if(PuginFactory_ == nullptr) PuginFactory_ = std::shared_ptr<PuginFactory>(new PuginFactory);
  26. return PuginFactory_;
  27. }
  28. /**
  29. * @description:
  30. * @return {*}
  31. */
  32. bool Regist(const std::string& Type, std::function<std::shared_ptr<gsd::PluginBase>()> pFunc){
  33. InfoL << Type << endl;
  34. if(pFunc == nullptr) return false;
  35. bool ret = _map.insert(std::make_pair(Type, pFunc)).second;
  36. return true;
  37. }
  38. /**
  39. * @description: getMap
  40. * @return {*}
  41. */
  42. unordered_map<std::string, std::function<std::shared_ptr<PluginBase>()>> getMap(){
  43. return _map;
  44. }
  45. /**
  46. * @description: ~PuginFactory
  47. * @return {*}
  48. */
  49. ~PuginFactory(){
  50. }
  51. protected:
  52. unordered_map<std::string, std::function<std::shared_ptr<PluginBase>()>> _map;
  53. };
  54. } // namespace gsd
  55. #endif