WIP
This commit is contained in:
parent
90d89c7fbe
commit
49383b1b32
68 changed files with 3385 additions and 610 deletions
35
components/f4ll_cpp/singleton.h
Normal file
35
components/f4ll_cpp/singleton.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* singleton.h
|
||||
*
|
||||
* Created on: Sep 11, 2019
|
||||
* Author: compi
|
||||
*/
|
||||
|
||||
#ifndef SINGLETON_H_
|
||||
#define SINGLETON_H_
|
||||
|
||||
#include <utility>
|
||||
|
||||
template<typename T> class Singleton {
|
||||
public:
|
||||
static T &Instance() { return *m_instance; }
|
||||
template<typename ... Args>
|
||||
static T &Init(Args &&... args)
|
||||
{
|
||||
static T instance{ std::forward<Args>(args)... };
|
||||
if(!m_instance)
|
||||
m_instance = &instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
protected:
|
||||
Singleton() = default;
|
||||
Singleton(const Singleton &) = delete;
|
||||
Singleton &operator=(const Singleton &) = delete;
|
||||
virtual ~Singleton() = default;
|
||||
static T *m_instance;
|
||||
};
|
||||
|
||||
template<typename T> T* Singleton<T>::m_instance = nullptr;
|
||||
|
||||
#endif /* SINGLETON_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue