HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_SubSystem.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_SubSystem.h
7  *
8  * COMMENTS:
9  *
10  *
11  */
12 
13 #ifndef __UT_SUBSYSTEM_H__
14 #define __UT_SUBSYSTEM_H__
15 
16 #include "UT_API.h"
17 
18 #define UT_ENABLE_SUBSYSTEMS
19 
20 #include "UT_NonCopyable.h"
21 #include "UT_UniquePtr.h"
22 
23 #include <SYS/SYS_StaticInit.h>
24 
25 #include <type_traits>
26 
27 /// All subsystems should derive from this interface. Each subsystem then
28 /// defines how to initialize and shutdown its components.
29 /// All components of a subsystem should be lazy initialized.
31 {
32 public:
33  enum Type
34  {
38  MAX_SUBSYSTEMS
39  };
40 
42 
43  virtual ~UT_ISubSystem() = default;
44 
45  /// The type of the subsystem.
46  virtual Type type() const = 0;
47 
48  template <typename SubSystemT>
49  static bool registerSubSystem(SubSystemT& subsys)
50  {
51  static_assert(
52  std::is_base_of_v<UT_ISubSystem, SubSystemT>
53  && std::is_default_constructible_v<SubSystemT>);
54  return registerSubSystem_(std::addressof(subsys));
55  }
56 
57 protected:
58  UT_ISubSystem() = default;
59 
60  /// Initialize this subsystem
61  virtual void initialize_() = 0;
62  /// Shutdown this subsystem
63  virtual void shutdown_() = 0;
64 private:
65  friend class ut_SubSystemRegistry;
66 
67  static bool registerSubSystem_(UT_ISubSystem* subsys);
68 };
69 
70 #define UT_SUBSYSTEM_CLASS(sub_type) \
71 public: \
72  static constexpr Type subsystem_type = UT_ISubSystem::Type::sub_type; \
73  Type type() const override \
74  { \
75  return subsystem_type; \
76  } \
77  \
78 private: \
79  static bool theIsRegistered;
80 
81 #define UT_SUBSYSTEM_IMPL_INNER(cls) \
82  static SYS_StaticInit<cls> theSubSystem; \
83  static void cls##Init() \
84  { \
85  UT_ISubSystem::registerSubSystem<cls>(*theSubSystem); \
86  } \
87  static void cls##CleanUp() \
88  { \
89  }
90 
91 #define UT_SUBSYSTEM_IMPL(cls) \
92  namespace cls_Namespace \
93  { \
94  UT_SUBSYSTEM_IMPL_INNER(cls) \
95  SYSimplementStaticInit(cls); \
96  }
97 
98 #define UT_SUBSYSTEM_DECLARE(api, cls) \
99  namespace cls_Namespace \
100  { \
101  SYSdeclareStaticInit(api, cls) \
102  }
103 
104 /// The subsystem to initialize and cleanup UT.
105 class UT_API UT_SubSystem final : public UT_ISubSystem
106 {
107  UT_SUBSYSTEM_CLASS(UT_SUBSYSTEM);
108 public:
109  UT_SubSystem() = default;
110 
111 protected:
112 
113  void initialize_() override;
114  void shutdown_() override;
115 };
116 
117 
118 /// Initialize all subsystems
120 /// Shutdown all subsystems. initialize() must be called prior to this
121 /// function.
123 
124 namespace UT_SubSystemImpl
125 {
126 SYSdeclareStaticObject(UT_API, theRegistry);
127 
129 } // namespace UT_SubSystemImpl
130 
131 template <typename T>
132 T*
134 {
135  static_assert(std::is_base_of_v<T, UT_ISubSystem>());
136  return static_cast<T*>(UT_SubSystemImpl::utGetSubSystem(T::subsystem_type));
137 }
138 
140 
141 #endif // __UT_SUBSYSTEM_H__
The subsystem to initialize and cleanup UT.
Definition: UT_SubSystem.h:105
#define UT_API
Definition: UT_API.h:14
virtual void shutdown_()=0
Shutdown this subsystem.
T * UTgetSubSystem()
Definition: UT_SubSystem.h:133
UT_API void UTsubSystemShutdown()
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
GLdouble t
Definition: glad.h:2397
#define UT_SUBSYSTEM_CLASS(sub_type)
Definition: UT_SubSystem.h:70
static bool registerSubSystem(SubSystemT &subsys)
Definition: UT_SubSystem.h:49
#define UT_SUBSYSTEM_DECLARE(api, cls)
Definition: UT_SubSystem.h:98
SYSdeclareStaticObject(UT_API, theRegistry)
virtual void initialize_()=0
Initialize this subsystem.
UT_API void UTsubSystemInitialize()
Initialize all subsystems.
UT_API UT_ISubSystem * utGetSubSystem(UT_SubSystem::Type t)
type
Definition: core.h:1059