first_owner_policy.hpp 2.4 KB

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