[vlc-devel] commit: Adding a generic singleton pattern implementation ( Hugo Beauzee-Luyssen )
git version control
git at videolan.org
Fri Dec 25 18:19:23 CET 2009
vlc | branch: master | Hugo Beauzee-Luyssen <beauze.h at gmail.com> | Mon Dec 21 15:10:05 2009 +0100| [120a9af2529f50eae6e0d4e2b556f0ac0a9551e4] | committer: Jean-Baptiste Kempf
Adding a generic singleton pattern implementation
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=120a9af2529f50eae6e0d4e2b556f0ac0a9551e4
---
modules/gui/qt4/Modules.am | 4 ++-
modules/gui/qt4/util/singleton.hpp | 63 ++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 1 deletions(-)
diff --git a/modules/gui/qt4/Modules.am b/modules/gui/qt4/Modules.am
index 9ce1baf..15f842c 100644
--- a/modules/gui/qt4/Modules.am
+++ b/modules/gui/qt4/Modules.am
@@ -302,7 +302,9 @@ noinst_HEADERS = \
util/qvlcframe.hpp \
util/qvlcapp.hpp \
util/qt_dirs.hpp \
- util/registry.hpp
+ util/registry.hpp \
+ util/singleton.hpp
+
EXTRA_DIST += \
vlc.qrc \
diff --git a/modules/gui/qt4/util/singleton.hpp b/modules/gui/qt4/util/singleton.hpp
new file mode 100644
index 0000000..f6f6050
--- /dev/null
+++ b/modules/gui/qt4/util/singleton.hpp
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ * singleton.hpp: Generic Singleton pattern implementation
+ ****************************************************************************
+ * Copyright (C) 2009 VideoLAN
+ *
+ * Authors: Hugo Beauzee-Luyssen <beauze.h # gmail - com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef _SINGLETON_HPP_
+#define _SINGLETON_HPP_
+
+#include <stdlib.h>
+#include "qt4.hpp"
+
+template <typename T>
+class Singleton
+{
+public:
+ static T* getInstance( intf_thread_t *p_intf = NULL )
+ {
+ if ( m_instance == NULL )
+ m_instance = new T( p_intf );
+ return m_instance;
+ }
+
+ static void killInstance()
+ {
+ if ( m_instance != NULL )
+ {
+ delete m_instance;
+ m_instance = NULL;
+ }
+ }
+protected:
+ Singleton(){}
+ virtual ~Singleton(){}
+ /* Not implemented since these methods should *NEVER* been called.
+ If they do, it probably won't compile :) */
+ Singleton(const Singleton<T>&);
+ Singleton<T>& operator=(const Singleton<T>&);
+
+private:
+ static T* m_instance;
+};
+
+template <typename T>
+T* Singleton<T>::m_instance = NULL;
+
+#endif // _SINGLETON_HPP_
More information about the vlc-devel
mailing list