Registration.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. #include <mutex>
  3. #include <map>
  4. #include <memory>
  5. #include <ModuleGenerator.h>
  6. #include <ProcessorGenerator.h>
  7. #include <OptimizerGenerator.h>
  8. #define REGISTER_MODULE(CLASS) registerModuleGenerator<CLASS>(#CLASS);
  9. #define REGISTER_PROCESSOR(CLASS) registerProcessorGenerator<CLASS>(#CLASS);
  10. #define REGISTER_OPTIMIZER(CLASS) registerOptimizerGenerator<CLASS>(#CLASS);
  11. namespace mdd {
  12. class Registration {
  13. private:
  14. std::map<std::string, std::shared_ptr<IModuleGenerator>> _modules;
  15. std::map<std::string, std::shared_ptr<IProcessorGenerator>> _processors;
  16. std::map<std::string, std::shared_ptr<IOptimizerGenerator>> _optimizers;
  17. //std::mutex _mutex;
  18. public:
  19. template<class MODULE_CLASS>
  20. void registerModuleGenerator(const std::string& name) {
  21. auto generator = std::make_shared<ModuleGenerator<MODULE_CLASS>>();
  22. if (generator != nullptr)
  23. {
  24. //_mutex.lock();
  25. _modules[name] = generator;
  26. //_mutex.unlock();
  27. }
  28. }
  29. template<class PROCESSOR_CLASS>
  30. void registerProcessorGenerator(const std::string& name) {
  31. auto generator = std::make_shared<ProcessorGenerator<PROCESSOR_CLASS>>();
  32. if (generator != nullptr)
  33. {
  34. //_mutex.lock();
  35. _processors[name] = generator;
  36. //_mutex.unlock();
  37. }
  38. }
  39. template<class OPTIMIZER_CLASS>
  40. void registerOptimizerGenerator(const std::string& name) {
  41. auto generator = std::make_shared<OptimizerGenerator<OPTIMIZER_CLASS>>();
  42. if (generator != nullptr)
  43. {
  44. //_mutex.lock();
  45. _optimizers[name] = generator;
  46. //_mutex.unlock();
  47. }
  48. }
  49. Registration();
  50. IModule::Ptr generateModule(const std::string& name);
  51. std::vector<std::string> getModules();
  52. IProcessor::Ptr generateProcessor(const std::string& name);
  53. std::vector<std::string> getProcessors();
  54. IOptimizer::Ptr generateOptimizer(const std::string& name);
  55. std::vector<std::string> getOptimizers();
  56. };
  57. }