epoc32/include/stdapis/boost/detail/sp_counted_base_nt.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/detail/sp_counted_base_nt.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,107 @@
     1.4 +#ifndef BOOST_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
     1.5 +#define BOOST_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
     1.6 +
     1.7 +// MS compatible compilers support #pragma once
     1.8 +
     1.9 +#if defined(_MSC_VER) && (_MSC_VER >= 1020)
    1.10 +# pragma once
    1.11 +#endif
    1.12 +
    1.13 +//
    1.14 +//  detail/sp_counted_base_nt.hpp
    1.15 +//
    1.16 +//  Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
    1.17 +//  Copyright 2004-2005 Peter Dimov
    1.18 +//
    1.19 +// Distributed under the Boost Software License, Version 1.0. (See
    1.20 +// accompanying file LICENSE_1_0.txt or copy at
    1.21 +// http://www.boost.org/LICENSE_1_0.txt)
    1.22 +//
    1.23 +
    1.24 +#include <typeinfo>
    1.25 +
    1.26 +namespace boost
    1.27 +{
    1.28 +
    1.29 +namespace detail
    1.30 +{
    1.31 +
    1.32 +class sp_counted_base
    1.33 +{
    1.34 +private:
    1.35 +
    1.36 +    sp_counted_base( sp_counted_base const & );
    1.37 +    sp_counted_base & operator= ( sp_counted_base const & );
    1.38 +
    1.39 +    long use_count_;        // #shared
    1.40 +    long weak_count_;       // #weak + (#shared != 0)
    1.41 +
    1.42 +public:
    1.43 +
    1.44 +    sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
    1.45 +    {
    1.46 +    }
    1.47 +
    1.48 +    virtual ~sp_counted_base() // nothrow
    1.49 +    {
    1.50 +    }
    1.51 +
    1.52 +    // dispose() is called when use_count_ drops to zero, to release
    1.53 +    // the resources managed by *this.
    1.54 +
    1.55 +    virtual void dispose() = 0; // nothrow
    1.56 +
    1.57 +    // destroy() is called when weak_count_ drops to zero.
    1.58 +
    1.59 +    virtual void destroy() // nothrow
    1.60 +    {
    1.61 +        delete this;
    1.62 +    }
    1.63 +
    1.64 +    virtual void * get_deleter( std::type_info const & ti ) = 0;
    1.65 +
    1.66 +    void add_ref_copy()
    1.67 +    {
    1.68 +        ++use_count_;
    1.69 +    }
    1.70 +
    1.71 +    bool add_ref_lock() // true on success
    1.72 +    {
    1.73 +        if( use_count_ == 0 ) return false;
    1.74 +        ++use_count_;
    1.75 +        return true;
    1.76 +    }
    1.77 +
    1.78 +    void release() // nothrow
    1.79 +    {
    1.80 +        if( --use_count_ == 0 )
    1.81 +        {
    1.82 +            dispose();
    1.83 +            weak_release();
    1.84 +        }
    1.85 +    }
    1.86 +
    1.87 +    void weak_add_ref() // nothrow
    1.88 +    {
    1.89 +        ++weak_count_;
    1.90 +    }
    1.91 +
    1.92 +    void weak_release() // nothrow
    1.93 +    {
    1.94 +        if( --weak_count_ == 0 )
    1.95 +        {
    1.96 +            destroy();
    1.97 +        }
    1.98 +    }
    1.99 +
   1.100 +    long use_count() const // nothrow
   1.101 +    {
   1.102 +        return use_count_;
   1.103 +    }
   1.104 +};
   1.105 +
   1.106 +} // namespace detail
   1.107 +
   1.108 +} // namespace boost
   1.109 +
   1.110 +#endif  // #ifndef BOOST_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED