2
0

Factory.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Jolt/Core/RTTI.h>
  6. #include <Jolt/Core/UnorderedMap.h>
  7. JPH_NAMESPACE_BEGIN
  8. /// Factory, to create RTTI objects
  9. class JPH_EXPORT Factory
  10. {
  11. public:
  12. JPH_OVERRIDE_NEW_DELETE
  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. /// Register a list of objects with the factory. Returns false on failure.
  22. bool Register(const RTTI **inRTTIs, uint inNumber);
  23. /// Unregisters all types
  24. void Clear();
  25. /// Get all registered classes
  26. Array<const RTTI *> GetAllClasses() const;
  27. /// Singleton factory instance
  28. static Factory * sInstance;
  29. private:
  30. using ClassNameMap = UnorderedMap<string_view, const RTTI *>;
  31. using ClassHashMap = UnorderedMap<uint32, const RTTI *>;
  32. /// Map of class names to type info
  33. ClassNameMap mClassNameMap;
  34. // Map of class hash to type info
  35. ClassHashMap mClassHashMap;
  36. };
  37. JPH_NAMESPACE_END