aboutsummaryrefslogtreecommitdiffstats
path: root/src/3rdparty/masm/stubs/wtf/RefCounted.h
blob: 5f62f72293f66d603e3b4109112d98b6fcc3ca8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef REFCOUNTED_H
#define REFCOUNTED_H

#include "PassRefPtr.h"

template <typename Base>
class RefCounted {
public:
    RefCounted() : m_refCount(1) {}
    ~RefCounted()
    {
        deref();
    }

    void ref()
    {
        ++m_refCount;
    }

    void deref()
    {
        if (!--m_refCount)
            delete static_cast<Base*>(this);
    }

protected:
    int m_refCount;
};

#endif // REFCOUNTED_H