1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#ifndef REFCOUNTED_H
4#define REFCOUNTED_H
5
6#include "PassRefPtr.h"
7
8template <typename Base>
9class RefCounted {
10public:
11 RefCounted() : m_refCount(1) {}
12 ~RefCounted()
13 {
14 deref();
15 }
16
17 void ref()
18 {
19 ++m_refCount;
20 }
21
22 void deref()
23 {
24 if (!--m_refCount)
25 delete static_cast<Base*>(this);
26 }
27
28protected:
29 int m_refCount;
30};
31
32#endif // REFCOUNTED_H
33

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qtdeclarative/src/3rdparty/masm/stubs/wtf/RefCounted.h