Factory.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Jolt/Core/RTTI.h>
  5. JPH_SUPPRESS_WARNINGS_STD_BEGIN
  6. #include <unordered_map>
  7. JPH_SUPPRESS_WARNINGS_STD_END
  8. JPH_NAMESPACE_BEGIN
  9. /// Factory, to create RTTI objects
  10. class Factory
  11. {
  12. public:
  13. /// Create an object
  14. void * CreateObject(const char *inName);
  15. /// Find type info for a specific class by name
  16. const RTTI * Find(const char *inName);
  17. /// Find type info for a specific class by hash
  18. const RTTI * Find(uint32 inHash);
  19. /// Register an object with the factory. Returns false on failure.
  20. bool Register(const RTTI *inRTTI);
  21. /// Get all registered classes
  22. vector<const RTTI *> GetAllClasses() const;
  23. /// Singleton factory instance
  24. static Factory sInstance;
  25. private:
  26. using ClassNameMap = unordered_map<string_view, const RTTI *>;
  27. using ClassHashMap = unordered_map<uint32, const RTTI *>;
  28. /// Map of class names to type info
  29. ClassNameMap mClassNameMap;
  30. // Map of class hash to type info
  31. ClassHashMap mClassHashMap;
  32. };
  33. JPH_NAMESPACE_END