REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
singleton.h
Go to the documentation of this file.
1// Copyright (c) 2024 anabrid GmbH
2// Contact: https://www.anabrid.com/licensing/
3//
4// SPDX-License-Identifier: MIT OR GPL-2.0-or-later
5
6#pragma once
7
8namespace utils {
9
20template <class T> class Singleton {
21public:
22 static T &get() {
23 static T instance;
24 return instance;
25 }
26};
27
46template <class T> class HeapSingleton {
47public:
48 static T &get() {
49 static T *instance = nullptr;
50 if(!instance) {
51 instance = new T{};
52 }
53 return *instance;
54 }
55};
56
57} // ns utils
Define singletons which are not static-space allocated (and thus consume valuable ICTM space).
Definition singleton.h:46
static T & get()
Definition singleton.h:48
This is a standard way of defining singletons, Usage is like:
Definition singleton.h:20
static T & get()
Definition singleton.h:22