~robot3d-team/robot3d/trunk

« back to all changes in this revision

Viewing changes to inc/srCore/singleton.h

  • Committer: Anne van Rossum
  • Date: 2010-08-10 15:58:55 UTC
  • Revision ID: anne@gamix-20100810155855-kve7x2vwouagdij9
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file singleton.h
 
3
 * @brief 
 
4
 *
 
5
 * This file singleton.h is created at Almende B.V. It is open-source software and part
 
6
 * of the Common Hybrid Agent Platform (CHAP). A toolbox with a lot of open-source tools.
 
7
 * Ranging from thread pools, and TCP/IP components to control architectures and learning
 
8
 * algorithms. This software is published under the GNU Lesser General Public license,
 
9
 * but the software is not allowed to be used for military use, within the bio-industry
 
10
 * or for animal experimentation.
 
11
 *
 
12
 * @author  Anne C. van Rossum
 
13
 * @date    Jul 13, 2010
 
14
 * @project Replicator FP7
 
15
 * @company Almende B.V.
 
16
 * @case        
 
17
 */
 
18
 
 
19
 
 
20
#ifndef SINGLETON_H_
 
21
#define SINGLETON_H_
 
22
 
 
23
// General files
 
24
#include <cassert>
 
25
 
 
26
namespace srCore {
 
27
 
 
28
/**
 
29
 * \addtogroup Default
 
30
 * @{
 
31
 */
 
32
 
 
33
/* **************************************************************************************
 
34
 * Interface of singleton
 
35
 * **************************************************************************************/
 
36
 
 
37
 
 
38
template <class T>
 
39
class Singleton
 
40
{
 
41
public:
 
42
        static T* Instance() {
 
43
                if(!m_pInstance) m_pInstance = new T;
 
44
                assert(m_pInstance !=NULL);
 
45
                return m_pInstance;
 
46
        }
 
47
protected:
 
48
        Singleton();
 
49
        ~Singleton();
 
50
private:
 
51
        Singleton(Singleton const&);
 
52
        Singleton& operator=(Singleton const&);
 
53
        static T* m_pInstance;
 
54
};
 
55
 
 
56
template <class T> T* Singleton<T>::m_pInstance=NULL;
 
57
 
 
58
 
 
59
///@}
 
60
 
 
61
}
 
62
 
 
63
#endif /* SINGLETON_H_ */