1 // Copyright (c) 2001 Daniel C. Nuffer
2 // Copyright (c) 2001-2011 Hartmut Kaiser
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #if !defined(BOOST_SPIRIT_ITERATOR_REF_COUNTED_POLICY_MAR_16_2007_1108AM)
8 #define BOOST_SPIRIT_ITERATOR_REF_COUNTED_POLICY_MAR_16_2007_1108AM
10 #include <boost/spirit/home/support/iterators/multi_pass_fwd.hpp>
11 #include <boost/spirit/home/support/iterators/detail/multi_pass.hpp>
12 #if defined(BOOST_HAS_THREADS)
13 #include <boost/detail/atomic_count.hpp>
17 namespace boost { namespace spirit { namespace iterator_policies
19 ///////////////////////////////////////////////////////////////////////////
21 // Implementation of an OwnershipPolicy used by multi_pass.
23 // Implementation modified from RefCounted class from the Loki library by
24 // Andrei Alexandrescu.
25 ///////////////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////////
29 struct unique // : detail::default_ownership_policy
33 // clone is called when a copy of the iterator is made, so
34 // increment the ref-count.
35 template <typename MultiPass>
36 static void clone(MultiPass& mp)
42 // called when a copy is deleted. Decrement the ref-count. Return
43 // value of true indicates that the last copy has been released.
44 template <typename MultiPass>
45 static bool release(MultiPass& mp)
47 return 0 != mp.shared() && 0 == --mp.shared()->count;
50 // returns true if there is only one iterator in existence.
51 // std_deque StoragePolicy will free it's buffered data if this
53 template <typename MultiPass>
54 static bool is_unique(MultiPass const& mp)
56 return 0 == mp.shared() || 1 == mp.shared()->count;
59 template <typename MultiPass>
60 static void destroy(MultiPass&) {}
63 ////////////////////////////////////////////////////////////////////////
66 shared() : count(1) {}
68 #if defined(BOOST_HAS_THREADS)
69 boost::detail::atomic_count count;
In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
Douglas Adams