2
0

Registry.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. namespace spells
  13. {
  14. namespace effects
  15. {
  16. std::unique_ptr<Registry> Instance;
  17. namespace detail
  18. {
  19. class RegistryImpl : public Registry
  20. {
  21. using DataPtr = std::shared_ptr<IEffectFactory>;
  22. public:
  23. RegistryImpl() = default;
  24. ~RegistryImpl() = default;
  25. const IEffectFactory * find(const std::string & name) const override
  26. {
  27. auto iter = data.find(name);
  28. if(iter == data.end())
  29. return nullptr;
  30. else
  31. return iter->second.get();
  32. }
  33. void add(const std::string & name, IEffectFactory * item) override
  34. {
  35. data[name].reset(item);
  36. }
  37. private:
  38. std::map<std::string, DataPtr> data;
  39. };
  40. }
  41. Registry::Registry() = default;
  42. Registry::~Registry() = default;
  43. Registry * Registry::get()
  44. {
  45. if(!Instance)
  46. Instance = make_unique<detail::RegistryImpl>();
  47. return Instance.get();
  48. }
  49. }
  50. }