holder.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright Oliver Kowalke 2009.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_COROUTINES_DETAIL_HOLDER_H
  6. #define BOOST_COROUTINES_DETAIL_HOLDER_H
  7. #include <boost/assert.hpp>
  8. #include <boost/config.hpp>
  9. #include <boost/optional.hpp>
  10. #include <boost/coroutine/detail/coroutine_context.hpp>
  11. #ifdef BOOST_HAS_ABI_HEADERS
  12. # include BOOST_ABI_PREFIX
  13. #endif
  14. namespace boost {
  15. namespace coroutines {
  16. namespace detail {
  17. template< typename Data >
  18. struct holder
  19. {
  20. coroutine_context * ctx;
  21. optional< Data > data;
  22. bool force_unwind;
  23. explicit holder( coroutine_context * ctx_) :
  24. ctx( ctx_), data(), force_unwind( false)
  25. { BOOST_ASSERT( ctx); }
  26. explicit holder( coroutine_context * ctx_, Data data_) :
  27. ctx( ctx_), data( data_), force_unwind( false)
  28. { BOOST_ASSERT( ctx); }
  29. explicit holder( coroutine_context * ctx_, bool force_unwind_) :
  30. ctx( ctx_), data(), force_unwind( force_unwind_)
  31. {
  32. BOOST_ASSERT( ctx);
  33. BOOST_ASSERT( force_unwind);
  34. }
  35. holder( holder const& other) :
  36. ctx( other.ctx), data( other.data),
  37. force_unwind( other.force_unwind)
  38. {}
  39. holder & operator=( holder const& other)
  40. {
  41. if ( this == & other) return * this;
  42. ctx = other.ctx;
  43. data = other.data;
  44. force_unwind = other.force_unwind;
  45. return * this;
  46. }
  47. };
  48. template<>
  49. struct holder< void >
  50. {
  51. coroutine_context * ctx;
  52. bool force_unwind;
  53. explicit holder( coroutine_context * ctx_, bool force_unwind_ = false) :
  54. ctx( ctx_), force_unwind( force_unwind_)
  55. { BOOST_ASSERT( ctx); }
  56. holder( holder const& other) :
  57. ctx( other.ctx), force_unwind( other.force_unwind)
  58. {}
  59. holder & operator=( holder const& other)
  60. {
  61. if ( this == & other) return * this;
  62. ctx = other.ctx;
  63. force_unwind = other.force_unwind;
  64. return * this;
  65. }
  66. };
  67. }}}
  68. #ifdef BOOST_HAS_ABI_HEADERS
  69. # include BOOST_ABI_SUFFIX
  70. #endif
  71. #endif // BOOST_COROUTINES_DETAIL_HOLDER_H