~ubuntu-branches/ubuntu/wily/bombono-dvd/wily

« back to all changes in this revision

Viewing changes to libs/boost-lib/boost/detail/sp_counted_base_nt.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-11-04 11:46:25 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101104114625-8xfdhvhpsm51i0nu
Tags: upstream-0.8.0
ImportĀ upstreamĀ versionĀ 0.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef BOOST_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
2
 
#define BOOST_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
3
 
 
4
 
// MS compatible compilers support #pragma once
5
 
 
6
 
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
7
 
# pragma once
8
 
#endif
9
 
 
10
 
//
11
 
//  detail/sp_counted_base_nt.hpp
12
 
//
13
 
//  Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
14
 
//  Copyright 2004-2005 Peter Dimov
15
 
//
16
 
// Distributed under the Boost Software License, Version 1.0. (See
17
 
// accompanying file LICENSE_1_0.txt or copy at
18
 
// http://www.boost.org/LICENSE_1_0.txt)
19
 
//
20
 
 
21
 
#include <typeinfo>
22
 
 
23
 
namespace boost
24
 
{
25
 
 
26
 
namespace detail
27
 
{
28
 
 
29
 
class sp_counted_base
30
 
{
31
 
private:
32
 
 
33
 
    sp_counted_base( sp_counted_base const & );
34
 
    sp_counted_base & operator= ( sp_counted_base const & );
35
 
 
36
 
    long use_count_;        // #shared
37
 
    long weak_count_;       // #weak + (#shared != 0)
38
 
 
39
 
public:
40
 
 
41
 
    sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
42
 
    {
43
 
    }
44
 
 
45
 
    virtual ~sp_counted_base() // nothrow
46
 
    {
47
 
    }
48
 
 
49
 
    // dispose() is called when use_count_ drops to zero, to release
50
 
    // the resources managed by *this.
51
 
 
52
 
    virtual void dispose() = 0; // nothrow
53
 
 
54
 
    // destroy() is called when weak_count_ drops to zero.
55
 
 
56
 
    virtual void destroy() // nothrow
57
 
    {
58
 
        delete this;
59
 
    }
60
 
 
61
 
    virtual void * get_deleter( std::type_info const & ti ) = 0;
62
 
 
63
 
    void add_ref_copy()
64
 
    {
65
 
        ++use_count_;
66
 
    }
67
 
 
68
 
    bool add_ref_lock() // true on success
69
 
    {
70
 
        if( use_count_ == 0 ) return false;
71
 
        ++use_count_;
72
 
        return true;
73
 
    }
74
 
 
75
 
    void release() // nothrow
76
 
    {
77
 
        if( --use_count_ == 0 )
78
 
        {
79
 
            dispose();
80
 
            weak_release();
81
 
        }
82
 
    }
83
 
 
84
 
    void weak_add_ref() // nothrow
85
 
    {
86
 
        ++weak_count_;
87
 
    }
88
 
 
89
 
    void weak_release() // nothrow
90
 
    {
91
 
        if( --weak_count_ == 0 )
92
 
        {
93
 
            destroy();
94
 
        }
95
 
    }
96
 
 
97
 
    long use_count() const // nothrow
98
 
    {
99
 
        return use_count_;
100
 
    }
101
 
};
102
 
 
103
 
} // namespace detail
104
 
 
105
 
} // namespace boost
106
 
 
107
 
#endif  // #ifndef BOOST_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED