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 //////////////////////////////////////////////////////////////////////////////
11 #include <boost/detail/atomic_count.hpp>
12 #include <boost/config.hpp> // BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
25 template< bool NeedsLocking >
28 count_base() : count_( 0 ) {}
29 mutable boost::detail::atomic_count count_;
33 struct count_base< false >
35 count_base() : count_( 0 ) {}
39 //////////////////////////////////////////////////////////////////////////////
40 template< bool NeedsLocking = true >
41 class counted_base : private count_base< NeedsLocking >
43 typedef count_base< NeedsLocking > base_type;
45 //////////////////////////////////////////////////////////////////////////
46 bool ref_counted() const
48 return base_type::count_ != 0;
51 long ref_count() const
53 return base_type::count_;
57 //////////////////////////////////////////////////////////////////////////
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 & ) : base_type() {}
65 counted_base & operator=( const counted_base & ) { return *this; }
68 //////////////////////////////////////////////////////////////////////////
69 // The following declarations should be private.
70 // They are only public because many compilers lack template friends.
71 //////////////////////////////////////////////////////////////////////////
79 BOOST_ASSERT( base_type::count_ > 0 );
80 return --base_type::count_ == 0;
87 } // namespace statechart