Registry.cpp 2.1 KB

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