Registry.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Registry.cpp, 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. #include "StdInc.h"
  11. #include "Registry.h"
  12. #include "Catapult.h"
  13. #include "Clone.h"
  14. #include "Damage.h"
  15. #include "DemonSummon.h"
  16. #include "Dispel.h"
  17. #include "Effect.h"
  18. #include "Effects.h"
  19. #include "Heal.h"
  20. #include "LocationEffect.h"
  21. #include "Obstacle.h"
  22. #include "RemoveObstacle.h"
  23. #include "Sacrifice.h"
  24. #include "Summon.h"
  25. #include "Teleport.h"
  26. #include "Timed.h"
  27. #include "UnitEffect.h"
  28. VCMI_LIB_NAMESPACE_BEGIN
  29. namespace spells
  30. {
  31. namespace effects
  32. {
  33. namespace detail
  34. {
  35. class RegistryImpl : public Registry
  36. {
  37. public:
  38. RegistryImpl()
  39. {
  40. add("core:catapult", std::make_shared<EffectFactory<Catapult>>());
  41. add("core:clone", std::make_shared<EffectFactory<Clone>>());
  42. add("core:damage", std::make_shared<EffectFactory<Damage>>());
  43. add("core:demonSummon", std::make_shared<EffectFactory<DemonSummon>>());
  44. add("core:dispel", std::make_shared<EffectFactory<Dispel>>());
  45. add("core:heal", std::make_shared<EffectFactory<Heal>>());
  46. add("core:obstacle", std::make_shared<EffectFactory<Obstacle>>());
  47. add("core:removeObstacle", std::make_shared<EffectFactory<RemoveObstacle>>());
  48. add("core:sacrifice", std::make_shared<EffectFactory<Sacrifice>>());
  49. add("core:summon", std::make_shared<EffectFactory<Summon>>());
  50. add("core:teleport", std::make_shared<EffectFactory<Teleport>>());
  51. add("core:timed", std::make_shared<EffectFactory<Timed>>());
  52. }
  53. const IEffectFactory * find(const std::string & name) const override
  54. {
  55. auto iter = data.find(name);
  56. if(iter == data.end())
  57. return nullptr;
  58. else
  59. return iter->second.get();
  60. }
  61. void add(const std::string & name, FactoryPtr item) override
  62. {
  63. data[name] = item;
  64. }
  65. private:
  66. std::map<std::string, FactoryPtr> data;
  67. };
  68. }
  69. Registry * GlobalRegistry::get()
  70. {
  71. static std::unique_ptr<Registry> Instance = std::make_unique<detail::RegistryImpl>();
  72. return Instance.get();
  73. }
  74. }
  75. }
  76. VCMI_LIB_NAMESPACE_END