ATLAS Offline Software
Loading...
Searching...
No Matches
EncapsulatingSingleton.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6// EncapsulatingSingleton.h, (c) ATLAS Detector software
8// Author: Thomas Gillam (thomas.gillam@cern.ch)
9// ExpressionParsing library
11
12#ifndef ENCAPSULATING_SINGLETON_H
13#define ENCAPSULATING_SINGLETON_H
14
15#include <stdexcept>
16
17namespace ExpressionParsing {
18 template <typename T> struct EncapsulatedDefault {
19 typedef T type;
20 };
21
22 template <typename T> class EncapsulatingSingleton {
23 public:
24 static T *getInstance() {
26 if (!instance.m_pointer) {
27 throw std::runtime_error("EncapsulatingSingleton: Error - no instance loaded.");
28 }
29 return instance.m_pointer;
30 }
31
32 static void setInstance(T *proxyLoader) {
34 if (instance.m_pointer) {
35 delete instance.m_pointer;
36 }
37 instance.m_pointer = proxyLoader;
38 }
39
42 return instance;
43 }
44
45 private:
50
52 if (m_pointer) {
53 delete m_pointer;
54 }
55 }
56
59
61 };
62}
63
64#endif // ENCAPSULATING_SINGLETON_H
std::map< std::string, double > instance
EncapsulatingSingleton(const EncapsulatingSingleton &)=delete
EncapsulatingSingleton & operator=(const EncapsulatingSingleton &)=delete
static const EncapsulatingSingleton & getSingleton()
Namespace holding all the expression evaluation code.