2
0
mirror of https://github.com/boostorg/process.git synced 2026-01-20 04:42:24 +00:00

Compare commits

...

1 Commits
pty ... variant

Author SHA1 Message Date
klemens-morgenstern
85345157d3 added (untested) initializer-variant. 2016-11-07 00:17:02 +01:00
5 changed files with 394 additions and 1 deletions

View File

@@ -0,0 +1,157 @@
// Copyright (c) 2016 Klemens D. Morgenstern
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_PROCESS_DETAIL_POSIX_VARIANT_HPP_
#define BOOST_PROCESS_DETAIL_POSIX_VARIANT_HPP_
#include <boost/process/detail/posix/handler.hpp>
#include <boost/variant/variant.hpp>
#include <boost/variant/static_visitor.hpp>
namespace boost
{
namespace process
{
namespace detail
{
namespace posix
{
template<typename Executor>
struct on_setup_visitor : boost::static_visitor<void>
{
Executor & exec;
template<typename T>
void operator()(T &t)
{
t.on_setup(exec);
}
};
template<typename Executor>
struct on_error_visitor : boost::static_visitor<void>
{
Executor & exec;
const std::error_code &ec;
template<typename T>
void operator()(T &t)
{
t.on_error(exec, ec);
}
};
template<typename Executor>
struct on_success_visitor : boost::static_visitor<void>
{
Executor & exec;
template<typename T>
void operator()(T &t)
{
t.on_success(exec);
}
};
template<typename Executor>
struct on_fork_error_visitor : boost::static_visitor<void>
{
Executor & exec;
const std::error_code &ec;
template<typename T>
void operator()(T &t)
{
t.on_fork_error(exec, ec);
}
};
template<typename Executor>
struct on_exec_setup_visitor : boost::static_visitor<void>
{
Executor & exec;
template<typename T>
void operator()(T &t)
{
t.on_exec_setup(exec);
}
};
template<typename Executor>
struct on_exec_error_visitor : boost::static_visitor<void>
{
Executor & exec;
const std::error_code &ec;
template<typename T>
void operator()(T &t)
{
t.on_exec_error(exec, ec);
}
};
template<typename ...Args>
struct handler_variant : handler_base_ext, boost::variant<Args...>
{
using boost::variant<Args...>::variant;
using boost::variant<Args...>::operator=;
template <class Executor>
void on_setup(Executor& exec)
{
on_setup_visitor<Executor> vis{exec};
boost::apply_visitor(vis, *this);
}
template <class Executor>
void on_error(Executor& exec, const std::error_code & ec)
{
on_error_visitor<Executor> vis{exec, ec};
boost::apply_visitor(vis, *this);
}
template <class Executor>
void on_success(Executor& exec)
{
on_success_visitor<Executor> vis{exec};
boost::apply_visitor(vis, *this);
}
template<typename Executor>
void on_fork_error (Executor & exec, const std::error_code& ec)
{
on_fork_error_visitor<Executor> vis{exec, ec};
boost::apply_visitor(vis, *this);
}
template<typename Executor>
void on_exec_setup (Executor & exec)
{
on_exec_setup_visitor<Executor> vis{exec};
boost::apply_visitor(vis, *this);
}
template<typename Executor>
void on_exec_error (Executor & exec, const std::error_code& ec)
{
on_exec_error_visitor<Executor> vis{exec, ec};
boost::apply_visitor(vis, *this);
}
};
}
}
}
}
#endif

View File

@@ -33,7 +33,6 @@ struct on_exit_ : boost::process::detail::windows::async_handler
{
handler(static_cast<int>(exit_code), ec);
};
}
};

View File

@@ -0,0 +1,114 @@
// Copyright (c) 2016 Klemens D. Morgenstern
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_PROCESS_DETAIL_POSIX_VARIANT_HPP_
#define BOOST_PROCESS_DETAIL_POSIX_VARIANT_HPP_
#include <boost/process/detail/windows/handler.hpp>
#include <boost/variant/variant.hpp>
#include <boost/variant/static_visitor.hpp>
#include <boost/process/detail/async_handler.hpp>
namespace boost
{
namespace process
{
namespace detail
{
namespace windows
{
template<typename Executor>
struct on_setup_visitor : boost::static_visitor<void>
{
Executor & exec;
template<typename T>
void operator()(T &t)
{
t.on_setup(exec);
}
};
template<typename Executor>
struct on_error_visitor : boost::static_visitor<void>
{
Executor & exec;
const std::error_code &ec;
template<typename T>
void operator()(T &t)
{
t.on_error(exec, ec);
}
};
template<typename Executor>
struct on_success_visitor : boost::static_visitor<void>
{
Executor & exec;
template<typename T>
void operator()(T &t)
{
t.on_success(exec);
}
};
struct variant_require_ios_tag_empty {};
template<typename ...Args>
struct variant_require_ios_tag
{
using needs_io_service = typename needs_io_service<Args...>::type;
using type = typename std::conditional<
needs_io_service,
require_io_service,
variant_require_ios_tag_empty>::type;
};
template<typename ...Args>
using variant_require_ios_tag_t = typename variant_require_ios_tag<Args...>::type;
template<typename ...Args>
struct handler_variant : handler_base_ext, boost::variant<Args...>, variant_require_ios_tag_t<Args...>
{
using boost::variant<Args...>::variant;
using boost::variant<Args...>::operator=;
template <class Executor>
void on_setup(Executor& exec)
{
on_setup_visitor<Executor> vis{exec};
boost::apply_visitor(vis, *this);
}
template <class Executor>
void on_error(Executor& exec, const std::error_code & ec)
{
on_error_visitor<Executor> vis{exec, ec};
boost::apply_visitor(vis, *this);
}
template <class Executor>
void on_success(Executor& exec)
{
on_success_visitor<Executor> vis{exec};
boost::apply_visitor(vis, *this);
}
};
}
}
}
}
#endif

View File

@@ -0,0 +1,93 @@
// Copyright (c) 2016 Klemens D. Morgenstern
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_PROCESS_IO_VARIANT_HPP_
#define BOOST_PROCESS_IO_VARIANT_HPP_
#include <boost/process/variant.hpp>
#include <boost/process/io.hpp>
namespace boost
{
namespace process
{
namespace detail
{
using std_in_variant_base =
handler_variant<
api::null_in,
api::close_in,
api::pipe_in,
api::file_in,
api::async_in_buffer<boost::asio::mutable_buffer>,
api::async_in_buffer<boost::asio::const_buffer>,
api::async_in_buffer<boost::asio::mutable_buffers_1>,
api::async_in_buffer<boost::asio::const_buffers_1>,
api::async_in_buffer<boost::asio::streambuf>>;
template<int p1, int p2>
using std_sink_variant_base =
handler_variant<
api::null_out<p1, p2>,
api::close_out<p1, p2>,
api::pipe_out<p1, p2>,
api::file_out<p1, p2>,
api::async_out_buffer<p1, p2, const asio::mutable_buffer> ,
api::async_out_buffer<p1, p2, const asio::mutable_buffers_1>,
api::async_out_buffer<p1, p2, asio::streambuf>,
api::async_out_buffer<p1, p2, const asio::mutable_buffer>,
api::async_out_buffer<p1, p2, const asio::mutable_buffers_1>,
api::async_out_buffer<p1, p2, asio::streambuf>,
api::async_out_future<p1, p2, std::string>,
api::async_out_future<p1, p2, std::string>,
api::async_out_future<p1, p2, std::vector<char>>,
api::async_out_future<p1, p2, std::vector<char>>>;
template<int p1, int p2 = -1>
struct std_sink_variant : std_sink_variant_base<p1, p2>,
::boost::process::detail::api::require_io_service
{
using std_sink_variant_base<p1, p2>::std_sink_variant_base;
using std_sink_variant_base<p1, p2>::operator=;
void null() {*this = api:: null_out<p1, p2>();}
void close() {*this = api::close_out<p1, p2>();}
template<typename T>
void set(T& t)
{
*this = (std_out_<p1, p2>() > t);
}
};
}
struct std_in_variant : detail::std_in_variant_base,
::boost::process::detail::api::require_io_service
{
using detail::std_in_variant_base::std_in_variant_base;
using detail::std_in_variant_base::operator=;
void null() {*this = detail::api:: null_in();}
void close() {*this = detail::api::close_in();}
template<typename T>
void set(T& t)
{
*this = (std_in < t);
}
};
using std_out_variant = ::boost::process::detail::std_sink_variant_base<1>;
using std_err_variant = ::boost::process::detail::std_sink_variant_base<2>;
using std_out_err_variant = ::boost::process::detail::std_sink_variant_base<1,2>;
}
}
#endif

View File

@@ -0,0 +1,30 @@
// Copyright (c) 2016 Klemens D. Morgenstern
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_PROCESS_VARIANT_HPP_
#define BOOST_PROCESS_VARIANT_HPP_
#include <boost/process/detail/config.hpp>
#if defined(BOOST_WINDOWS_API)
#include <boost/process/detail/windows/variant.hpp>
#elif defined(BOOST_POSIX_API)
#include <boost/process/detail/posix/variant.hpp>
#endif
namespace boost
{
namespace process
{
using ::boost::process::detail::api::handler_variant;
}
}
#endif /* INCLUDE_BOOST_PROCESS_IO_VARIANT_HPP_ */