cancellation_type.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. //
  2. // cancellation_type.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_CANCELLATION_TYPE_HPP
  11. #define ASIO_CANCELLATION_TYPE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include "asio/detail/push_options.hpp"
  17. namespace asio {
  18. # if defined(GENERATING_DOCUMENTATION)
  19. /// Enumeration representing the different types of cancellation that may
  20. /// be requested from or implemented by an asynchronous operation.
  21. enum cancellation_type
  22. {
  23. /// Bitmask representing no types of cancellation.
  24. none = 0,
  25. /// Requests cancellation where, following a successful cancellation, the only
  26. /// safe operations on the I/O object are closure or destruction.
  27. terminal = 1,
  28. /// Requests cancellation where a successful cancellation may result in
  29. /// partial side effects or no side effects. Following cancellation, the I/O
  30. /// object is in a well-known state, and may be used for further operations.
  31. partial = 2,
  32. /// Requests cancellation where a successful cancellation results in no
  33. /// apparent side effects. Following cancellation, the I/O object is in the
  34. /// same observable state as it was prior to the operation.
  35. total = 4,
  36. /// Bitmask representing all types of cancellation.
  37. all = 0xFFFFFFFF
  38. };
  39. /// Portability typedef.
  40. typedef cancellation_type cancellation_type_t;
  41. #else // defined(GENERATING_DOCUMENTATION)
  42. enum class cancellation_type : unsigned int
  43. {
  44. none = 0,
  45. terminal = 1,
  46. partial = 2,
  47. total = 4,
  48. all = 0xFFFFFFFF
  49. };
  50. typedef cancellation_type cancellation_type_t;
  51. #endif // defined(GENERATING_DOCUMENTATION)
  52. /// Negation operator.
  53. /**
  54. * @relates cancellation_type
  55. */
  56. inline constexpr bool operator!(cancellation_type_t x)
  57. {
  58. return static_cast<unsigned int>(x) == 0;
  59. }
  60. /// Bitwise and operator.
  61. /**
  62. * @relates cancellation_type
  63. */
  64. inline constexpr cancellation_type_t operator&(
  65. cancellation_type_t x, cancellation_type_t y)
  66. {
  67. return static_cast<cancellation_type_t>(
  68. static_cast<unsigned int>(x) & static_cast<unsigned int>(y));
  69. }
  70. /// Bitwise or operator.
  71. /**
  72. * @relates cancellation_type
  73. */
  74. inline constexpr cancellation_type_t operator|(
  75. cancellation_type_t x, cancellation_type_t y)
  76. {
  77. return static_cast<cancellation_type_t>(
  78. static_cast<unsigned int>(x) | static_cast<unsigned int>(y));
  79. }
  80. /// Bitwise xor operator.
  81. /**
  82. * @relates cancellation_type
  83. */
  84. inline constexpr cancellation_type_t operator^(
  85. cancellation_type_t x, cancellation_type_t y)
  86. {
  87. return static_cast<cancellation_type_t>(
  88. static_cast<unsigned int>(x) ^ static_cast<unsigned int>(y));
  89. }
  90. /// Bitwise negation operator.
  91. /**
  92. * @relates cancellation_type
  93. */
  94. inline constexpr cancellation_type_t operator~(cancellation_type_t x)
  95. {
  96. return static_cast<cancellation_type_t>(~static_cast<unsigned int>(x));
  97. }
  98. /// Bitwise and-assignment operator.
  99. /**
  100. * @relates cancellation_type
  101. */
  102. inline cancellation_type_t& operator&=(
  103. cancellation_type_t& x, cancellation_type_t y)
  104. {
  105. x = x & y;
  106. return x;
  107. }
  108. /// Bitwise or-assignment operator.
  109. /**
  110. * @relates cancellation_type
  111. */
  112. inline cancellation_type_t& operator|=(
  113. cancellation_type_t& x, cancellation_type_t y)
  114. {
  115. x = x | y;
  116. return x;
  117. }
  118. /// Bitwise xor-assignment operator.
  119. /**
  120. * @relates cancellation_type
  121. */
  122. inline cancellation_type_t& operator^=(
  123. cancellation_type_t& x, cancellation_type_t y)
  124. {
  125. x = x ^ y;
  126. return x;
  127. }
  128. } // namespace asio
  129. #include "asio/detail/pop_options.hpp"
  130. #endif // ASIO_CANCELLATION_TYPE_HPP