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