Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:31:58

0001 //  Copyright (c) 2001 Daniel C. Nuffer
0002 //  Copyright (c) 2001-2011 Hartmut Kaiser
0003 // 
0004 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #if !defined(BOOST_SPIRIT_ITERATOR_REF_COUNTED_POLICY_MAR_16_2007_1108AM)
0008 #define BOOST_SPIRIT_ITERATOR_REF_COUNTED_POLICY_MAR_16_2007_1108AM
0009 
0010 #include <boost/spirit/home/support/iterators/multi_pass_fwd.hpp>
0011 #include <boost/spirit/home/support/iterators/detail/multi_pass.hpp>
0012 #if defined(BOOST_HAS_THREADS)
0013 #include <boost/detail/atomic_count.hpp>
0014 #endif
0015 #include <cstdlib>
0016 
0017 namespace boost { namespace spirit { namespace iterator_policies
0018 {
0019     ///////////////////////////////////////////////////////////////////////////
0020     //  class ref_counted
0021     //  Implementation of an OwnershipPolicy used by multi_pass.
0022     //
0023     //  Implementation modified from RefCounted class from the Loki library by
0024     //  Andrei Alexandrescu.
0025     ///////////////////////////////////////////////////////////////////////////
0026     struct ref_counted
0027     {
0028         ///////////////////////////////////////////////////////////////////////
0029         struct unique // : detail::default_ownership_policy
0030         {
0031             void swap(unique&) {}
0032 
0033             // clone is called when a copy of the iterator is made, so 
0034             // increment the ref-count.
0035             template <typename MultiPass>
0036             static void clone(MultiPass& mp)
0037             {
0038                 if (0 != mp.shared())
0039                     ++mp.shared()->count;
0040             }
0041 
0042             // called when a copy is deleted. Decrement the ref-count. Return
0043             // value of true indicates that the last copy has been released.
0044             template <typename MultiPass>
0045             static bool release(MultiPass& mp)
0046             {
0047                 return 0 != mp.shared() && 0 == --mp.shared()->count;
0048             }
0049 
0050             // returns true if there is only one iterator in existence.
0051             // std_deque StoragePolicy will free it's buffered data if this
0052             // returns true.
0053             template <typename MultiPass>
0054             static bool is_unique(MultiPass const& mp) 
0055             {
0056                 return 0 == mp.shared() || 1 == mp.shared()->count;
0057             }
0058 
0059             template <typename MultiPass>
0060             static void destroy(MultiPass&) {}
0061         };
0062 
0063         ////////////////////////////////////////////////////////////////////////
0064         struct shared
0065         {
0066             shared() : count(1) {}
0067 
0068 #if defined(BOOST_HAS_THREADS)
0069             boost::detail::atomic_count count;
0070 #else
0071             std::size_t count;
0072 #endif
0073         };
0074 
0075     };
0076 
0077 }}}
0078 
0079 #endif