Uniot Core
0.8.1
Loading...
Searching...
No Matches
Singleton.h
Go to the documentation of this file.
1/*
2 * This is a part of the Uniot project.
3 * Copyright (C) 2016-2024 Uniot <contact@uniot.io>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21namespace uniot {
22
51template <typename Derived>
52class Singleton {
53 public:
57 Singleton(const Singleton&) = delete;
58
62 Singleton& operator=(const Singleton&) = delete;
63
73 static inline Derived& getInstance() {
74 static Derived instance;
75 return instance;
76 }
77
78 protected:
85 Singleton() = default;
86
90 ~Singleton() = default;
91};
92
93} // namespace uniot
~Singleton()=default
Default destructor is protected to prevent deletion through base class pointer.
Singleton(const Singleton &)=delete
Copy constructor is deleted to prevent duplicating the singleton instance.
Singleton()=default
Default constructor is protected to prevent instantiation outside of derived classes.
Singleton & operator=(const Singleton &)=delete
Assignment operator is deleted to prevent duplicating the singleton instance.
static Derived & getInstance()
Gets the singleton instance of the derived class.
Definition Singleton.h:73
Contains all classes and functions related to the Uniot Core.