From 69f6fb3b281a38c8c2971de6eaae19e1591d34b8 Mon Sep 17 00:00:00 2001 From: Federico Terraneo <fede.tft@miosix.org> Date: Sun, 14 May 2017 00:12:38 +0200 Subject: [PATCH] Improved singleton --- src/shared/Singleton.h | 33 +++++++++++++++++++++++++-------- src/shared/boards/AnakinBoard.h | 5 ----- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/shared/Singleton.h b/src/shared/Singleton.h index 41f82300f..96d81c24f 100644 --- a/src/shared/Singleton.h +++ b/src/shared/Singleton.h @@ -23,16 +23,33 @@ #ifndef SINGLETON_H #define SINGLETON_H +/** + * WARNING: deriving from this class is not enough to make a singleton, + * you also have to declare the constructor of your class private! + * + * \code + * class Foo : public Singleton<Foo> + * { + * private: + * Foo() {} //Ok, private constructor + * }; + * \endcode + */ template<typename T> class Singleton { - public: - inline static T* getInstance() { - static T instance; - return &instance; - } - protected: - Singleton(){} - +public: + /** + * \return a pointer to the only instance of the class T + */ + inline static T* getInstance() { + static T instance; + return &instance; + } +protected: + Singleton(){} +private: + Singleton(const Singleton&)=delete; + Singleton& operator=(const Singleton&)=delete; }; diff --git a/src/shared/boards/AnakinBoard.h b/src/shared/boards/AnakinBoard.h index 87a24080a..388f617b9 100644 --- a/src/shared/boards/AnakinBoard.h +++ b/src/shared/boards/AnakinBoard.h @@ -86,11 +86,6 @@ private: ms580_t* mS_MS580; AnakinBoard(); - - AnakinBoard(const AnakinBoard&) = delete; - AnakinBoard(AnakinBoard&&) = delete; - AnakinBoard& operator=(const AnakinBoard&) = delete; - AnakinBoard& operator=(AnakinBoard&&) = delete; }; #ifdef sBoard -- GitLab