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