signal_set_base.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //
  2. // signal_set_base.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 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. #elif defined(BOOST_ASIO_HAS_ENUM_CLASS)
  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. #else // defined(BOOST_ASIO_HAS_ENUM_CLASS)
  60. struct flags
  61. {
  62. enum flags_t
  63. {
  64. none = 0,
  65. restart = BOOST_ASIO_OS_DEF(SA_RESTART),
  66. no_child_stop = BOOST_ASIO_OS_DEF(SA_NOCLDSTOP),
  67. no_child_wait = BOOST_ASIO_OS_DEF(SA_NOCLDWAIT),
  68. dont_care = -1
  69. };
  70. };
  71. typedef flags::flags_t flags_t;
  72. #endif // defined(BOOST_ASIO_HAS_ENUM_CLASS)
  73. protected:
  74. /// Protected destructor to prevent deletion through this type.
  75. ~signal_set_base()
  76. {
  77. }
  78. };
  79. /// Negation operator.
  80. /**
  81. * @relates signal_set_base::flags
  82. */
  83. inline BOOST_ASIO_CONSTEXPR bool operator!(signal_set_base::flags_t x)
  84. {
  85. return static_cast<int>(x) == 0;
  86. }
  87. /// Bitwise and operator.
  88. /**
  89. * @relates signal_set_base::flags
  90. */
  91. inline BOOST_ASIO_CONSTEXPR signal_set_base::flags_t operator&(
  92. signal_set_base::flags_t x, signal_set_base::flags_t y)
  93. {
  94. return static_cast<signal_set_base::flags_t>(
  95. static_cast<int>(x) & static_cast<int>(y));
  96. }
  97. /// Bitwise or operator.
  98. /**
  99. * @relates signal_set_base::flags
  100. */
  101. inline BOOST_ASIO_CONSTEXPR signal_set_base::flags_t operator|(
  102. signal_set_base::flags_t x, signal_set_base::flags_t y)
  103. {
  104. return static_cast<signal_set_base::flags_t>(
  105. static_cast<int>(x) | static_cast<int>(y));
  106. }
  107. /// Bitwise xor operator.
  108. /**
  109. * @relates signal_set_base::flags
  110. */
  111. inline BOOST_ASIO_CONSTEXPR signal_set_base::flags_t operator^(
  112. signal_set_base::flags_t x, signal_set_base::flags_t y)
  113. {
  114. return static_cast<signal_set_base::flags_t>(
  115. static_cast<int>(x) ^ static_cast<int>(y));
  116. }
  117. /// Bitwise negation operator.
  118. /**
  119. * @relates signal_set_base::flags
  120. */
  121. inline BOOST_ASIO_CONSTEXPR signal_set_base::flags_t operator~(
  122. signal_set_base::flags_t x)
  123. {
  124. return static_cast<signal_set_base::flags_t>(~static_cast<int>(x));
  125. }
  126. /// Bitwise and-assignment operator.
  127. /**
  128. * @relates signal_set_base::flags
  129. */
  130. inline signal_set_base::flags_t& operator&=(
  131. signal_set_base::flags_t& x, signal_set_base::flags_t y)
  132. {
  133. x = x & y;
  134. return x;
  135. }
  136. /// Bitwise or-assignment operator.
  137. /**
  138. * @relates signal_set_base::flags
  139. */
  140. inline signal_set_base::flags_t& operator|=(
  141. signal_set_base::flags_t& x, signal_set_base::flags_t y)
  142. {
  143. x = x | y;
  144. return x;
  145. }
  146. /// Bitwise xor-assignment operator.
  147. /**
  148. * @relates signal_set_base::flags
  149. */
  150. inline signal_set_base::flags_t& operator^=(
  151. signal_set_base::flags_t& x, signal_set_base::flags_t y)
  152. {
  153. x = x ^ y;
  154. return x;
  155. }
  156. } // namespace asio
  157. } // namespace boost
  158. #include <boost/asio/detail/pop_options.hpp>
  159. #endif // BOOST_ASIO_SIGNAL_SET_BASE_HPP