summaryrefslogtreecommitdiff
path: root/tools/quickbook/src/intrusive_base.hpp
blob: 702c13d0b9a37dbd3e405d0cc006e2fb5d0a0851 (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
33
34
35
36
/*=============================================================================
    Copyright (c) 2011 Daniel James

    Use, modification and distribution is subject to the Boost Software
    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/

#if !defined(BOOST_QUICKBOOK_INTRUSIVE_BASE_HPP)
#define BOOST_QUICKBOOK_INTRUSIVE_BASE_HPP

namespace quickbook
{
    //
    // instructive_base
    //

    template <typename T>
    struct intrusive_base
    {
        intrusive_base() : ref_count_(0) {}
        intrusive_base(intrusive_base const&) : ref_count_(0) {}
        intrusive_base& operator=(intrusive_base const&) { return *this; }
        ~intrusive_base() { assert(!ref_count_); }

        friend void intrusive_ptr_add_ref(T* ptr)
            { ++ptr->ref_count_; }

        friend void intrusive_ptr_release(T* ptr)
            { if(--ptr->ref_count_ == 0) delete ptr; }
    private:
        unsigned ref_count_;
    };
}

#endif