Registry.cpp 983 B

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