Skip to content

Commit

Permalink
added send_as and send_tuple_as functions
Browse files Browse the repository at this point in the history
these functions provide a simple interface to "fake"
the sender information of a message
  • Loading branch information
Neverlord committed Nov 6, 2012
1 parent be17f21 commit 2222695
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cppa/cppa.hpp
Expand Up @@ -454,6 +454,34 @@ send(const intrusive_ptr<C>& whom, Args&&... what) {
detail::send_tpl_impl(whom.get(), std::forward<Args>(what)...);
}

/**
* @brief Sends @p what as a message to @p whom, but sets
* the sender information to @p from.
* @param from Sender as seen by @p whom.
* @param whom Receiver of the message.
* @param what Message elements.
* @pre <tt>sizeof...(Args) > 0</tt>
*/
template<class C, typename... Args>
inline typename std::enable_if<std::is_base_of<channel, C>::value>::type
send_tuple_as(const actor_ptr& from, const intrusive_ptr<C>& whom, any_tuple what) {
if (whom) whom->enqueue(from.get(), std::move(what));
}

/**
* @brief Sends <tt>{what...}</tt> as a message to @p whom, but sets
* the sender information to @p from.
* @param from Sender as seen by @p whom.
* @param whom Receiver of the message.
* @param what Message elements.
* @pre <tt>sizeof...(Args) > 0</tt>
*/
template<class C, typename... Args>
inline typename std::enable_if<std::is_base_of<channel, C>::value>::type
send_as(const actor_ptr& from, const intrusive_ptr<C>& whom, Args&&... what) {
send_tuple_as(from, whom, make_any_tuple(std::forward<Args>(what)...));
}

/**
* @brief Sends a message to @p whom.
*
Expand Down

0 comments on commit 2222695

Please sign in to comment.