roviz  0.7
Code Documentation of roviz
startup_helper.h
Go to the documentation of this file.
1 #ifndef STARTUPHELPER_H
2 #define STARTUPHELPER_H
3 
4 #include <QMetaObject>
5 #include <QApplication>
6 
7 #include "appcore.h"
8 #include "helper/singleton.h"
9 #include "helper/startup_helper_templates.h"
10 
12  //Otherwise we won't see the marcos documented.
14 
19 class ITEMFRAMEWORK_EXPORT StartupHelper
20 {
21 public:
32  template<class T> static void addSingleton()
33  {
34  static_assert(std::is_base_of<Singleton<T>, T>::value, "Class is not derived from AbstractSingleton");
35  static_assert(internal::HasMetaObject<T>::value, "Class has no Q_OBJECT or Q_GADGET macro");
36  addSingletonHelper(T::staticMetaObject);
37  }
38 
45  template<class T> static void addComponent()
46  {
47  static_assert(internal::HasMetaObject<T>::value, "Class has no Q_OBJECT or Q_GADGET macro");
48  static_assert((internal::GetInitFnPtr<T>::value != nullptr || internal::GetDeinitFnPtr<T>::value != nullptr),
49  "Class has neither an init() nor a deinit() function");
50  addComponentHelper(T::staticMetaObject, internal::GetInitFnPtr<T>::value, internal::GetDeinitFnPtr<T>::value);
51  }
52 
57  static void ensureCoreGetsLinked();
58 
59 private:
60  static void addSingletonHelper(const QMetaObject& metaobj);
61  static void addComponentHelper(const QMetaObject& metaobj, internal::VoidFnPtr initFunc, internal::VoidFnPtr deinitFunc);
62 };
63 
64 
65 
70 #define STARTUP_ADD_SINGLETON(type) \
71 static void startup_singleton_##type() { \
72  StartupHelper::addSingleton<type>(); \
73 } \
74 Q_COREAPP_STARTUP_FUNCTION(startup_singleton_##type)
75 
80 #define STARTUP_ADD_COMPONENT(type) \
81 static void startup_component_##type() { \
82  StartupHelper::addComponent<type>(); \
83 } \
84 Q_COREAPP_STARTUP_FUNCTION(startup_component_##type)
85 
86 
87 
88 #endif // STARTUP_HELPER_H
static void addSingleton()
Adds a Singleton to the Helper. The Singleton will be constructed after it&#39;s dependencies. Dependencies can be marked by adding a Q_CLASSINFO "dependsOn" or "optionallyDependsOn" to the class definition. .
Definition: startup_helper.h:32
The StartupHelper class manages dependencies between global singletons and other components. It ensures that the singletons/components are constructed/deleted in the right order.
Definition: startup_helper.h:19
static void addComponent()
Adds a component to the Helper. The StartupHelper will call init() and deinit() on the component clas...
Definition: startup_helper.h:45
The Singleton Template figures as baseclass for all Singletons. It provides a instance() functions wh...
Definition: singleton.h:54
Definition: startup_helper_templates.h:19
Definition: startup_helper_templates.h:29
Definition: startup_helper_p.h:91
Definition: startup_helper_templates.h:9