signal_set_base.hpp 4.2 KB

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