signal_set_base.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // signal_set_base.hpp
  3. // ~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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 BOOST_ASIO_SIGNAL_SET_BASE_HPP
  11. #define BOOST_ASIO_SIGNAL_SET_BASE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/socket_types.hpp>
  17. #include <boost/asio/detail/push_options.hpp>
  18. namespace boost {
  19. namespace asio {
  20. /// The signal_set_base class is used as a base for the basic_signal_set class
  21. /// templates so that we have a common place to define the flags enum.
  22. class signal_set_base
  23. {
  24. public:
  25. # if defined(GENERATING_DOCUMENTATION)
  26. /// Enumeration representing the different types of flags that may specified
  27. /// when adding a signal to a set.
  28. enum flags
  29. {
  30. /// Bitmask representing no flags.
  31. none = 0,
  32. /// Affects the behaviour of interruptible functions such that, if the
  33. /// function would have failed with error::interrupted when interrupted by
  34. /// the specified signal, the function shall instead be restarted and not
  35. /// fail with error::interrupted.
  36. restart = implementation_defined,
  37. /// Do not generate SIGCHLD when child processes stop or stopped child
  38. /// processes continue.
  39. no_child_stop = implementation_defined,
  40. /// Do not transform child processes into zombies when they terminate.
  41. no_child_wait = implementation_defined,
  42. /// Special value to indicate that the signal registration does not care
  43. /// which flags are set, and so will not conflict with any prior
  44. /// registrations of the same signal.
  45. dont_care = -1
  46. };
  47. /// Portability typedef.
  48. typedef flags flags_t;
  49. #else // defined(GENERATING_DOCUMENTATION)
  50. enum class flags : int
  51. {
  52. none = 0,
  53. restart = BOOST_ASIO_OS_DEF(SA_RESTART),
  54. no_child_stop = BOOST_ASIO_OS_DEF(SA_NOCLDSTOP),
  55. no_child_wait = BOOST_ASIO_OS_DEF(SA_NOCLDWAIT),
  56. dont_care = -1
  57. };
  58. typedef flags flags_t;
  59. #endif // defined(GENERATING_DOCUMENTATION)
  60. protected:
  61. /// Protected destructor to prevent deletion through this type.
  62. ~signal_set_base()
  63. {
  64. }
  65. };
  66. /// Negation operator.
  67. /**
  68. * @relates signal_set_base::flags
  69. */
  70. inline constexpr bool operator!(signal_set_base::flags_t x)
  71. {
  72. return static_cast<int>(x) == 0;
  73. }
  74. /// Bitwise and operator.
  75. /**
  76. * @relates signal_set_base::flags
  77. */
  78. inline constexpr signal_set_base::flags_t operator&(
  79. signal_set_base::flags_t x, signal_set_base::flags_t y)
  80. {
  81. return static_cast<signal_set_base::flags_t>(
  82. static_cast<int>(x) & static_cast<int>(y));
  83. }
  84. /// Bitwise or operator.
  85. /**
  86. * @relates signal_set_base::flags
  87. */
  88. inline constexpr signal_set_base::flags_t operator|(
  89. signal_set_base::flags_t x, signal_set_base::flags_t y)
  90. {
  91. return static_cast<signal_set_base::flags_t>(
  92. static_cast<int>(x) | static_cast<int>(y));
  93. }
  94. /// Bitwise xor operator.
  95. /**
  96. * @relates signal_set_base::flags
  97. */
  98. inline constexpr signal_set_base::flags_t operator^(
  99. signal_set_base::flags_t x, signal_set_base::flags_t y)
  100. {
  101. return static_cast<signal_set_base::flags_t>(
  102. static_cast<int>(x) ^ static_cast<int>(y));
  103. }
  104. /// Bitwise negation operator.
  105. /**
  106. * @relates signal_set_base::flags
  107. */
  108. inline constexpr signal_set_base::flags_t operator~(
  109. signal_set_base::flags_t x)
  110. {
  111. return static_cast<signal_set_base::flags_t>(~static_cast<int>(x));
  112. }
  113. /// Bitwise and-assignment operator.
  114. /**
  115. * @relates signal_set_base::flags
  116. */
  117. inline signal_set_base::flags_t& operator&=(
  118. signal_set_base::flags_t& x, signal_set_base::flags_t y)
  119. {
  120. x = x & y;
  121. return x;
  122. }
  123. /// Bitwise or-assignment operator.
  124. /**
  125. * @relates signal_set_base::flags
  126. */
  127. inline signal_set_base::flags_t& operator|=(
  128. signal_set_base::flags_t& x, signal_set_base::flags_t y)
  129. {
  130. x = x | y;
  131. return x;
  132. }
  133. /// Bitwise xor-assignment operator.
  134. /**
  135. * @relates signal_set_base::flags
  136. */
  137. inline signal_set_base::flags_t& operator^=(
  138. signal_set_base::flags_t& x, signal_set_base::flags_t y)
  139. {
  140. x = x ^ y;
  141. return x;
  142. }
  143. } // namespace asio
  144. } // namespace boost
  145. #include <boost/asio/detail/pop_options.hpp>
  146. #endif // BOOST_ASIO_SIGNAL_SET_BASE_HPP