Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/boost/statechart/detail/counted_base.hpp @ 47

Last change on this file since 47 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.3 KB
Line 
1#ifndef BOOST_STATECHART_DETAIL_COUNTED_BASE_HPP_INCLUDED
2#define BOOST_STATECHART_DETAIL_COUNTED_BASE_HPP_INCLUDED
3//////////////////////////////////////////////////////////////////////////////
4// Copyright 2002-2006 Andreas Huber Doenni
5// Distributed under the Boost Software License, Version 1.0. (See accompany-
6// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7//////////////////////////////////////////////////////////////////////////////
8
9
10
11#include <boost/detail/atomic_count.hpp>
12#include <boost/config.hpp> // BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
13
14
15
16namespace boost
17{
18namespace statechart
19{
20namespace detail
21{
22
23
24 
25template< bool NeedsLocking >
26struct count_base
27{
28  count_base() : count_( 0 ) {}
29  mutable boost::detail::atomic_count count_;
30};
31
32template<>
33struct count_base< false >
34{
35  count_base() : count_( 0 ) {}
36  mutable long count_;
37};
38
39//////////////////////////////////////////////////////////////////////////////
40template< bool NeedsLocking = true >
41class counted_base : private count_base< NeedsLocking >
42{
43  typedef count_base< NeedsLocking > base_type;
44  public:
45    //////////////////////////////////////////////////////////////////////////
46    bool ref_counted() const
47    {
48      return base_type::count_ != 0;
49    }
50
51    long ref_count() const
52    {
53      return base_type::count_;
54    }
55
56  protected:
57    //////////////////////////////////////////////////////////////////////////
58    counted_base() {}
59    ~counted_base() {}
60
61    // do nothing copy implementation is intentional (the number of
62    // referencing pointers of the source and the destination is not changed
63    // through the copy operation)
64    counted_base( const counted_base & ) {}
65    counted_base & operator=( const counted_base & ) { return *this; }
66
67  public:
68    //////////////////////////////////////////////////////////////////////////
69    // The following declarations should be private.
70    // They are only public because many compilers lack template friends.
71    //////////////////////////////////////////////////////////////////////////
72    void add_ref() const
73    {
74      ++base_type::count_;
75    }
76
77    bool release() const
78    {
79      BOOST_ASSERT( base_type::count_ > 0 );
80      return --base_type::count_ == 0;
81    }
82};
83
84
85
86} // namespace detail
87} // namespace statechart
88} // namespace boost
89
90
91
92#endif
Note: See TracBrowser for help on using the repository browser.