Commit 637d7d9a authored by Dominik Charousset's avatar Dominik Charousset

got rid of 'reply is deprecated' warnings

parent a781875b
......@@ -87,7 +87,7 @@ class actor_companion_mixin : public Base {
/**
* @brief Defines the message handler.
* @note While the message handler is invoked, @p self will point
* to the companion object to enable send() and reply().
* to the companion object to enable function calls to send().
*/
template<typename... Ts>
void set_message_handler(Ts&&... args) {
......@@ -97,7 +97,7 @@ class actor_companion_mixin : public Base {
/**
* @brief Invokes the message handler with @p msg.
* @note While the message handler is invoked, @p self will point
* to the companion object to enable send() and reply().
* to the companion object to enable function calls to send().
*/
void handle_message(const message_pointer& msg) {
if (!msg) return;
......
......@@ -87,6 +87,13 @@ class any_tuple {
template<typename... Ts>
any_tuple(cow_tuple<Ts...>&& arg) : m_vals(std::move(arg.m_vals)) { }
/**
* @brief Creates a tuple from a set of values.
*/
template<typename T, typename... Ts>
any_tuple(T v0, Ts&&... vs)
: m_vals(make_cow_tuple(std::move(v0), std::forward<Ts>(vs)...).vals()) { }
/**
* @brief Move constructor.
*/
......
......@@ -276,7 +276,7 @@
* on(atom("compute"), arg_match) >> [](int i0, int i1, int i2)
* {
* // send our result back to the sender of this messages
* reply(atom("result"), i0 + i1 + i2);
* return make_cow_tuple(atom("result"), i0 + i1 + i2);
* }
* );
* @endcode
......@@ -296,10 +296,10 @@
* void math_actor() {
* receive_loop (
* on(atom("plus"), arg_match) >> [](int a, int b) {
* reply(atom("result"), a + b);
* return make_cow_tuple(atom("result"), a + b);
* },
* on(atom("minus"), arg_match) >> [](int a, int b) {
* reply(atom("result"), a - b);
* return make_cow_tuple(atom("result"), a - b);
* }
* );
* }
......@@ -340,7 +340,7 @@
* std::vector<int> vec {1, 2, 3, 4};
* auto i = vec.begin();
* receive_for(i, vec.end()) (
* on(atom("get")) >> [&]() { reply(atom("result"), *i); }
* on(atom("get")) >> [&]() -> any_tuple { return {atom("result"), *i}; }
* );
* @endcode
*
......@@ -654,6 +654,11 @@ inline const actor_ostream& operator<<(const actor_ostream& o, const any_tuple&
return o.write(cppa::to_string(arg));
}
// disambiguate between conversion to string and to any_tuple
inline const actor_ostream& operator<<(const actor_ostream& o, const char* arg) {
return o << std::string{arg};
}
template<typename T>
inline typename std::enable_if<
!std::is_convertible<T, std::string>::value
......
......@@ -184,8 +184,6 @@ class local_actor : public extend<actor>::with<memory_cached> {
/**
* @brief Returns the sender of the last dequeued message.
* @warning Only set during callback invocation.
* @note Implicitly used by the function {@link cppa::reply}.
* @see cppa::reply()
*/
inline actor_ptr& last_sender();
......
......@@ -440,6 +440,17 @@ std::ostream& operator<<(std::ostream& lhs, const optional_variant<T0, Ts...>& r
return apply_visitor(detail::optional_variant_ostream_helper{lhs}, rhs);
}
template<typename T, typename... Ts>
optional_variant<T, typename util::rm_const_and_ref<Ts>::type...>
make_optional_variant(T value, Ts&&... args) {
return {std::move(value), std::forward<Ts>(args)...};
}
template<typename... Ts>
inline optional_variant<Ts...> make_optional_variant(optional_variant<Ts...> value) {
return std::move(value);
}
} // namespace cppa
#endif // OPTIONAL_VARIANT_HPP
......@@ -67,7 +67,7 @@ void receive_loop(Ts&&... args);
* @code
* int i = 0;
* receive_for(i, 10) (
* on(atom("get")) >> [&]() { reply("result", i); }
* on(atom("get")) >> [&]() -> any_tuple { return {"result", i}; }
* );
* @endcode
* @param begin First value in range.
......
......@@ -41,6 +41,10 @@ namespace cppa {
struct typed_actor_result_visitor {
typed_actor_result_visitor() : m_hdl(self->make_response_handle()) { }
typed_actor_result_visitor(response_handle hdl) : m_hdl(hdl) { }
inline void operator()(const none_t&) const {
CPPA_LOG_ERROR("a typed actor received a "
"non-matching message: "
......@@ -51,29 +55,27 @@ struct typed_actor_result_visitor {
template<typename T>
inline void operator()(T& value) const {
reply(std::move(value));
reply_to(m_hdl, std::move(value));
}
template<typename... Ts>
inline void operator()(cow_tuple<Ts...>& value) const {
reply_tuple(std::move(value));
reply_tuple_to(m_hdl, std::move(value));
}
template<typename R>
inline void operator()(typed_continue_helper<R>& ch) const {
auto hdl = self->make_response_handle();
auto hdl = m_hdl;
ch.continue_with([=](R value) {
reply_to(hdl, std::move(value));
typed_actor_result_visitor tarv{hdl};
auto ov = make_optional_variant(std::move(value));
apply_visitor(tarv, ov);
});
}
template<typename... Rs>
inline void operator()(typed_continue_helper<cow_tuple<Rs...>>& ch) const {
auto hdl = self->make_response_handle();
ch.continue_with([=](cow_tuple<Rs...> value) {
reply_tuple_to(hdl, std::move(value));
});
}
private:
response_handle m_hdl;
};
......
......@@ -33,6 +33,7 @@
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <type_traits>
......@@ -47,12 +48,14 @@ std::vector<std::string> split(const std::string& str,
template<typename Iterator>
typename std::enable_if<is_forward_iterator<Iterator>::value,std::string>::type
join(Iterator begin, Iterator end, const std::string& glue = "") {
std::string result;
std::for_each(begin, end, [&](const std::string& str) {
if (!result.empty()) result += glue;
result += str;
});
return result;
bool first = true;
std::ostringstream oss;
for ( ; begin != end; ++begin) {
if (first) first = false;
else oss << glue;
oss << *begin;
}
return oss.str();
}
template<typename Container>
......
......@@ -28,11 +28,11 @@ using namespace cppa::placeholders;
// our "service"
void calculator() {
become (
on(atom("plus"), arg_match) >> [](int a, int b) {
reply(atom("result"), a + b);
on(atom("plus"), arg_match) >> [](int a, int b) -> any_tuple {
return {atom("result"), a + b};
},
on(atom("minus"), arg_match) >> [](int a, int b) {
reply(atom("result"), a - b);
on(atom("minus"), arg_match) >> [](int a, int b) -> any_tuple {
return {atom("result"), a - b};
},
on(atom("quit")) >> [=]() {
self->quit();
......
......@@ -61,10 +61,10 @@ void ping(size_t num_pings) {
on(atom("kickoff"), arg_match) >> [=](const actor_ptr& pong) {
send(pong, atom("ping"), 1);
become (
on(atom("pong"), arg_match) >> [=](int value) {
on(atom("pong"), arg_match) >> [=](int value) -> any_tuple {
aout << "pong: " << value << endl;
if (++*count >= num_pings) self->quit_later();
else reply(atom("ping"), value + 1);
if (++*count >= num_pings) self->quit();
return {atom("ping"), value + 1};
}
);
}
......
......@@ -597,7 +597,7 @@ class default_meta_tuple : public uniform_type_info {
}
any_tuple as_any_tuple(void* ptr) const override {
return any_tuple{cast(ptr)};
return any_tuple{static_cast<any_tuple::raw_ptr>(cast(ptr))};
}
const char* name() const override {
......
......@@ -17,7 +17,7 @@ size_t s_pongs = 0;
behavior ping_behavior(size_t num_pings) {
return (
on(atom("pong"), arg_match) >> [num_pings](int value) {
on(atom("pong"), arg_match) >> [num_pings](int value) -> any_tuple {
CPPA_LOGF_ERROR_IF(!self->last_sender(), "last_sender() == nullptr");
CPPA_LOGF_INFO("received {'pong', " << value << "}");
//cout << to_string(self->last_dequeued()) << endl;
......@@ -27,7 +27,7 @@ behavior ping_behavior(size_t num_pings) {
send_exit(self->last_sender(), exit_reason::user_defined);
self->quit();
}
else reply(atom("ping"), value);
return {atom("ping"), value};
},
others() >> [] {
CPPA_LOGF_ERROR("unexpected message; "
......@@ -39,9 +39,9 @@ behavior ping_behavior(size_t num_pings) {
behavior pong_behavior() {
return (
on(atom("ping"), arg_match) >> [](int value) {
on(atom("ping"), arg_match) >> [](int value) -> any_tuple {
CPPA_LOGF_INFO("received {'ping', " << value << "}");
reply(atom("pong"), value + 1);
return {atom("pong"), value + 1};
},
others() >> [] {
CPPA_LOGF_ERROR("unexpected message; "
......
......@@ -45,9 +45,10 @@ void ping(size_t num_pings) {
on(atom("kickoff"), arg_match) >> [=](const actor_ptr& pong) {
send(pong, atom("ping"), 1);
become (
on(atom("pong"), arg_match) >> [=](int value) {
on(atom("pong"), arg_match)
>> [=](int value) -> cow_tuple<atom_value, int> {
if (++*count >= num_pings) self->quit();
else reply(atom("ping"), value + 1);
return make_cow_tuple(atom("ping"), value + 1);
},
others() >> CPPA_UNEXPECTED_MSG_CB()
);
......@@ -58,18 +59,21 @@ void ping(size_t num_pings) {
void pong() {
become (
on(atom("ping"), arg_match) >> [](int value) {
on(atom("ping"), arg_match)
>> [](int value) -> cow_tuple<atom_value, int> {
self->monitor(self->last_sender());
reply(atom("pong"), value);
// set next behavior
become (
on(atom("ping"), arg_match) >> [](int value) {
reply(atom("pong"), value);
return make_cow_tuple(atom("pong"), value);
},
on(atom("DOWN"), arg_match) >> [=](uint32_t reason) {
self->quit(reason);
},
others() >> CPPA_UNEXPECTED_MSG_CB()
);
// reply to 'ping'
return {atom("pong"), value};
},
others() >> CPPA_UNEXPECTED_MSG_CB()
);
......
......@@ -367,7 +367,7 @@ template<typename... Ts>
any_tuple make_dynamically_typed(Ts&&... args) {
auto oarr = new detail::object_array;
make_dynamically_typed_impl(*oarr, std::forward<Ts>(args)...);
return any_tuple{oarr};
return any_tuple{static_cast<any_tuple::raw_ptr>(oarr)};
}
void test_wildcards() {
......
......@@ -25,8 +25,8 @@ void reflector() {
become (
others() >> [=] {
CPPA_LOGF_INFO("reflect and quit");
reply_tuple(self->last_dequeued());
self->quit();
return self->last_dequeued();
}
);
}
......@@ -111,17 +111,17 @@ void spawn5_server(actor_ptr client, bool inverted) {
void spawn5_client() {
CPPA_SET_DEBUG_NAME("spawn5_client");
become (
on(atom("GetGroup")) >> [] {
on(atom("GetGroup")) >> []() -> group_ptr {
CPPA_LOGF_INFO("received {'GetGroup'}");
reply(group::get("local", "foobar"));
return group::get("local", "foobar");
},
on(atom("Spawn5"), arg_match) >> [=](const group_ptr& grp) {
on(atom("Spawn5"), arg_match) >> [=](const group_ptr& grp) -> any_tuple {
CPPA_LOGF_INFO("received {'Spawn5'}");
actor_vector vec;
for (int i = 0; i < 5; ++i) {
vec.push_back(spawn_in_group(grp, reflector));
}
reply(atom("ok"), std::move(vec));
return {atom("ok"), std::move(vec)};
},
on(atom("Spawn5Done")) >> [] {
CPPA_LOGF_INFO("received {'Spawn5Done'}");
......@@ -211,14 +211,15 @@ class client : public event_based_actor {
void test_group_comm_inverted() {
CPPA_PRINT("test group communication via network (inverted setup)");
become (
on(atom("GClient")) >> [=] {
on(atom("GClient")) >> [=]() -> any_tuple {
auto cptr = self->last_sender();
auto s5c = spawn<monitored>(spawn5_client);
reply(atom("GClient"), s5c);
// set next behavior
await_down(s5c, [=] {
CPPA_CHECKPOINT();
self->quit();
});
return {atom("GClient"), s5c};
}
);
}
......@@ -241,18 +242,18 @@ class server : public event_based_actor {
void await_spawn_ping() {
CPPA_PRINT("await {'SpawnPing'}");
become (
on(atom("SpawnPing")) >> [=] {
on(atom("SpawnPing")) >> [=]() -> any_tuple {
CPPA_PRINT("received {'SpawnPing'}");
auto client = self->last_sender();
CPPA_LOGF_ERROR_IF(!client, "last_sender() == nullptr");
CPPA_LOGF_INFO("spawn event-based ping actor");
auto pptr = spawn<monitored>(event_based_ping, num_pings);
reply(atom("PingPtr"), pptr);
CPPA_LOGF_INFO("wait until spawned ping actor is done");
await_down(pptr, [=] {
CPPA_CHECK_EQUAL(pongs(), num_pings);
await_sync_msg();
});
return {atom("PingPtr"), pptr};
}
);
}
......@@ -260,11 +261,11 @@ class server : public event_based_actor {
void await_sync_msg() {
CPPA_PRINT("await {'SyncMsg'}");
become (
on(atom("SyncMsg"), arg_match) >> [=](float f) {
on(atom("SyncMsg"), arg_match) >> [=](float f) -> atom_value {
CPPA_PRINT("received {'SyncMsg', " << f << "}");
CPPA_CHECK_EQUAL(f, 4.2f);
reply(atom("SyncReply"));
await_foobars();
return atom("SyncReply");
}
);
}
......@@ -273,13 +274,13 @@ class server : public event_based_actor {
CPPA_PRINT("await foobars");
auto foobars = make_shared<int>(0);
become (
on(atom("foo"), atom("bar"), arg_match) >> [=](int i) {
on(atom("foo"), atom("bar"), arg_match) >> [=](int i) -> any_tuple {
++*foobars;
reply_tuple(self->last_dequeued());
if (i == 99) {
CPPA_CHECK_EQUAL(*foobars, 100);
test_group_comm();
}
return self->last_dequeued();
}
);
}
......@@ -287,13 +288,13 @@ class server : public event_based_actor {
void test_group_comm() {
CPPA_PRINT("test group communication via network");
become (
on(atom("GClient")) >> [=] {
on(atom("GClient")) >> [=]() -> any_tuple {
auto cptr = self->last_sender();
auto s5c = spawn<monitored>(spawn5_client);
reply(atom("GClient"), s5c);
await_down(s5c, [=] {
test_group_comm_inverted(cptr);
});
return {atom("GClient"), s5c};
}
);
}
......
......@@ -159,7 +159,7 @@ int main() {
oarr->push_back(object::from(static_cast<uint32_t>(42)));
oarr->push_back(object::from("foo" ));
any_tuple atuple1(oarr);
any_tuple atuple1{static_cast<any_tuple::raw_ptr>(oarr)};
try {
auto opt = tuple_cast<uint32_t, string>(atuple1);
CPPA_CHECK(opt.valid());
......
......@@ -227,10 +227,10 @@ class fixed_stack : public sb_actor<fixed_stack> {
full = (
on(atom("push"), arg_match) >> [=](int) { },
on(atom("pop")) >> [=]() {
reply(atom("ok"), data.back());
on(atom("pop")) >> [=]() -> any_tuple {
data.pop_back();
become(filled);
return {atom("ok"), data.back()};
}
);
......@@ -240,11 +240,12 @@ class fixed_stack : public sb_actor<fixed_stack> {
if (data.size() == max_size)
become(full);
},
on(atom("pop")) >> [=]() {
reply(atom("ok"), data.back());
on(atom("pop")) >> [=]() -> any_tuple {
auto result = data.back();
data.pop_back();
if (data.empty())
become(empty);
return {atom("ok"), result};
}
);
......@@ -264,9 +265,9 @@ class fixed_stack : public sb_actor<fixed_stack> {
void echo_actor() {
become (
others() >> [] {
reply_tuple(self->last_dequeued());
others() >> []() -> any_tuple {
self->quit(exit_reason::normal);
return self->last_dequeued();
}
);
}
......@@ -616,7 +617,7 @@ int main() {
}
);
vector<int> expected{9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
CPPA_CHECK(values == expected);
CPPA_CHECK_EQUAL(util::join(values, ","), util::join(values, ","));
}
// terminate st
send_exit(st, exit_reason::user_defined);
......@@ -671,8 +672,9 @@ int main() {
on_arg_match >> [&](const string& str) {
CPPA_CHECK(self->last_sender() != nullptr);
CPPA_CHECK_EQUAL(str, "nothing");
reply("goodbye!");
self->quit();
// TODO: should return the value instead
send(self->last_sender(), "goodbye!");
},
after(chrono::minutes(1)) >> [] {
cerr << "PANIC!!!!" << endl;
......@@ -690,7 +692,7 @@ int main() {
send(sync_testee, "hi");
receive (
on("whassup?") >> [&]() -> std::string {
CPPA_CHECK(true);
CPPA_CHECKPOINT();
// this is NOT a reply, it's just an asynchronous message
send(self->last_sender(), "a lot!");
return "nothing";
......
......@@ -76,9 +76,9 @@ struct B : popular_actor {
struct C : sb_actor<C> {
behavior init_state = (
on(atom("gogo")) >> [=] {
reply(atom("gogogo"));
on(atom("gogo")) >> [=]() -> atom_value {
self->quit();
return atom("gogogo");
}
);
};
......
......@@ -90,10 +90,10 @@ optional<int> str2int(const std::string& str) {
struct dummy_receiver : event_based_actor {
void init() {
become(
on_arg_match >> [=](expensive_copy_struct& ecs) {
on_arg_match >> [=](expensive_copy_struct& ecs) -> expensive_copy_struct {
ecs.value = 42;
reply(std::move(ecs));
quit();
return std::move(ecs);
}
);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment