LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
Singleton.h
Go to the documentation of this file.
1// Copyright 2002-2016 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#ifndef LIMA_MISC_SINGLETON_H
7#define LIMA_MISC_SINGLETON_H
8#include <memory>
9
10namespace Lima
11{
12
20template<typename Object>
22{
23public:
24 Singleton() = default;
25 virtual ~Singleton() = default;
26
30 static const Object& single();
31 static const Object* psingle();
32
36 static Object& changeable();
37 static Object* pchangeable();
38
39
40private:
41 Singleton(const Singleton<Object>&) = default;
42 Singleton& operator=(Singleton<Object>&) = default;
43
44 static std::unique_ptr< Object > s_instance;
45};
46
47template<typename Object>
48std::unique_ptr< Object > Singleton<Object>::s_instance(new Object());
49
50template<typename Object>
52{
53 if (s_instance == nullptr)
54 {
55 s_instance=std::unique_ptr< Object >(new Object());
56 }
57 return *s_instance;
58}
59
60template<typename Object>
62{
63 if (s_instance==nullptr)
64 {
65 s_instance=std::unique_ptr< Object >(new Object());
66 }
67 return s_instance.get();
68}
69
70template<typename Object>
72{
73 if (s_instance==nullptr)
74 {
75 s_instance=std::unique_ptr< Object >(new Object());
76 }
77 return *s_instance;
78}
79
80template<typename Object>
82{
83 if (s_instance==nullptr)
84 {
85 s_instance=std::unique_ptr< Object >(new Object());
86 }
87 return s_instance.get();
88}
89
90} // Lima
91
92#endif
Defines access method for the singleton pattern.
Definition Singleton.h:22
static Object * pchangeable()
Definition Singleton.h:81
virtual ~Singleton()=default
static const Object & single()
const singleton accessor
Definition Singleton.h:51
static Object & changeable()
singleton accessor
Definition Singleton.h:71
Singleton()=default
static const Object * psingle()
Definition Singleton.h:61
NAUTITIA.