Open FFBoard
Open source force feedback firmware
Singleton.h
Go to the documentation of this file.
1/*
2 * Singleton.h
3 *
4 * Created on: 15.04.2021
5 * Author: Yannick
6 */
7
8#ifndef SRC_SINGLETON_H_
9#define SRC_SINGLETON_H_
10#include "main.h"
11#include "memory"
12/*
13 * Helper class to enforce singleton pattern and prevent creation of multiple instances by the classchooser
14 * This is intended to be used by the classchooser. It will not prevent you from making multiple instances by calling the constructor directly
15 * Subclasses have to inherit this to prevent classchooser from creating multiple instances
16 */
17template<typename T>
18class Singleton {
19
20protected:
21 static T* instance_ptr;
23
25 Singleton<T>::instance_ptr = nullptr; // Reset pointer if destroyed
27 }
28 static int16_t singletonRefCount;
29
30public:
31
32 static T* getInstance(){
36 }
38 }
39
40 Singleton(const Singleton&) = delete;
41 Singleton& operator= (const Singleton) = delete;
43
44};
45
46#endif /* SRC_SINGLETON_H_ */
static T * instance_ptr
Definition: Singleton.h:21
Singleton(const Singleton &)=delete
static int16_t getSingletonRefCount()
Definition: Singleton.h:42
Singleton()
Definition: Singleton.h:22
static int16_t singletonRefCount
Definition: Singleton.h:28
~Singleton()
Definition: Singleton.h:24
static T * getInstance()
Definition: Singleton.h:32
Singleton & operator=(const Singleton)=delete