Registry.cpp 915 B

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