From 3faabb1e4ec106f00f2a2810804684f8d3821dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Mon, 5 Dec 2016 12:57:57 +0100 Subject: [PATCH] receive_policy must provide an invalid_msg_do_what method --- chat_networking.hpp | 2 ++ check_policy.hpp | 9 ++++++++- commandline_chat.cpp | 5 ++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/chat_networking.hpp b/chat_networking.hpp index 0114ccf..d452fda 100644 --- a/chat_networking.hpp +++ b/chat_networking.hpp @@ -171,6 +171,8 @@ namespace chat receive_policy::logout_do_what (chat_message(message::LOGOUT, content)); break; + default: + receive_policy::invalid_msg_do_what(msg); } for (auto& fun : _subscriptions) // notify subscribers diff --git a/check_policy.hpp b/check_policy.hpp index 3fc045b..fc95c91 100644 --- a/check_policy.hpp +++ b/check_policy.hpp @@ -10,7 +10,8 @@ * - static void handshake_do_what(chat_message) * - static void serverdirection_do_what(chat_message) * - static void login_do_what(chat_message) - * - static void logout_do_what(chat_message) */ + * - static void logout_do_what(chat_message) + * - static void invalid_msg_do_what(chat_message) */ template struct is_valid_receive_policy : std::false_type {}; @@ -48,6 +49,12 @@ struct is_valid_receive_policy< ::logout_do_what(std::declval())), void >::value + && + std::is_same< + decltype(PolicyCandidate + ::invalid_msg_do_what(std::declval())), + void + >::value >::type> : std::true_type {}; diff --git a/commandline_chat.cpp b/commandline_chat.cpp index 18471e9..14b5677 100644 --- a/commandline_chat.cpp +++ b/commandline_chat.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "chat_networking.hpp" @@ -20,6 +21,9 @@ struct receive_policy_stdout static void logout_do_what(const chat::chat_message& msg) { std::cout << msg.get_content() << " kilépett.\n"; } + + static void invalid_msg_do_what(const chat::chat_message& msg) + { throw std::runtime_error("Invalid message received!"); } }; struct send_policy_stdout @@ -45,7 +49,6 @@ int main() chat::client_network_manager cnm(ios, epit, "BATMAN"); std::thread t([&ios]{ ios.run(); }); - std::string input; while (true) {