fix work service class on the android and windows apps for the shared applications

This commit is contained in:
Andrei Yankovich 2023-04-06 14:48:23 +02:00
parent 7737b28258
commit c29c9edc52

View File

@ -78,12 +78,10 @@ public:
*/ */
template<class BaseClass = Base, class... Args> template<class BaseClass = Base, class... Args>
static Base* initService(Args&&... args) { static Base* initService(Args&&... args) {
Service<Base>* instanceObj = privateInstance(); if(!_data) {
if(!instanceObj->_data) { _data = new BaseClass(std::forward<Args>(args)...);
instanceObj->_data = new BaseClass(std::forward<Args>(args)...);
} }
return _data;
return instanceObj->_data;
} }
/** /**
@ -95,7 +93,7 @@ public:
* @see autoInstance * @see autoInstance
*/ */
static Base* instance() { static Base* instance() {
return privateInstance()->_data; return _data;
} }
/** /**
@ -105,11 +103,11 @@ public:
*/ */
static Base* autoInstance() { static Base* autoInstance() {
if (!privateInstance()->_data) { if (!_data) {
initService(); initService();
} }
return privateInstance()->_data; return _data;
} }
/** /**
@ -120,23 +118,20 @@ public:
* @see autoInstance * @see autoInstance
*/ */
static void deinitService() { static void deinitService() {
Service<Base>* instanceObj = privateInstance(); if(_data) {
if(instanceObj->_data) { delete _data;
delete instanceObj->_data; _data = nullptr;
instanceObj->_data = nullptr;
} }
} }
private: private:
static Service<Base>* privateInstance() { static Base* _data;
static Service<Base>* privateObject = new Service<Base>;
return privateObject;
};
Base* _data = nullptr;
}; };
template<class Base>
Base* Service<Base>::_data = nullptr;
} }
#endif // QASERVICE_H #endif // QASERVICE_H