|
| 1 | +// |
| 2 | +// any_io_executor.hpp |
| 3 | +// ~~~~~~~~~~~~~~~~~~~ |
| 4 | +// |
| 5 | +// Copyright (c) 2003-2021 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 | + |
| 11 | +#ifndef ASIO_ANY_IO_EXECUTOR_HPP |
| 12 | +#define ASIO_ANY_IO_EXECUTOR_HPP |
| 13 | + |
| 14 | +#if defined(_MSC_VER) && (_MSC_VER >= 1200) |
| 15 | +# pragma once |
| 16 | +#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) |
| 17 | + |
| 18 | +#include "asio/detail/config.hpp" |
| 19 | +#if defined(ASIO_USE_TS_EXECUTOR_AS_DEFAULT) |
| 20 | +# include "asio/executor.hpp" |
| 21 | +#else // defined(ASIO_USE_TS_EXECUTOR_AS_DEFAULT) |
| 22 | +# include "asio/execution.hpp" |
| 23 | +# include "asio/execution_context.hpp" |
| 24 | +#endif // defined(ASIO_USE_TS_EXECUTOR_AS_DEFAULT) |
| 25 | + |
| 26 | +#include "asio/detail/push_options.hpp" |
| 27 | + |
| 28 | +namespace asio { |
| 29 | + |
| 30 | +#if defined(ASIO_USE_TS_EXECUTOR_AS_DEFAULT) |
| 31 | + |
| 32 | +typedef executor any_io_executor; |
| 33 | + |
| 34 | +#else // defined(ASIO_USE_TS_EXECUTOR_AS_DEFAULT) |
| 35 | + |
| 36 | +/// Polymorphic executor type for use with I/O objects. |
| 37 | +/** |
| 38 | + * The @c any_io_executor type is a polymorphic executor that supports the set |
| 39 | + * of properties required by I/O objects. It is defined as the |
| 40 | + * execution::any_executor class template parameterised as follows: |
| 41 | + * @code execution::any_executor< |
| 42 | + * execution::context_as_t<execution_context&>, |
| 43 | + * execution::blocking_t::never_t, |
| 44 | + * execution::prefer_only<execution::blocking_t::possibly_t>, |
| 45 | + * execution::prefer_only<execution::outstanding_work_t::tracked_t>, |
| 46 | + * execution::prefer_only<execution::outstanding_work_t::untracked_t>, |
| 47 | + * execution::prefer_only<execution::relationship_t::fork_t>, |
| 48 | + * execution::prefer_only<execution::relationship_t::continuation_t> |
| 49 | + * > @endcode |
| 50 | + */ |
| 51 | +class any_io_executor : |
| 52 | +#if defined(GENERATING_DOCUMENTATION) |
| 53 | + public execution::any_executor<...> |
| 54 | +#else // defined(GENERATING_DOCUMENTATION) |
| 55 | + public execution::any_executor< |
| 56 | + execution::context_as_t<execution_context&>, |
| 57 | + execution::blocking_t::never_t, |
| 58 | + execution::prefer_only<execution::blocking_t::possibly_t>, |
| 59 | + execution::prefer_only<execution::outstanding_work_t::tracked_t>, |
| 60 | + execution::prefer_only<execution::outstanding_work_t::untracked_t>, |
| 61 | + execution::prefer_only<execution::relationship_t::fork_t>, |
| 62 | + execution::prefer_only<execution::relationship_t::continuation_t> |
| 63 | + > |
| 64 | +#endif // defined(GENERATING_DOCUMENTATION) |
| 65 | +{ |
| 66 | +public: |
| 67 | +#if !defined(GENERATING_DOCUMENTATION) |
| 68 | + typedef execution::any_executor< |
| 69 | + execution::context_as_t<execution_context&>, |
| 70 | + execution::blocking_t::never_t, |
| 71 | + execution::prefer_only<execution::blocking_t::possibly_t>, |
| 72 | + execution::prefer_only<execution::outstanding_work_t::tracked_t>, |
| 73 | + execution::prefer_only<execution::outstanding_work_t::untracked_t>, |
| 74 | + execution::prefer_only<execution::relationship_t::fork_t>, |
| 75 | + execution::prefer_only<execution::relationship_t::continuation_t> |
| 76 | + > base_type; |
| 77 | + |
| 78 | + typedef void supportable_properties_type( |
| 79 | + execution::context_as_t<execution_context&>, |
| 80 | + execution::blocking_t::never_t, |
| 81 | + execution::prefer_only<execution::blocking_t::possibly_t>, |
| 82 | + execution::prefer_only<execution::outstanding_work_t::tracked_t>, |
| 83 | + execution::prefer_only<execution::outstanding_work_t::untracked_t>, |
| 84 | + execution::prefer_only<execution::relationship_t::fork_t>, |
| 85 | + execution::prefer_only<execution::relationship_t::continuation_t> |
| 86 | + ); |
| 87 | +#endif // !defined(GENERATING_DOCUMENTATION) |
| 88 | + |
| 89 | + /// Default constructor. |
| 90 | + any_io_executor() ASIO_NOEXCEPT |
| 91 | + : base_type() |
| 92 | + { |
| 93 | + } |
| 94 | + |
| 95 | + /// Construct in an empty state. Equivalent effects to default constructor. |
| 96 | + any_io_executor(nullptr_t) ASIO_NOEXCEPT |
| 97 | + : base_type(nullptr_t()) |
| 98 | + { |
| 99 | + } |
| 100 | + |
| 101 | + /// Copy constructor. |
| 102 | + any_io_executor(const any_io_executor& e) ASIO_NOEXCEPT |
| 103 | + : base_type(static_cast<const base_type&>(e)) |
| 104 | + { |
| 105 | + } |
| 106 | + |
| 107 | +#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) |
| 108 | + /// Move constructor. |
| 109 | + any_io_executor(any_io_executor&& e) ASIO_NOEXCEPT |
| 110 | + : base_type(static_cast<base_type&&>(e)) |
| 111 | + { |
| 112 | + } |
| 113 | +#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) |
| 114 | + |
| 115 | + /// Construct to point to the same target as another any_executor. |
| 116 | +#if defined(GENERATING_DOCUMENTATION) |
| 117 | + template <class... OtherSupportableProperties> |
| 118 | + any_io_executor(execution::any_executor<OtherSupportableProperties...> e); |
| 119 | +#else // defined(GENERATING_DOCUMENTATION) |
| 120 | + template <typename OtherAnyExecutor> |
| 121 | + any_io_executor(OtherAnyExecutor e, |
| 122 | + typename constraint< |
| 123 | + conditional< |
| 124 | + !is_same<OtherAnyExecutor, any_io_executor>::value |
| 125 | + && is_base_of<execution::detail::any_executor_base, |
| 126 | + OtherAnyExecutor>::value, |
| 127 | + typename execution::detail::supportable_properties< |
| 128 | + 0, supportable_properties_type>::template |
| 129 | + is_valid_target<OtherAnyExecutor>, |
| 130 | + false_type |
| 131 | + >::type::value |
| 132 | + >::type = 0) |
| 133 | + : base_type(ASIO_MOVE_CAST(OtherAnyExecutor)(e)) |
| 134 | + { |
| 135 | + } |
| 136 | +#endif // defined(GENERATING_DOCUMENTATION) |
| 137 | + |
| 138 | + /// Construct a polymorphic wrapper for the specified executor. |
| 139 | +#if defined(GENERATING_DOCUMENTATION) |
| 140 | + template <ASIO_EXECUTION_EXECUTOR Executor> |
| 141 | + any_io_executor(Executor e); |
| 142 | +#else // defined(GENERATING_DOCUMENTATION) |
| 143 | + template <ASIO_EXECUTION_EXECUTOR Executor> |
| 144 | + any_io_executor(Executor e, |
| 145 | + typename constraint< |
| 146 | + conditional< |
| 147 | + !is_same<Executor, any_io_executor>::value |
| 148 | + && !is_base_of<execution::detail::any_executor_base, |
| 149 | + Executor>::value, |
| 150 | + execution::detail::is_valid_target_executor< |
| 151 | + Executor, supportable_properties_type>, |
| 152 | + false_type |
| 153 | + >::type::value |
| 154 | + >::type = 0) |
| 155 | + : base_type(ASIO_MOVE_CAST(Executor)(e)) |
| 156 | + { |
| 157 | + } |
| 158 | +#endif // defined(GENERATING_DOCUMENTATION) |
| 159 | + |
| 160 | + /// Assignment operator. |
| 161 | + any_io_executor& operator=(const any_io_executor& e) ASIO_NOEXCEPT |
| 162 | + { |
| 163 | + base_type::operator=(static_cast<const base_type&>(e)); |
| 164 | + return *this; |
| 165 | + } |
| 166 | + |
| 167 | +#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) |
| 168 | + /// Move assignment operator. |
| 169 | + any_io_executor& operator=(any_io_executor&& e) ASIO_NOEXCEPT |
| 170 | + { |
| 171 | + base_type::operator=(static_cast<base_type&&>(e)); |
| 172 | + return *this; |
| 173 | + } |
| 174 | +#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) |
| 175 | + |
| 176 | + /// Assignment operator that sets the polymorphic wrapper to the empty state. |
| 177 | + any_io_executor& operator=(nullptr_t) |
| 178 | + { |
| 179 | + base_type::operator=(nullptr_t()); |
| 180 | + return *this; |
| 181 | + } |
| 182 | + |
| 183 | + /// Destructor. |
| 184 | + ~any_io_executor() |
| 185 | + { |
| 186 | + } |
| 187 | + |
| 188 | + /// Swap targets with another polymorphic wrapper. |
| 189 | + void swap(any_io_executor& other) ASIO_NOEXCEPT |
| 190 | + { |
| 191 | + static_cast<base_type&>(*this).swap(static_cast<base_type&>(other)); |
| 192 | + } |
| 193 | + |
| 194 | + /// Obtain a polymorphic wrapper with the specified property. |
| 195 | + /** |
| 196 | + * Do not call this function directly. It is intended for use with the |
| 197 | + * asio::require and asio::prefer customisation points. |
| 198 | + * |
| 199 | + * For example: |
| 200 | + * @code any_io_executor ex = ...; |
| 201 | + * auto ex2 = asio::require(ex, execution::blocking.possibly); @endcode |
| 202 | + */ |
| 203 | + template <typename Property> |
| 204 | + any_io_executor require(const Property& p, |
| 205 | + typename constraint< |
| 206 | + traits::require_member<const base_type&, const Property&>::is_valid |
| 207 | + >::type = 0) const |
| 208 | + { |
| 209 | + return static_cast<const base_type&>(*this).require(p); |
| 210 | + } |
| 211 | + |
| 212 | + /// Obtain a polymorphic wrapper with the specified property. |
| 213 | + /** |
| 214 | + * Do not call this function directly. It is intended for use with the |
| 215 | + * asio::prefer customisation point. |
| 216 | + * |
| 217 | + * For example: |
| 218 | + * @code any_io_executor ex = ...; |
| 219 | + * auto ex2 = asio::prefer(ex, execution::blocking.possibly); @endcode |
| 220 | + */ |
| 221 | + template <typename Property> |
| 222 | + any_io_executor prefer(const Property& p, |
| 223 | + typename constraint< |
| 224 | + traits::prefer_member<const base_type&, const Property&>::is_valid |
| 225 | + >::type = 0) const |
| 226 | + { |
| 227 | + return static_cast<const base_type&>(*this).prefer(p); |
| 228 | + } |
| 229 | +}; |
| 230 | + |
| 231 | +#if !defined(GENERATING_DOCUMENTATION) |
| 232 | + |
| 233 | +namespace traits { |
| 234 | + |
| 235 | +#if !defined(ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) |
| 236 | + |
| 237 | +template <> |
| 238 | +struct equality_comparable<any_io_executor> |
| 239 | +{ |
| 240 | + static const bool is_valid = true; |
| 241 | + static const bool is_noexcept = true; |
| 242 | +}; |
| 243 | + |
| 244 | +#endif // !defined(ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) |
| 245 | + |
| 246 | +#if !defined(ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT) |
| 247 | + |
| 248 | +template <typename F> |
| 249 | +struct execute_member<any_io_executor, F> |
| 250 | +{ |
| 251 | + static const bool is_valid = true; |
| 252 | + static const bool is_noexcept = false; |
| 253 | + typedef void result_type; |
| 254 | +}; |
| 255 | + |
| 256 | +#endif // !defined(ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT) |
| 257 | + |
| 258 | +#if !defined(ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT) |
| 259 | + |
| 260 | +template <typename Prop> |
| 261 | +struct query_member<any_io_executor, Prop> : |
| 262 | + query_member<any_io_executor::base_type, Prop> |
| 263 | +{ |
| 264 | +}; |
| 265 | + |
| 266 | +#endif // !defined(ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT) |
| 267 | + |
| 268 | +#if !defined(ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT) |
| 269 | + |
| 270 | +template <typename Prop> |
| 271 | +struct require_member<any_io_executor, Prop> : |
| 272 | + require_member<any_io_executor::base_type, Prop> |
| 273 | +{ |
| 274 | + typedef any_io_executor result_type; |
| 275 | +}; |
| 276 | + |
| 277 | +#endif // !defined(ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT) |
| 278 | + |
| 279 | +#if !defined(ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT) |
| 280 | + |
| 281 | +template <typename Prop> |
| 282 | +struct prefer_member<any_io_executor, Prop> : |
| 283 | + prefer_member<any_io_executor::base_type, Prop> |
| 284 | +{ |
| 285 | + typedef any_io_executor result_type; |
| 286 | +}; |
| 287 | + |
| 288 | +#endif // !defined(ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT) |
| 289 | + |
| 290 | +} // namespace traits |
| 291 | + |
| 292 | +#endif // !defined(GENERATING_DOCUMENTATION) |
| 293 | + |
| 294 | +#endif // defined(ASIO_USE_TS_EXECUTOR_AS_DEFAULT) |
| 295 | + |
| 296 | +} // namespace asio |
| 297 | + |
| 298 | +#include "asio/detail/pop_options.hpp" |
| 299 | + |
| 300 | +#endif // ASIO_ANY_IO_EXECUTOR_HPP |
0 commit comments