Plasma Engine  2.0
Loading...
Searching...
No Matches
SerializationContext.h
1
2#pragma once
3
8template <typename Derived>
10{
11 PL_DISALLOW_COPY_AND_ASSIGN(plSerializationContext);
12
13public:
14 plSerializationContext() { Derived::SetContext(this); }
15 ~plSerializationContext() { Derived::SetContext(nullptr); }
16
21 void SetActive(bool bActive) { Derived::SetContext(bActive ? this : nullptr); }
22};
23
25#define PL_DECLARE_SERIALIZATION_CONTEXT(type) \
26public: \
27 static type* GetContext(); \
28 \
29protected: \
30 friend class plSerializationContext<type>; \
31 static void SetContext(plSerializationContext* pContext);
32
33
35#define PL_IMPLEMENT_SERIALIZATION_CONTEXT(type) \
36 thread_local type* PL_PP_CONCAT(s_pActiveContext, type); \
37 type* type::GetContext() \
38 { \
39 return PL_PP_CONCAT(s_pActiveContext, type); \
40 } \
41 void type::SetContext(plSerializationContext* pContext) \
42 { \
43 PL_ASSERT_DEV(pContext == nullptr || PL_PP_CONCAT(s_pActiveContext, type) == nullptr, "Only one context can be active at a time."); \
44 PL_PP_CONCAT(s_pActiveContext, type) = static_cast<type*>(pContext); \
45 }
Base class for serialization contexts. A serialization context can be used to add high level logic to...
Definition SerializationContext.h:10
void SetActive(bool bActive)
Set the context as active which means it can be accessed via GetContext in serialization methods.
Definition SerializationContext.h:21