mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-07 05:53:06 +00:00
feat(Object): check weak ptr when getSharedFromThis is called
This commit is contained in:
parent
459d54c746
commit
6caf117b91
1 changed files with 15 additions and 2 deletions
|
|
@ -16,12 +16,15 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "logger/logger.h"
|
||||
#include "object-p.h"
|
||||
|
||||
#include "object.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
#define GET_SHARED_FROM_THIS_FATAL_ERROR "Object was not created with `ObjectFactory::create`."
|
||||
|
||||
using namespace std;
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
|
@ -33,11 +36,21 @@ Object::~Object () {
|
|||
Object::Object (ObjectPrivate &p) : mPrivate(&p) {}
|
||||
|
||||
shared_ptr<Object> Object::getSharedFromThis () {
|
||||
return mPrivate->weak.lock();
|
||||
return const_pointer_cast<Object>(static_cast<const Object *>(this)->getSharedFromThis());
|
||||
}
|
||||
|
||||
shared_ptr<const Object> Object::getSharedFromThis () const {
|
||||
return mPrivate->weak.lock();
|
||||
shared_ptr<const Object> object;
|
||||
|
||||
try {
|
||||
object = mPrivate->weak.lock();
|
||||
if (!object)
|
||||
lFatal() << GET_SHARED_FROM_THIS_FATAL_ERROR;
|
||||
} catch (const exception &) {
|
||||
lFatal() << GET_SHARED_FROM_THIS_FATAL_ERROR;
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
void ObjectFactory::setPublic (const shared_ptr<Object> &object) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue