Debian Codegraph @

thirdparty/jolt_physics/Jolt/Core/Factory.h

raw symbols SCIP
1 // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2 // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3 // SPDX-License-Identifier: MIT
4
5 #pragma once
6
7 #include <Jolt/Core/RTTI.h>
8 #include <Jolt/Core/UnorderedMap.h>
9
10 JPH_NAMESPACE_BEGIN
11
12 /// This class is responsible for creating instances of classes based on their name or hash and is mainly used for deserialization of saved data.
13 class JPH_EXPORT Factory
14 {
15 public:
16 JPH_OVERRIDE_NEW_DELETE
17
18 /// Create an object
19 void * CreateObject(const char *inName);
20
21 /// Find type info for a specific class by name
22 const RTTI * Find(const char *inName);
23
24 /// Find type info for a specific class by hash
25 const RTTI * Find(uint32 inHash);
26
27 /// Register an object with the factory. Returns false on failure.
28 bool Register(const RTTI *inRTTI);
29
30 /// Register a list of objects with the factory. Returns false on failure.
31 bool Register(const RTTI **inRTTIs, uint inNumber);
32
33 /// Unregisters all types
34 void Clear();
35
36 /// Get all registered classes
37 Array<const RTTI *> GetAllClasses() const;
38
39 /// Singleton factory instance
40 static Factory * sInstance;
41
42 private:
43 using ClassNameMap = UnorderedMap<string_view, const RTTI *>;
44
45 using ClassHashMap = UnorderedMap<uint32, const RTTI *>;
46
47 /// Map of class names to type info
48 ClassNameMap mClassNameMap;
49
50 // Map of class hash to type info
51 ClassHashMap mClassHashMap;
52 };
53
54 JPH_NAMESPACE_END