~manky/bmdc++/trunk

« back to all changes in this revision

Viewing changes to Plugins/LuaPlugin/include/Singleton.h

  • Committer: M@niu
  • Date: 2017-12-08 16:42:20 UTC
  • Revision ID: m@niu-20171208164220-co5o2eqljpxnv09q
remove plugins folder . some small fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; either version 2 of the License, or
7
 
 * (at your option) any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 
 */
18
 
 
19
 
#ifndef DCPLUSPLUS_DCPP_SINGLETON_H
20
 
#define DCPLUSPLUS_DCPP_SINGLETON_H
21
 
 
22
 
#include "debug.h"
23
 
 
24
 
namespace dcpp {
25
 
 
26
 
template<typename T>
27
 
class Singleton {
28
 
public:
29
 
        Singleton() { }
30
 
        virtual ~Singleton() { }
31
 
 
32
 
        static T* getInstance() {
33
 
                dcassert(instance);
34
 
                return instance;
35
 
        }
36
 
 
37
 
        static void newInstance() {
38
 
                if(instance)
39
 
                        delete instance;
40
 
 
41
 
                instance = new T();
42
 
        }
43
 
 
44
 
        static void deleteInstance() {
45
 
                if(instance)
46
 
                        delete instance;
47
 
                instance = NULL;
48
 
        }
49
 
protected:
50
 
        static T* instance;
51
 
private:
52
 
        Singleton(const Singleton&);
53
 
        Singleton& operator=(const Singleton&);
54
 
 
55
 
};
56
 
 
57
 
template<class T> T* Singleton<T>::instance = NULL;
58
 
 
59
 
} // namespace dcpp
60
 
 
61
 
#endif // DCPLUSPLUS_DCPP_SINGLETON_H