]> git.sesse.net Git - vlc/blob - modules/gui/qt4/util/singleton.hpp
Qt: emit video window resize events
[vlc] / modules / gui / qt4 / util / singleton.hpp
1 /*****************************************************************************
2  * singleton.hpp: Generic Singleton pattern implementation
3  ****************************************************************************
4  * Copyright (C) 2009 VideoLAN
5  *
6  * Authors: Hugo Beauzee-Luyssen <beauze.h # gmail - com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 #ifndef _SINGLETON_HPP_
24 #define _SINGLETON_HPP_
25
26 #include <stdlib.h>
27 #include "qt4.hpp"
28
29 template <typename T>
30 class       Singleton
31 {
32 public:
33     static T*      getInstance( intf_thread_t *p_intf = NULL )
34     {
35         if ( m_instance == NULL )
36             m_instance = new T( p_intf );
37         return m_instance;
38     }
39
40     static void    killInstance()
41     {
42         if ( m_instance != NULL )
43         {
44             delete m_instance;
45             m_instance = NULL;
46         }
47     }
48 protected:
49     Singleton(){}
50     virtual ~Singleton(){}
51     /* Not implemented since these methods should *NEVER* been called.
52     If they do, it probably won't compile :) */
53     Singleton(const Singleton<T>&);
54     Singleton<T>&   operator=(const Singleton<T>&);
55
56 private:
57     static T*      m_instance;
58 };
59
60 template <typename T>
61 T*  Singleton<T>::m_instance = NULL;
62
63 #endif // _SINGLETON_HPP_