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 
13 #ifndef FFA_SINGELTON_H
14 #define FFA_SINGELTON_H
15 
25 template<class T, class Container = T> class FFaSingelton
26 {
27 protected:
31  FFaSingelton(const FFaSingelton&) = delete;
33  FFaSingelton& operator=(const FFaSingelton&) = delete;
34 
35 public:
38  static T* instance()
39  {
40  if (!ourInstance)
41  ourInstance = new T();
42  return ourInstance;
43  }
44 
47  static void removeInstance()
48  {
49  delete ourInstance;
50  ourInstance = 0;
51  }
52 
54  static bool allocated() { return ourInstance != 0; }
55 
56 private:
57  static T* ourInstance;
58 };
59 
60 
61 template<class T, class Container>
63 
64 #endif
Template for singleton classes.
Definition: FFaSingelton.H:26
static T * ourInstance
Points to the dynamically allocated instance.
Definition: FFaSingelton.H:57
FFaSingelton & operator=(const FFaSingelton &)=delete
Disable default assignment operator.
static bool allocated()
Returns true, if the instance has been allocated.
Definition: FFaSingelton.H:54
FFaSingelton()
The constructor is protected to allow objects of sub-classes only.
Definition: FFaSingelton.H:29
static void removeInstance()
Deletes the dynamically allocated instance.
Definition: FFaSingelton.H:47
static T * instance()
Returns the actual instance of this class.
Definition: FFaSingelton.H:38
FFaSingelton(const FFaSingelton &)=delete
Disable default copy constructor.