Plasma Engine  2.0
Loading...
Searching...
No Matches
RttiMappedObjectFactory_inl.h
1
2
3template <typename Object>
5
6template <typename Object>
8
9template <typename Object>
10void plRttiMappedObjectFactory<Object>::RegisterCreator(const plRTTI* pType, CreateObjectFunc creator)
11{
12 PL_ASSERT_DEV(!m_Creators.Contains(pType), "Type already registered.");
13
14 m_Creators.Insert(pType, creator);
15 Event e;
16 e.m_Type = Event::Type::CreatorAdded;
17 e.m_pRttiType = pType;
18 m_Events.Broadcast(e);
19}
20
21template <typename Object>
23{
24 PL_ASSERT_DEV(m_Creators.Contains(pType), "Type was never registered.");
25 m_Creators.Remove(pType);
26
27 Event e;
28 e.m_Type = Event::Type::CreatorRemoved;
29 e.m_pRttiType = pType;
30 m_Events.Broadcast(e);
31}
32
33template <typename Object>
35{
36 CreateObjectFunc* creator = nullptr;
37 while (pType != nullptr)
38 {
39 if (m_Creators.TryGetValue(pType, creator))
40 {
41 return (*creator)(pType);
42 }
43 pType = pType->GetParentType();
44 }
45 return nullptr;
46}
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
PL_ALWAYS_INLINE const plRTTI * GetParentType() const
Returns the type that is the base class of this type. May be nullptr if this type has no base class.
Definition RTTI.h:54
A factory that creates the closest matching objects according to the passed type.
Definition RttiMappedObjectFactory.h:13
constexpr TYPE e()
Returns the natural constant e.