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 2025 Federico Guerra
4 * and regents of the SIGNET lab, University of Padova
5 *
6 * Author: Federico Guerra - WOSS@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
33#ifndef SINGLETON_DEFINITIONS_H
34#define SINGLETON_DEFINITIONS_H
35
36#include <memory>
37
38namespace woss {
39
46 template< typename T >
47 class Singleton {
48
49 public:
50
55 static T& instance();
56
57#ifdef WOSS_NS_MIRACLE_SUPPORT
58 static T* instance_ptr();
59#endif // WOSS_NS_MIRACLE_SUPPORT
60
61 ~Singleton() = default;
62
66 Singleton() = delete;
67
71 Singleton( const Singleton& copy ) = delete;
72
76 Singleton( Singleton&& tmp ) = delete;
77
81 Singleton& operator=( const Singleton& copy ) = delete;
82
86 Singleton& operator=( Singleton&& tmp ) = delete;
87 };
88
89 template <typename T>
91 // from C++11 this is guaranteed to be thread safe
92 static auto the_instance = std::make_unique<T>();
93 return *the_instance;
94 }
95
96#ifdef WOSS_NS_MIRACLE_SUPPORT
97 template <typename T>
99 // from C++11 this is guaranteed to be thread safe
100 static auto the_instance = new T();
101 return the_instance;
102 }
103#endif // WOSS_NS_MIRACLE_SUPPORT
104}
105
106#endif // SINGLETON_DEFINITIONS_H
107
Singleton design pattern template.
Definition singleton-definitions.h:47
Singleton & operator=(const Singleton &copy)=delete
Singleton()=delete
static T * instance_ptr()
Definition singleton-definitions.h:98
static T & instance()
Definition singleton-definitions.h:90
Singleton(const Singleton &copy)=delete
~Singleton()=default
Singleton(Singleton &&tmp)=delete
Singleton & operator=(Singleton &&tmp)=delete
Definition ac-toolbox-arr-asc-reader.h:44