World Ocean Simulation System (WOSS) library
singleton-definitions.h
Go to the documentation of this file.
1/* WOSS - World Ocean Simulation System -
2 *
3 * Copyright (C) 2009 Federico Guerra
4 * and regents of the SIGNET lab, University of Padova
5 *
6 * Author: Federico Guerra - federico@guerra-tlc.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 version 2 as
10 * published by the Free Software Foundation;
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22/*
23 * This software has been developed by Federico Guerra and SIGNET lab,
24 * University of Padova, in collaboration with the NATO Centre for
25 * Maritime Research and Experimentation (http://www.cmre.nato.int ;
26 * E-mail: pao@cmre.nato.int), whose support is gratefully acknowledged.
27 */
28
29
40#ifndef SINGLETON_DEFINITIONS_H
41#define SINGLETON_DEFINITIONS_H
42
43
44namespace woss {
45
46
53 template< typename T >
54 class Singleton {
55
56
57 public:
58
63 static T* instance();
64
65
66 private:
67
68
72 static T* the_instance;
73
74
79
83 Singleton( const Singleton& copy ) { }
84
88 Singleton& operator=( const Singleton& copy ) { return( *this ); }
89
90
91 };
92
93
94 template <typename T>
96
97
98 template <typename T>
100 if (the_instance)
101 return the_instance;
102 else {
103 the_instance = new T();
104 return the_instance;
105 }
106 }
107
108
109}
110
111
112#endif // SINGLETON_DEFINITIONS_H
113
Singleton design pattern template.
Definition singleton-definitions.h:54
Singleton()
Definition singleton-definitions.h:78
Singleton(const Singleton &copy)
Definition singleton-definitions.h:83
static T * instance()
Definition singleton-definitions.h:99
static T * the_instance
Definition singleton-definitions.h:72
Singleton & operator=(const Singleton &copy)
Definition singleton-definitions.h:88