From 3cfaab9a2debe03829b1ff26fe94e775e1d18e0a Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Tue, 12 Nov 2013 23:47:00 +0100 Subject: Map irc commands to callbacks, in a clean way --- src/irc/irc_client.hpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/irc/irc_client.hpp') diff --git a/src/irc/irc_client.hpp b/src/irc/irc_client.hpp index 722f850..07ff02c 100644 --- a/src/irc/irc_client.hpp +++ b/src/irc/irc_client.hpp @@ -167,11 +167,33 @@ private: */ std::vector channels_to_join; bool welcomed; - IrcClient(const IrcClient&) = delete; IrcClient(IrcClient&&) = delete; IrcClient& operator=(const IrcClient&) = delete; IrcClient& operator=(IrcClient&&) = delete; }; +/** + * Define a map of functions to be called for each IRC command we can + * handle. + */ +typedef void (IrcClient::*irc_callback_t)(const IrcMessage&); + +static const std::unordered_map irc_callbacks = { + {"NOTICE", &IrcClient::forward_server_message}, + {"375", &IrcClient::forward_server_message}, + {"372", &IrcClient::forward_server_message}, + {"JOIN", &IrcClient::on_channel_join}, + {"PRIVMSG", &IrcClient::on_channel_message}, + {"353", &IrcClient::set_and_forward_user_list}, + {"332", &IrcClient::on_topic_received}, + {"366", &IrcClient::on_channel_completely_joined}, + {"001", &IrcClient::on_welcome_message}, + {"PART", &IrcClient::on_part}, + {"QUIT", &IrcClient::on_quit}, + {"NICK", &IrcClient::on_nick}, + {"MODE", &IrcClient::on_mode}, + {"PING", &IrcClient::send_pong_command}, +}; + #endif // IRC_CLIENT_INCLUDED -- cgit v1.2.3