PicoScenes API Docs
Loading...
Searching...
No Matches
Singleton.hxx
Go to the documentation of this file.
1
//
2
// Singleton.hpp
3
//
4
// Created by JiangZhping on 2017/2/1.
5
// Copyright © 2017年 JiangZhping. All rights reserved.
6
//
7
8
#ifndef Singleton_hpp
9
#define Singleton_hpp
10
11
#include <cstdio>
12
13
template
<
class
T>
14
class
Singleton
{
15
public
:
16
template
<
typename
... Args>
17
static
T &
getInstance
(Args... args) {
18
if
(!m_pInstance) [[unlikely]] {
19
m_pInstance =
new
T(std::forward<Args>(args)...);
20
}
21
22
return
*m_pInstance;
23
}
24
25
protected
:
26
Singleton
();
27
28
~Singleton
();
29
30
private
:
31
Singleton
(
Singleton
const
&);
32
33
Singleton
&operator=(
Singleton
const
&);
34
35
static
T *m_pInstance;
36
};
37
38
template
<
class
T> T *
Singleton<T>::m_pInstance
=
nullptr
;
39
40
41
#endif
/* Singleton_hpp */
Singleton
Definition
Singleton.hxx:14
Singleton::getInstance
static T & getInstance(Args... args)
Definition
Singleton.hxx:17
Singleton::Singleton
Singleton()
Singleton::~Singleton
~Singleton()
headers
Singleton.hxx
Generated by
1.9.8