implemented rvalue qualifications
This commit is contained in:
parent
3f2f2e33fe
commit
fba709f789
@ -51,7 +51,7 @@ namespace bp = boost::process; //we will assume this for all further examples
|
||||
bp::system("g++ main.cpp");
|
||||
```
|
||||
|
||||
The first thing we can do, is to seperate the command and the executable into
|
||||
The first thing we can do, is to separate the command and the executable into
|
||||
two parts, so it is more readable and can be built by a function.
|
||||
|
||||
```
|
||||
|
@ -184,27 +184,27 @@ public:
|
||||
WriteHandler && handler);
|
||||
|
||||
///Get the asio handle of the pipe sink.
|
||||
const handle_type & sink () const;
|
||||
const handle_type & sink () const &;
|
||||
///Get the asio handle of the pipe source.
|
||||
const handle_type & source() const;
|
||||
const handle_type & source() const &;
|
||||
|
||||
///Get the asio handle of the pipe sink.
|
||||
handle_type && sink () &&;
|
||||
///Get the asio handle of the pipe source.
|
||||
handle_type && source() &&;
|
||||
|
||||
/// Move the source out of this class and change the io_service. Qualified as rvalue. \attention Will always move.
|
||||
handle_type source(::boost::asio::io_service& ios) &&;
|
||||
/// Move the sink out of this class and change the io_service. Qualified as rvalue. \attention Will always move
|
||||
handle_type sink (::boost::asio::io_service& ios) &&;
|
||||
|
||||
/// Copy the source out of this class and change the io_service. \attention Will always copy.
|
||||
handle_type source(::boost::asio::io_service& ios) const &;
|
||||
/// Copy the sink out of this class and change the io_service. \attention Will always copy
|
||||
handle_type sink (::boost::asio::io_service& ios) const &;
|
||||
|
||||
|
||||
///Steal, i.e. move, the source out of this class.
|
||||
handle_type steal_source();
|
||||
///Steal, i.e. move the sink out of this class.
|
||||
handle_type steal_sink();
|
||||
|
||||
///Steal, i.e. move, the source out of this class and change the io_service.
|
||||
handle_type steal_source(::boost::asio::io_service& ios);
|
||||
///Steal, i.e. move, the sink out of this class and change the io_service.
|
||||
handle_type steal_sink (::boost::asio::io_service& ios);
|
||||
///Clone the source.
|
||||
handle_type clone_source() const;
|
||||
///Clone the sink.
|
||||
handle_type clone_sink() const;
|
||||
///Clone the source and replace the io_service.
|
||||
handle_type clone_source(::boost::asio::io_service& ios) const;
|
||||
///Clone the sink and replace the io_service.
|
||||
handle_type clone_sink (::boost::asio::io_service& ios) const
|
||||
};
|
||||
|
||||
#else
|
||||
|
@ -151,43 +151,56 @@ public:
|
||||
}
|
||||
|
||||
|
||||
const handle_type & sink () const {return _sink;}
|
||||
const handle_type & source() const {return _source;}
|
||||
const handle_type & sink () const & {return _sink;}
|
||||
const handle_type & source() const & {return _source;}
|
||||
|
||||
handle_type steal_source() { return steal_source(_source.get_io_service()); }
|
||||
handle_type steal_sink() { return steal_sink(_sink.get_io_service()); }
|
||||
handle_type && source() && { return std::move(_source); }
|
||||
handle_type && sink() && { return std::move(_sink); }
|
||||
|
||||
handle_type steal_source(::boost::asio::io_service& ios)
|
||||
handle_type source(::boost::asio::io_service& ios) &&
|
||||
{
|
||||
::boost::asio::posix::stream_descriptor stolen(ios, _source.native_handle());
|
||||
_source.assign(-1);
|
||||
::boost::asio::windows::stream_handle stolen(ios, _source.native_handle());
|
||||
_source.assign(::boost::detail::winapi::INVALID_HANDLE_VALUE_);
|
||||
return stolen;
|
||||
}
|
||||
handle_type steal_sink (::boost::asio::io_service& ios)
|
||||
handle_type sink (::boost::asio::io_service& ios) &&
|
||||
{
|
||||
::boost::asio::posix::stream_descriptor stolen(ios, _sink.native_handle());
|
||||
_sink.assign(-1);
|
||||
::boost::asio::windows::stream_handle stolen(ios, _sink.native_handle());
|
||||
_sink.assign(::boost::detail::winapi::INVALID_HANDLE_VALUE_);
|
||||
return stolen;
|
||||
}
|
||||
|
||||
handle_type clone_source() const
|
||||
handle_type source(::boost::asio::io_service& ios) const &
|
||||
{
|
||||
return clone_source(const_cast<handle_type&>(_source).get_io_service());
|
||||
}
|
||||
handle_type clone_sink() const
|
||||
{
|
||||
return clone_sink(const_cast<handle_type&>(_sink).get_io_service());
|
||||
}
|
||||
auto proc = ::boost::detail::winapi::GetCurrentProcess();
|
||||
|
||||
handle_type clone_source(::boost::asio::io_service& ios) const
|
||||
{
|
||||
auto source_in = const_cast<::boost::asio::posix::stream_descriptor &>(_source).native();
|
||||
return ::boost::asio::posix::stream_descriptor(ios, ::dup(source_in));
|
||||
::boost::detail::winapi::HANDLE_ source;
|
||||
auto source_in = const_cast<handle_type&>(_source).native();
|
||||
if (source_in == ::boost::detail::winapi::INVALID_HANDLE_VALUE_)
|
||||
source = ::boost::detail::winapi::INVALID_HANDLE_VALUE_;
|
||||
else if (!::boost::detail::winapi::DuplicateHandle(
|
||||
proc, source_in, proc, &source, 0,
|
||||
static_cast<::boost::detail::winapi::BOOL_>(true),
|
||||
::boost::detail::winapi::DUPLICATE_SAME_ACCESS_))
|
||||
throw_last_error("Duplicate Pipe Failed");
|
||||
|
||||
return ::boost::asio::windows::stream_handle(ios, source);
|
||||
}
|
||||
handle_type clone_sink (::boost::asio::io_service& ios) const
|
||||
handle_type sink (::boost::asio::io_service& ios) const &
|
||||
{
|
||||
auto sink_in = const_cast<::boost::asio::posix::stream_descriptor &>(_sink).native();
|
||||
return ::boost::asio::posix::stream_descriptor(ios, ::dup(sink_in));
|
||||
auto proc = ::boost::detail::winapi::GetCurrentProcess();
|
||||
|
||||
::boost::detail::winapi::HANDLE_ sink;
|
||||
auto sink_in = const_cast<handle_type&>(_sink).native();
|
||||
if (sink_in == ::boost::detail::winapi::INVALID_HANDLE_VALUE_)
|
||||
sink = ::boost::detail::winapi::INVALID_HANDLE_VALUE_;
|
||||
else if (!::boost::detail::winapi::DuplicateHandle(
|
||||
proc, sink_in, proc, &sink, 0,
|
||||
static_cast<::boost::detail::winapi::BOOL_>(true),
|
||||
::boost::detail::winapi::DUPLICATE_SAME_ACCESS_))
|
||||
throw_last_error("Duplicate Pipe Failed");
|
||||
|
||||
return ::boost::asio::windows::stream_handle(ios, sink);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -164,35 +164,26 @@ public:
|
||||
_sink.async_write_some(buffers, std::forward<WriteHandler>(handler));
|
||||
}
|
||||
|
||||
const handle_type & sink () const {return _sink;}
|
||||
const handle_type & source() const {return _source;}
|
||||
const handle_type & sink () const & {return _sink;}
|
||||
const handle_type & source() const & {return _source;}
|
||||
|
||||
handle_type steal_source() { return steal_source(_source.get_io_service()); }
|
||||
handle_type steal_sink() { return steal_sink(_sink.get_io_service()); }
|
||||
handle_type && source() && { return std::move(_source); }
|
||||
handle_type && sink() && { return std::move(_sink); }
|
||||
|
||||
handle_type steal_source(::boost::asio::io_service& ios)
|
||||
handle_type source(::boost::asio::io_service& ios) &&
|
||||
{
|
||||
::boost::asio::windows::stream_handle stolen(ios, _source.native_handle());
|
||||
_source.assign(::boost::detail::winapi::INVALID_HANDLE_VALUE_);
|
||||
return stolen;
|
||||
}
|
||||
handle_type steal_sink (::boost::asio::io_service& ios)
|
||||
handle_type sink (::boost::asio::io_service& ios) &&
|
||||
{
|
||||
::boost::asio::windows::stream_handle stolen(ios, _sink.native_handle());
|
||||
_sink.assign(::boost::detail::winapi::INVALID_HANDLE_VALUE_);
|
||||
return stolen;
|
||||
}
|
||||
|
||||
handle_type clone_source() const
|
||||
{
|
||||
return clone_source(const_cast<handle_type&>(_source).get_io_service());
|
||||
}
|
||||
handle_type clone_sink() const
|
||||
{
|
||||
return clone_sink(const_cast<handle_type&>(_sink).get_io_service());
|
||||
}
|
||||
|
||||
handle_type clone_source(::boost::asio::io_service& ios) const
|
||||
handle_type source(::boost::asio::io_service& ios) const &
|
||||
{
|
||||
auto proc = ::boost::detail::winapi::GetCurrentProcess();
|
||||
|
||||
@ -208,7 +199,7 @@ public:
|
||||
|
||||
return ::boost::asio::windows::stream_handle(ios, source);
|
||||
}
|
||||
handle_type clone_sink (::boost::asio::io_service& ios) const
|
||||
handle_type sink (::boost::asio::io_service& ios) const &
|
||||
{
|
||||
auto proc = ::boost::detail::winapi::GetCurrentProcess();
|
||||
|
||||
|
@ -198,10 +198,12 @@ struct basic_pipebuf : std::basic_streambuf<CharT, Traits>
|
||||
void pipe(pipe_type&& p) {_pipe = std::move(p); }
|
||||
///Set the pipe of the streambuf.
|
||||
void pipe(const pipe_type& p) {_pipe = p; }
|
||||
///Get a const reference of the pipe.
|
||||
const pipe_type &pipe() const {return _pipe;}
|
||||
///Get a reference of the pipe. \note Is a reference so it can be moved.
|
||||
pipe_type &pipe() {return _pipe;}
|
||||
///Get a reference to the pipe.
|
||||
pipe_type & pipe() & {return _pipe;}
|
||||
///Get a const reference to the pipe.
|
||||
const pipe_type &pipe() const & {return _pipe;}
|
||||
///Get a rvalue reference to the pipe. Qualified as rvalue.
|
||||
pipe_type && pipe() && {return std::move(_pipe);}
|
||||
private:
|
||||
pipe_type _pipe;
|
||||
std::vector<char_type> _write;
|
||||
@ -293,10 +295,12 @@ public:
|
||||
void pipe(pipe_type&& p) {_buf.pipe(std::move(p)); }
|
||||
///Set the pipe of the streambuf.
|
||||
void pipe(const pipe_type& p) {_buf.pipe(p); }
|
||||
///Get a const reference of the pipe.
|
||||
const pipe_type &pipe() const {return _buf.pipe();}
|
||||
///Get a reference of the pipe. \note Is a reference so it can be moved.
|
||||
pipe_type &pipe() {return _buf.pipe();}
|
||||
///Get a reference to the pipe.
|
||||
pipe_type & pipe() & {return _buf.pipe();}
|
||||
///Get a const reference to the pipe.
|
||||
const pipe_type &pipe() const & {return _buf.pipe();}
|
||||
///Get a rvalue reference to the pipe. Qualified as rvalue.
|
||||
pipe_type && pipe() && {return std::move(_buf).pipe();}
|
||||
};
|
||||
|
||||
typedef basic_ipstream<char> ipstream;
|
||||
@ -365,10 +369,12 @@ public:
|
||||
void pipe(pipe_type&& p) {_buf.pipe(std::move(p)); }
|
||||
///Set the pipe of the streambuf.
|
||||
void pipe(const pipe_type& p) {_buf.pipe(p); }
|
||||
///Get a const reference of the pipe.
|
||||
const pipe_type &pipe() const {return _buf.pipe();}
|
||||
///Get a reference of the pipe. \note Is a reference so it can be moved.
|
||||
pipe_type &pipe() {return _buf.pipe();}
|
||||
///Get a reference to the pipe.
|
||||
pipe_type & pipe() & {return _buf.pipe();}
|
||||
///Get a const reference to the pipe.
|
||||
const pipe_type &pipe() const & {return _buf.pipe();}
|
||||
///Get a rvalue reference to the pipe. Qualified as rvalue.
|
||||
pipe_type && pipe() && {return std::move(_buf).pipe();}
|
||||
};
|
||||
|
||||
typedef basic_opstream<char> opstream;
|
||||
@ -438,10 +444,12 @@ public:
|
||||
void pipe(pipe_type&& p) {_buf.pipe(std::move(p)); }
|
||||
///Set the pipe of the streambuf.
|
||||
void pipe(const pipe_type& p) {_buf.pipe(p); }
|
||||
///Get a const reference of the pipe.
|
||||
const pipe_type &pipe() const {return _buf.pipe();}
|
||||
///Get a reference of the pipe. \note Is a reference so it can be moved.
|
||||
pipe_type &pipe() {return _buf.pipe();}
|
||||
///Get a reference to the pipe.
|
||||
pipe_type & pipe() & {return _buf.pipe();}
|
||||
///Get a const reference to the pipe.
|
||||
const pipe_type &pipe() const & {return _buf.pipe();}
|
||||
///Get a rvalue reference to the pipe. Qualified as rvalue.
|
||||
pipe_type && pipe() && {return std::move(_buf).pipe();}
|
||||
};
|
||||
|
||||
typedef basic_pstream<char> pstream;
|
||||
|
Loading…
Reference in New Issue
Block a user