QuasarAppLib
qaservice.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2025 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:
71 Service() {};
72
81 static inline std::unique_ptr<Base>& initService() {
82 auto& val = instancePrivat();
83 if(!val) {
84 val.reset(new Base());
85 }
86 return val;
87 }
88
98 static bool initService(std::unique_ptr<Base> obj) {
99 auto& val = instancePrivat();
100 if(!val) {
101 val = std::move(obj);
102 return true;
103 }
104 return false;
105 };
106
115 static Base* instance() {
116 return instancePrivat().get();
117 }
118
124 static Base* autoInstance() {
125 auto& val = instancePrivat();
126
127 if (!val) {
128 initService();
129 }
130
131 return val.get();
132 }
133
141 static void deinitService() {
142 auto& val = instancePrivat();
143
144 if(val) {
145 val.release();
146 }
147 }
148
149private:
150 static inline std::unique_ptr<Base>& instancePrivat() {
151 static std::unique_ptr<Base> instance = nullptr;
152 return instance;
153 }
154
155};
156
157
158}
159#endif // QASERVICE_H
The Service class is a template class for creating a singleton services objects. This is manual contr...
Definition qaservice.h:68
static Base * instance()
instance This method return pointerer to current service object.
Definition qaservice.h:115
static bool initService(std::unique_ptr< Base > obj)
initService This is overrided static method of initialization cross libraryes object.
Definition qaservice.h:98
static std::unique_ptr< Base > & initService()
initService This method initialize the Base object as a service.
Definition qaservice.h:81
static void deinitService()
deinitService This is distructor method for the service.
Definition qaservice.h:141
static Base * autoInstance()
autoInstance This method return pointerer to current service object and if it is not inited try to in...
Definition qaservice.h:124
The QuasaraAppUtils class This lib include base functions for the all applications of QuasarApp group...
Definition helpdata.cpp:18
void gen(int size, QByteArray &result)