mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-03 20:46:28 +00:00
fix(Singleton): better code
This commit is contained in:
parent
e4415e9b16
commit
075bf87798
1 changed files with 2 additions and 16 deletions
|
|
@ -31,31 +31,17 @@ public:
|
|||
virtual ~Singleton () = default;
|
||||
|
||||
static T *getInstance () {
|
||||
if (!mInstance) {
|
||||
mInstance = new T();
|
||||
static SingletonDeleter deleter;
|
||||
}
|
||||
return mInstance;
|
||||
static T instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit Singleton (ObjectPrivate &p) : Object(p) {}
|
||||
|
||||
private:
|
||||
struct SingletonDeleter {
|
||||
~SingletonDeleter () {
|
||||
delete mInstance;
|
||||
}
|
||||
};
|
||||
|
||||
static T *mInstance;
|
||||
|
||||
L_DISABLE_COPY(Singleton);
|
||||
};
|
||||
|
||||
template<class T>
|
||||
T *Singleton<T>::mInstance = nullptr;
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
||||
#endif // ifndef _SINGLETON_H_
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue