Generator.h 755 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. #include <map>
  3. #include <string>
  4. #include "IGenerator.h"
  5. namespace mdd
  6. {
  7. template <class MODULE_CLASS>
  8. class Generator
  9. : public IGenerator
  10. {
  11. virtual std::shared_ptr<IModule> Generate()
  12. {
  13. return std::make_shared<MODULE_CLASS>();
  14. }
  15. };
  16. std::map<std::string, std::shared_ptr<IGenerator>>&
  17. GetGenerators(
  18. const std::string& name = "",
  19. const std::shared_ptr<IGenerator>& generator = nullptr);
  20. template<class MODULE_CLASS>
  21. class GeneratorRegistration
  22. {
  23. public:
  24. GeneratorRegistration(const std::string& name)
  25. {
  26. GetGenerators(name.substr(6), std::make_shared<Generator<MODULE_CLASS>>());
  27. }
  28. };
  29. }
  30. #define ADD_GENERATOR(CLASS) namespace{mdd::GeneratorRegistration<CLASS> reg_sdewfdsf(typeid(CLASS).name());}