AusweisApp2
SingletonHelper.h
gehe zur Dokumentation dieser Datei
1 /*
2  * \brief Helper to introduce a Singleton.
3  * Be aware to use this helper in .cpp file only!
4  *
5  * \copyright Copyright (c) 2016-2023 Governikus GmbH & Co. KG, Germany
6  */
7 
8 #pragma once
9 
10 #include <QGlobalStatic>
11 #include <QObject>
12 
13 #define defineSingleton(className)\
14  namespace\
15  {\
16  class Singleton##className final\
17  : public className\
18  {\
19  public:\
20  using className::className;\
21  };\
22  }\
23 \
24  Q_GLOBAL_STATIC(Singleton##className, Instance)\
25 \
26  className & className::getInstance()\
27  {\
28  return *Instance;\
29  }\
30 \
31  static_assert(!std::is_base_of_v<QObject, className>, "QObject cannot be Q_GLOBAL_STATIC");