123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478 |
- BOOST_PROCESS_V2_BEGIN_NAMESPACE
-
- template<typename Executor = BOOST_PROCESS_V2_ASIO_NAMESPACE::any_io_executor>
- struct basic_popen : basic_process<Executor>
- {
-
- using executor_type = Executor;
-
- template <typename Executor1>
- struct rebind_executor
- {
-
- typedef basic_popen<Executor1> other;
- };
-
- basic_popen(basic_popen &&) = default;
-
- basic_popen& operator=(basic_popen &&) = default;
-
- template<typename Executor1>
- basic_popen(basic_popen<Executor1>&& lhs)
- : basic_process<Executor>(std::move(lhs)),
- stdin_(std::move(lhs.stdin_)), stdout_(std::move(lhs.stdout_))
- {
- }
-
- explicit basic_popen(executor_type exec) : basic_process<Executor>{std::move(exec)} {}
-
- template <typename ExecutionContext>
- explicit basic_popen(ExecutionContext & context,
- typename std::enable_if<
- is_convertible<ExecutionContext&,
- BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context&>::value, void *>::type = nullptr)
- : basic_process<Executor>{context}
- {
- }
-
- template<typename ... Inits>
- explicit basic_popen(
- executor_type executor,
- const filesystem::path& exe,
- std::initializer_list<string_view> args,
- Inits&&... inits)
- : basic_process<Executor>(executor)
- {
- this->basic_process<Executor>::operator=(
- default_process_launcher()(
- this->get_executor(), exe, args,
- std::forward<Inits>(inits)...,
- process_stdio{stdin_, stdout_}
- ));
- }
-
- template<typename Launcher, typename ... Inits>
- explicit basic_popen(
- Launcher && launcher,
- executor_type executor,
- const filesystem::path& exe,
- std::initializer_list<string_view> args,
- Inits&&... inits)
- : basic_process<Executor>(executor)
- {
- this->basic_process<Executor>::operator=(
- std::forward<Launcher>(launcher)(
- this->get_executor(), exe, args,
- std::forward<Inits>(inits)...,
- process_stdio{stdin_, stdout_}
- ));
- }
-
- template<typename Args, typename ... Inits>
- explicit basic_popen(
- executor_type executor,
- const filesystem::path& exe,
- Args&& args, Inits&&... inits)
- : basic_process<Executor>(executor)
- {
- this->basic_process<Executor>::operator=(
- default_process_launcher()(
- std::move(executor), exe, args,
- std::forward<Inits>(inits)...,
- process_stdio{stdin_, stdout_}
- ));
- }
-
- template<typename Launcher, typename Args, typename ... Inits>
- explicit basic_popen(
- Launcher && launcher,
- executor_type executor,
- const filesystem::path& exe,
- Args&& args, Inits&&... inits)
- : basic_process<Executor>(executor)
- {
- this->basic_process<Executor>::operator=(
- std::forward<Launcher>(launcher)(
- std::move(executor), exe, args,
- std::forward<Inits>(inits)...,
- process_stdio{stdin_, stdout_}
- ));
- }
-
- template<typename ExecutionContext, typename ... Inits>
- explicit basic_popen(
- ExecutionContext & context,
- typename std::enable_if<
- std::is_convertible<ExecutionContext&,
- BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context&>::value,
- const filesystem::path&>::type exe,
- std::initializer_list<string_view> args,
- Inits&&... inits)
- : basic_process<Executor>(context)
- {
- this->basic_process<Executor>::operator=(
- default_process_launcher()(
- this->get_executor(), exe, args,
- std::forward<Inits>(inits)...,
- process_stdio{stdin_, stdout_}
- ));
- }
-
- template<typename Launcher, typename ExecutionContext, typename ... Inits>
- explicit basic_popen(
- Launcher && launcher,
- ExecutionContext & context,
- typename std::enable_if<
- std::is_convertible<ExecutionContext&,
- BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context&>::value,
- const filesystem::path&>::type exe,
- std::initializer_list<string_view> args,
- Inits&&... inits)
- : basic_process<Executor>(context)
- {
- this->basic_process<Executor>::operator=(
- std::forward<Launcher>(launcher)(
- this->get_executor(), exe, args,
- std::forward<Inits>(inits)...,
- process_stdio{stdin_, stdout_}
- ));
- }
-
- template<typename ExecutionContext, typename Args, typename ... Inits>
- explicit basic_popen(
- ExecutionContext & context,
- typename std::enable_if<
- std::is_convertible<ExecutionContext&,
- BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context&>::value,
- const filesystem::path&>::type exe,
- Args&& args, Inits&&... inits)
- : basic_process<Executor>(context)
- {
- this->basic_process<Executor>::operator=(
- default_process_launcher()(
- this->get_executor(), exe, args,
- std::forward<Inits>(inits)...,
- process_stdio{stdin_, stdout_}
- ));
- }
-
- template<typename Launcher, typename ExecutionContext, typename Args, typename ... Inits>
- explicit basic_popen(
- Launcher && launcher,
- ExecutionContext & context,
- typename std::enable_if<
- std::is_convertible<ExecutionContext&,
- BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context&>::value,
- const filesystem::path&>::type exe,
- Args&& args, Inits&&... inits)
- : basic_process<Executor>(context)
- {
- this->basic_process<Executor>::operator=(
- std::forward<Launcher>(launcher)(
- this->get_executor(), exe, args,
- std::forward<Inits>(inits)...,
- process_stdio{stdin_, stdout_}
- ));
- }
-
- using stdin_type = BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_writable_pipe<Executor>;
-
- using stdout_type = BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_readable_pipe<Executor>;
-
- stdin_type & get_stdin() {return stdin_; }
-
- stdout_type & get_stdout() {return stdout_; }
-
- const stdin_type & get_stdin() const {return stdin_; }
-
- const stdout_type & get_stdout() const {return stdout_; }
-
-
- template <typename ConstBufferSequence>
- std::size_t write_some(const ConstBufferSequence& buffers)
- {
- return stdin_.write_some(buffers);
- }
-
-
- template <typename ConstBufferSequence>
- std::size_t write_some(const ConstBufferSequence& buffers,
- boost::system::error_code& ec)
- {
- return stdin_.write_some(buffers, ec);
- }
-
-
- template <typename ConstBufferSequence,
- BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
- std::size_t)) WriteToken
- BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
- BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(WriteToken,
- void (boost::system::error_code, std::size_t))
- async_write_some(const ConstBufferSequence& buffers,
- BOOST_ASIO_MOVE_ARG(WriteToken) token
- BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
- {
- return stdin_.async_write_some(buffers, std::forward<WriteToken>(token));
- }
-
-
- template <typename MutableBufferSequence>
- std::size_t read_some(const MutableBufferSequence& buffers)
- {
- return stdout_.read_some(buffers);
- }
-
-
- template <typename MutableBufferSequence>
- std::size_t read_some(const MutableBufferSequence& buffers,
- boost::system::error_code& ec)
- {
- return stdout_.read_some(buffers, ec);
- }
-
-
- template <typename MutableBufferSequence,
- BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
- std::size_t)) ReadToken
- BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
- BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(ReadToken,
- void (boost::system::error_code, std::size_t))
- async_read_some(const MutableBufferSequence& buffers,
- BOOST_ASIO_MOVE_ARG(ReadToken) token
- BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
- {
- return stdout_.async_read_some(buffers, std::forward<ReadToken>(token));
- }
- private:
- stdin_type stdin_ {basic_process<Executor>::get_executor()};
- stdout_type stdout_{basic_process<Executor>::get_executor()};
- };
- using popen = basic_popen<>;
- BOOST_PROCESS_V2_END_NAMESPACE
|