From 22226951be6337fc4fdfdeee0324f8f934b83aae Mon Sep 17 00:00:00 2001 From: Dominik Charousset Date: Tue, 6 Nov 2012 23:58:42 +0100 Subject: [PATCH] added send_as and send_tuple_as functions these functions provide a simple interface to "fake" the sender information of a message --- cppa/cppa.hpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cppa/cppa.hpp b/cppa/cppa.hpp index c6f74dfee4..c060bcebf0 100644 --- a/cppa/cppa.hpp +++ b/cppa/cppa.hpp @@ -454,6 +454,34 @@ send(const intrusive_ptr& whom, Args&&... what) { detail::send_tpl_impl(whom.get(), std::forward(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 sizeof...(Args) > 0 + */ +template +inline typename std::enable_if::value>::type +send_tuple_as(const actor_ptr& from, const intrusive_ptr& whom, any_tuple what) { + if (whom) whom->enqueue(from.get(), std::move(what)); +} + +/** + * @brief Sends {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 sizeof...(Args) > 0 + */ +template +inline typename std::enable_if::value>::type +send_as(const actor_ptr& from, const intrusive_ptr& whom, Args&&... what) { + send_tuple_as(from, whom, make_any_tuple(std::forward(what)...)); +} + /** * @brief Sends a message to @p whom. *