Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:43:20

0001 //
0002 // experimental/channel_traits.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2025 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_EXPERIMENTAL_CHANNEL_TRAITS_HPP
0012 #define BOOST_ASIO_EXPERIMENTAL_CHANNEL_TRAITS_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <deque>
0020 #include <boost/asio/detail/type_traits.hpp>
0021 #include <boost/asio/error.hpp>
0022 #include <boost/asio/experimental/channel_error.hpp>
0023 
0024 #include <boost/asio/detail/push_options.hpp>
0025 
0026 namespace boost {
0027 namespace asio {
0028 namespace experimental {
0029 
0030 #if defined(GENERATING_DOCUMENTATION)
0031 
0032 template <typename... Signatures>
0033 struct channel_traits
0034 {
0035   /// Rebind the traits to a new set of signatures.
0036   /**
0037    * This nested structure must have a single nested type @c other that
0038    * aliases a traits type with the specified set of signatures.
0039    */
0040   template <typename... NewSignatures>
0041   struct rebind
0042   {
0043     typedef user_defined other;
0044   };
0045 
0046   /// Determine the container for the specified elements.
0047   /**
0048    * This nested structure must have a single nested type @c other that
0049    * aliases a container type for the specified element type.
0050    */
0051   template <typename Element>
0052   struct container
0053   {
0054     typedef user_defined type;
0055   };
0056 
0057   /// The signature of a channel cancellation notification.
0058   typedef void receive_cancelled_signature(...);
0059 
0060   /// Invoke the specified handler with a cancellation notification.
0061   template <typename F>
0062   static void invoke_receive_cancelled(F f);
0063 
0064   /// The signature of a channel closed notification.
0065   typedef void receive_closed_signature(...);
0066 
0067   /// Invoke the specified handler with a closed notification.
0068   template <typename F>
0069   static void invoke_receive_closed(F f);
0070 };
0071 
0072 #else // defined(GENERATING_DOCUMENTATION)
0073 
0074 /// Traits used for customising channel behaviour.
0075 template <typename... Signatures>
0076 struct channel_traits
0077 {
0078   template <typename... NewSignatures>
0079   struct rebind
0080   {
0081     typedef channel_traits<NewSignatures...> other;
0082   };
0083 };
0084 
0085 template <typename R>
0086 struct channel_traits<R(boost::system::error_code)>
0087 {
0088   template <typename... NewSignatures>
0089   struct rebind
0090   {
0091     typedef channel_traits<NewSignatures...> other;
0092   };
0093 
0094   template <typename Element>
0095   struct container
0096   {
0097     typedef std::deque<Element> type;
0098   };
0099 
0100   typedef R receive_cancelled_signature(boost::system::error_code);
0101 
0102   template <typename F>
0103   static void invoke_receive_cancelled(F f)
0104   {
0105     const boost::system::error_code e = error::channel_cancelled;
0106     static_cast<F&&>(f)(e);
0107   }
0108 
0109   typedef R receive_closed_signature(boost::system::error_code);
0110 
0111   template <typename F>
0112   static void invoke_receive_closed(F f)
0113   {
0114     const boost::system::error_code e = error::channel_closed;
0115     static_cast<F&&>(f)(e);
0116   }
0117 };
0118 
0119 template <typename R, typename... Args, typename... Signatures>
0120 struct channel_traits<R(boost::system::error_code, Args...), Signatures...>
0121 {
0122   template <typename... NewSignatures>
0123   struct rebind
0124   {
0125     typedef channel_traits<NewSignatures...> other;
0126   };
0127 
0128   template <typename Element>
0129   struct container
0130   {
0131     typedef std::deque<Element> type;
0132   };
0133 
0134   typedef R receive_cancelled_signature(boost::system::error_code, Args...);
0135 
0136   template <typename F>
0137   static void invoke_receive_cancelled(F f)
0138   {
0139     const boost::system::error_code e = error::channel_cancelled;
0140     static_cast<F&&>(f)(e, decay_t<Args>()...);
0141   }
0142 
0143   typedef R receive_closed_signature(boost::system::error_code, Args...);
0144 
0145   template <typename F>
0146   static void invoke_receive_closed(F f)
0147   {
0148     const boost::system::error_code e = error::channel_closed;
0149     static_cast<F&&>(f)(e, decay_t<Args>()...);
0150   }
0151 };
0152 
0153 template <typename R>
0154 struct channel_traits<R(std::exception_ptr)>
0155 {
0156   template <typename... NewSignatures>
0157   struct rebind
0158   {
0159     typedef channel_traits<NewSignatures...> other;
0160   };
0161 
0162   template <typename Element>
0163   struct container
0164   {
0165     typedef std::deque<Element> type;
0166   };
0167 
0168   typedef R receive_cancelled_signature(std::exception_ptr);
0169 
0170   template <typename F>
0171   static void invoke_receive_cancelled(F f)
0172   {
0173     const boost::system::error_code e = error::channel_cancelled;
0174     static_cast<F&&>(f)(
0175         std::make_exception_ptr(boost::system::system_error(e)));
0176   }
0177 
0178   typedef R receive_closed_signature(std::exception_ptr);
0179 
0180   template <typename F>
0181   static void invoke_receive_closed(F f)
0182   {
0183     const boost::system::error_code e = error::channel_closed;
0184     static_cast<F&&>(f)(
0185         std::make_exception_ptr(boost::system::system_error(e)));
0186   }
0187 };
0188 
0189 template <typename R, typename... Args, typename... Signatures>
0190 struct channel_traits<R(std::exception_ptr, Args...), Signatures...>
0191 {
0192   template <typename... NewSignatures>
0193   struct rebind
0194   {
0195     typedef channel_traits<NewSignatures...> other;
0196   };
0197 
0198   template <typename Element>
0199   struct container
0200   {
0201     typedef std::deque<Element> type;
0202   };
0203 
0204   typedef R receive_cancelled_signature(std::exception_ptr, Args...);
0205 
0206   template <typename F>
0207   static void invoke_receive_cancelled(F f)
0208   {
0209     const boost::system::error_code e = error::channel_cancelled;
0210     static_cast<F&&>(f)(
0211         std::make_exception_ptr(boost::system::system_error(e)),
0212         decay_t<Args>()...);
0213   }
0214 
0215   typedef R receive_closed_signature(std::exception_ptr, Args...);
0216 
0217   template <typename F>
0218   static void invoke_receive_closed(F f)
0219   {
0220     const boost::system::error_code e = error::channel_closed;
0221     static_cast<F&&>(f)(
0222         std::make_exception_ptr(boost::system::system_error(e)),
0223         decay_t<Args>()...);
0224   }
0225 };
0226 
0227 template <typename R>
0228 struct channel_traits<R()>
0229 {
0230   template <typename... NewSignatures>
0231   struct rebind
0232   {
0233     typedef channel_traits<NewSignatures...> other;
0234   };
0235 
0236   template <typename Element>
0237   struct container
0238   {
0239     typedef std::deque<Element> type;
0240   };
0241 
0242   typedef R receive_cancelled_signature(boost::system::error_code);
0243 
0244   template <typename F>
0245   static void invoke_receive_cancelled(F f)
0246   {
0247     const boost::system::error_code e = error::channel_cancelled;
0248     static_cast<F&&>(f)(e);
0249   }
0250 
0251   typedef R receive_closed_signature(boost::system::error_code);
0252 
0253   template <typename F>
0254   static void invoke_receive_closed(F f)
0255   {
0256     const boost::system::error_code e = error::channel_closed;
0257     static_cast<F&&>(f)(e);
0258   }
0259 };
0260 
0261 template <typename R, typename T>
0262 struct channel_traits<R(T)>
0263 {
0264   template <typename... NewSignatures>
0265   struct rebind
0266   {
0267     typedef channel_traits<NewSignatures...> other;
0268   };
0269 
0270   template <typename Element>
0271   struct container
0272   {
0273     typedef std::deque<Element> type;
0274   };
0275 
0276   typedef R receive_cancelled_signature(boost::system::error_code);
0277 
0278   template <typename F>
0279   static void invoke_receive_cancelled(F f)
0280   {
0281     const boost::system::error_code e = error::channel_cancelled;
0282     static_cast<F&&>(f)(e);
0283   }
0284 
0285   typedef R receive_closed_signature(boost::system::error_code);
0286 
0287   template <typename F>
0288   static void invoke_receive_closed(F f)
0289   {
0290     const boost::system::error_code e = error::channel_closed;
0291     static_cast<F&&>(f)(e);
0292   }
0293 };
0294 
0295 #endif // defined(GENERATING_DOCUMENTATION)
0296 
0297 } // namespace experimental
0298 } // namespace asio
0299 } // namespace boost
0300 
0301 #include <boost/asio/detail/pop_options.hpp>
0302 
0303 #endif // BOOST_ASIO_EXPERIMENTAL_CHANNEL_TRAITS_HPP