7 #ifndef __MERCURY_COROUTINE_ENGINE_CHAN__
8 #define __MERCURY_COROUTINE_ENGINE_CHAN__
11 #include <type_traits>
48 ctx(std::move(rhs.ctx))
54 template <
typename CHANNEL>
57 ctx = std::unique_ptr<base_channel<T>>(
58 allocate_context(std::forward<CHANNEL>(ch)));
70 inline void*
context()
const {
return ctx ? ctx->context() : NULL; }
73 inline const std::type_info&
type_info()
const {
return typeid(*this); }
82 return ctx->type_info();
92 template <
typename CHANNEL>
93 inline CHANNEL
cast()
const
95 if(
context() && ctx->type_info() ==
typeid(CHANNEL))
97 return *(
dynamic_cast<CHANNEL*
>(ctx.get()));
106 inline void close()
const { ctx->close(); }
109 inline bool closed()
const {
return ctx->closed(); }
112 inline bool send(
const T& s)
const {
return ctx->send(s); }
115 inline bool send(T&& s)
const {
return ctx->send(std::move(s)); }
118 inline bool recv(T& r)
const {
return ctx->recv(r); }
151 mutable std::shared_ptr<base_channel<T>> ctx;
153 template <
typename CHANNEL>
156 typedef typename std::decay<CHANNEL>::type DECAY_CH;
158 new DECAY_CH(std::forward<CHANNEL>(ch))
result
enum for channel operation results
Definition: base_channel.hpp:23
Definition: base_channel.hpp:49
result try_send(const T &s) const
attempt to send a copy of data through channel
Definition: chan.hpp:121
void assign(const chan< T > &rhs) const
copy internal context of argument channel
Definition: chan.hpp:130
result try_recv(T &s) const
attempt to retrieve data from channel
Definition: chan.hpp:127
void * context() const
retrieve internal context pointer
Definition: chan.hpp:70
bool send(const T &s) const
send a copy of data through channel
Definition: chan.hpp:112
const chan< T > & operator=(chan< T > &&rhs) const
rvalue assign channel context
Definition: chan.hpp:144
void construct(CHANNEL &&ch) const
Definition: chan.hpp:55
bool recv(T &r) const
retrieve data from channel
Definition: chan.hpp:118
void construct() const
construct unbuffered channel context
Definition: chan.hpp:62
const chan< T > & operator=(const chan< T > &rhs) const
lvalue assign channel context
Definition: chan.hpp:137
bool closed() const
report if channel is closed
Definition: chan.hpp:109
void close() const
close channel
Definition: chan.hpp:106
void assign(chan< T > &&rhs) const
move internal context of argument channel
Definition: chan.hpp:133
result try_send(T &&s) const
attempt to move data through channel
Definition: chan.hpp:124
const std::type_info & type_info() const
retrieve type_info
Definition: chan.hpp:73
CHANNEL cast() const
Definition: chan.hpp:93
bool send(T &&s) const
move data through channel
Definition: chan.hpp:115
const std::type_info & context_type_info() const
Definition: chan.hpp:80
Definition: base_channel.hpp:229
Definition: unbuffered_channel.hpp:39
void construct() const
construct channel context
Definition: unbuffered_channel.hpp:59