liuxiaolong
2021-07-20 58d904a328c0d849769b483e901a0be9426b8209
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//  Copyright (c) 2001, Daniel C. Nuffer
//  Copyright (c) 2001-2011 Hartmut Kaiser
// 
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
#if !defined(BOOST_SPIRIT_ITERATOR_FIRST_OWNER_POLICY_MAR_16_2007_1108AM)
#define BOOST_SPIRIT_ITERATOR_FIRST_OWNER_POLICY_MAR_16_2007_1108AM
 
#include <boost/spirit/home/support/iterators/multi_pass_fwd.hpp>
#include <boost/spirit/home/support/iterators/detail/multi_pass.hpp>
 
namespace boost { namespace spirit { namespace iterator_policies
{
    ///////////////////////////////////////////////////////////////////////////
    //  class first_owner
    //  Implementation of an OwnershipPolicy used by multi_pass
    //  This ownership policy dictates that the first iterator created will
    //  determine the lifespan of the shared components.  This works well for
    //  spirit, since no dynamic allocation of iterators is done, and all 
    //  copies are make on the stack.
    //
    //  There is a caveat about using this policy together with the std_deque
    //  StoragePolicy. Since first_owner always returns false from unique(),
    //  std_deque will only release the queued data if clear_queue() is called.
    ///////////////////////////////////////////////////////////////////////////
    struct first_owner
    {
        ///////////////////////////////////////////////////////////////////////
        struct unique : detail::default_ownership_policy
        {
            unique() : first(true) {}
            unique(unique const&) : first(false) {}
 
            // return true to indicate deletion of resources
            template <typename MultiPass>
            static bool release(MultiPass& mp)
            {
                return mp.first;
            }
 
            // use swap from default policy
            // if we're the first, we still remain the first, even if assigned
            // to, so don't swap first.  swap is only called from operator=
 
            template <typename MultiPass>
            static bool is_unique(MultiPass const&) 
            {
                return false; // no way to know, so always return false
            }
 
        protected:
            bool first;
        };
 
        ////////////////////////////////////////////////////////////////////////
        struct shared {};   // no shared data
    };
 
}}}
 
#endif