Factory.h 994 B

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