Factory.h 1.2 KB

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