FEDEM Solver  R8.0
Source code of the dynamics solver
FFaSingelton.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
8 #ifndef FFA_SINGELTON_H
9 #define FFA_SINGELTON_H
10 
11 
19 template <class T, class Container = T> class FFaSingelton
20 {
21 protected:
25  FFaSingelton(const FFaSingelton&) = delete;
27  FFaSingelton& operator=(const FFaSingelton&) = delete;
28 
29 public:
32  static T* instance()
33  {
34  if (ourInstance == 0)
35  ourInstance = new T();
36  return ourInstance;
37  }
38 
41  static void removeInstance()
42  {
43  if (ourInstance != 0)
44  delete ourInstance;
45  ourInstance = 0;
46  }
47 
49  static bool allocated() { return ourInstance != 0; }
50 
51 private:
52  static T* ourInstance;
53 };
54 
55 
56 template <class T, class Container>
58 
59 #endif
Template class for singleton classes.
Definition: FFaSingelton.H:20
static T * ourInstance
Points to the dynamically allocated instance.
Definition: FFaSingelton.H:52
FFaSingelton & operator=(const FFaSingelton &)=delete
Disable default assignment operator.
static bool allocated()
Returns true, if the instance has been allocated.
Definition: FFaSingelton.H:49
FFaSingelton()
The constructor is protected to allow objects of sub-classes only.
Definition: FFaSingelton.H:23
static void removeInstance()
Deletes the dynamically allocated instance.
Definition: FFaSingelton.H:41
static T * instance()
Returns the actual instance of this class.
Definition: FFaSingelton.H:32
FFaSingelton(const FFaSingelton &)=delete
Disable default copy constructor.