QuasarAppLib 1.0.530.c9fba11
qaservice.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2026 QuasarApp.
3 * Distributed under the lgplv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8#ifndef QASERVICE_H
9#define QASERVICE_H
10
11#include <memory>
12#include <utility>
13namespace QuasarAppUtils {
14
66template<class Base>
68{
69
70public:
75 Service() {};
76
85 static inline std::unique_ptr<Base>& initService() {
86 auto& val = instancePrivat();
87 if(!val) {
88 val.reset(new Base());
89 }
90 return val;
91 }
92
102 static bool initService(std::unique_ptr<Base> obj) {
103 auto& val = instancePrivat();
104 if(!val) {
105 val = std::move(obj);
106 return true;
107 }
108 return false;
109 };
110
119 static Base* instance() {
120 return instancePrivat().get();
121 }
122
128 static Base* autoInstance() {
129 auto& val = instancePrivat();
130
131 if (!val) {
132 initService();
133 }
134
135 return val.get();
136 }
137
145 static void deinitService() {
146 auto& val = instancePrivat();
147
148 if(val) {
149 val.release();
150 }
151 }
152
153private:
159 static inline std::unique_ptr<Base>& instancePrivat() {
160 static std::unique_ptr<Base> instance = nullptr;
161 return instance;
162 }
163
164};
165
166
167}
168#endif // QASERVICE_H
static Base * instance()
instance This method return pointerer to current service object.
Definition qaservice.h:119
static bool initService(std::unique_ptr< Base > obj)
initService This is overridden static method of initialization cross libraries object.
Definition qaservice.h:102
static std::unique_ptr< Base > & initService()
initService This method initialize the Base object as a service using the default constructor....
Definition qaservice.h:85
Service()
Service This is the default constructor of the Service template class. It does nothing and is used on...
Definition qaservice.h:75
static void deinitService()
deinitService This is destructor method for the service.
Definition qaservice.h:145
static Base * autoInstance()
autoInstance This method return pointerer to current service object and if it is not inited try to in...
Definition qaservice.h:128
The QuasarAppUtils namespace contains the base functions for all applications of the QuasarApp group....