File indexing completed on 2025-01-18 09:50:09
0001
0002
0003
0004
0005
0006 #ifndef BOOST_PROCESS_DETAIL_USED_HANDLES_HPP_
0007 #define BOOST_PROCESS_DETAIL_USED_HANDLES_HPP_
0008
0009 #include <type_traits>
0010 #include <boost/fusion/include/filter_if.hpp>
0011 #include <boost/fusion/include/for_each.hpp>
0012
0013 #if defined(BOOST_POSIX_API)
0014 #include <boost/process/detail/posix/handles.hpp>
0015 #include <boost/process/detail/posix/asio_fwd.hpp>
0016 #else
0017 #include <boost/process/detail/windows/handles.hpp>
0018 #include <boost/process/detail/windows/asio_fwd.hpp>
0019 #endif
0020
0021 namespace boost { namespace process { namespace detail {
0022
0023 struct uses_handles
0024 {
0025
0026 void get_used_handles() const;
0027 };
0028
0029 template<typename T>
0030 struct does_use_handle: std::is_base_of<uses_handles, T> {};
0031
0032 template<typename T>
0033 struct does_use_handle<T&> : std::is_base_of<uses_handles, T> {};
0034
0035 template<typename T>
0036 struct does_use_handle<const T&> : std::is_base_of<uses_handles, T> {};
0037
0038 template<typename Char, typename Sequence>
0039 class executor;
0040
0041 template<typename Func>
0042 struct foreach_handle_invocator
0043 {
0044 Func & func;
0045 foreach_handle_invocator(Func & func) : func(func) {}
0046
0047
0048 template<typename Range>
0049 void invoke(const Range & range) const
0050 {
0051 for (auto handle_ : range)
0052 func(handle_);
0053
0054 }
0055 void invoke(::boost::process::detail::api::native_handle_type handle) const {func(handle);};
0056
0057 template<typename T>
0058 void operator()(T & val) const {invoke(val.get_used_handles());}
0059 };
0060
0061 template<typename Executor, typename Function>
0062 void foreach_used_handle(Executor &exec, Function &&func)
0063 {
0064 boost::fusion::for_each(boost::fusion::filter_if<does_use_handle<boost::mpl::_>>(exec.seq),
0065 foreach_handle_invocator<Function>(func));
0066 }
0067
0068 template<typename Executor>
0069 std::vector<::boost::process::detail::api::native_handle_type>
0070 get_used_handles(Executor &exec)
0071 {
0072 std::vector<::boost::process::detail::api::native_handle_type> res = exec.get_used_handles();
0073 foreach_used_handle(exec, [&](::boost::process::detail::api::native_handle_type handle){res.push_back(handle);});
0074 return res;
0075 }
0076
0077
0078
0079 }}}
0080
0081 #endif