Registry.h 988 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Registry.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "Effect.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. namespace spells
  14. {
  15. namespace effects
  16. {
  17. class DLL_LINKAGE IEffectFactory
  18. {
  19. public:
  20. virtual ~IEffectFactory() = default;
  21. virtual Effect * create() const = 0;
  22. };
  23. class DLL_LINKAGE Registry
  24. {
  25. public:
  26. using FactoryPtr = std::shared_ptr<IEffectFactory>;
  27. virtual ~Registry() = default; //Required for child classes
  28. virtual const IEffectFactory * find(const std::string & name) const = 0;
  29. virtual void add(const std::string & name, FactoryPtr item) = 0;
  30. };
  31. class DLL_LINKAGE GlobalRegistry
  32. {
  33. public:
  34. static Registry * get();
  35. };
  36. template<typename E>
  37. class EffectFactory : public IEffectFactory
  38. {
  39. public:
  40. Effect * create() const override
  41. {
  42. return new E();
  43. }
  44. };
  45. }
  46. }
  47. VCMI_LIB_NAMESPACE_END