From c6750bbb54eb2af0e534791755bd68cc7fd4d556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Tue, 29 Nov 2016 17:54:00 +0100 Subject: [PATCH] added chat_message.hpp to represent messages --- chat_messages.h | 36 ------------------------------------ chat_messages.hpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 36 deletions(-) delete mode 100644 chat_messages.h create mode 100644 chat_messages.hpp diff --git a/chat_messages.h b/chat_messages.h deleted file mode 100644 index b80f9e8..0000000 --- a/chat_messages.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#include -#include - - - -enum class message -{ - HELLO = 1, NEPTUN = 2, PASSW = 3, - SERVER_DIRECTION = 4, MESSAGE = 5, - PING = 6, PONG = 7, BYE = 8, - LOGIN = 9, LOGOUT = 10 -}; - - -class chat_message -{ -protected: - virtual message get_command() = 0; - virtual std::string get_content() = 0; -public: -}; - - -class client_message : public chat_message -{ -public: - void send(boost::asio::ip::tcp::socket& socket); -}; - - -class server_message : public chat_message -{ -public: - void receive(boost::asio::ip::tcp::socket& socket); -}; \ No newline at end of file diff --git a/chat_messages.hpp b/chat_messages.hpp new file mode 100644 index 0000000..88265b6 --- /dev/null +++ b/chat_messages.hpp @@ -0,0 +1,30 @@ +#pragma once +#include +#include + + + +enum class message +{ + HELLO = 1, NEPTUN = 2, PASSW = 3, + SERVER_DIRECTION = 4, MESSAGE = 5, + PING = 6, PONG = 7, BYE = 8, + LOGIN = 9, LOGOUT = 10 +}; + + +class chat_message +{ + message _header; + std::string _content; + +public: + chat_message(message header, std::string content) + :_header(header), _content(content) {} + + chat_message(std::underlying_type::type header_integral, std::string content) + :_header(static_cast(header_integral)), _content(content) {} + + std::string get() + { return std::to_string(static_cast::type>(_header)) + _content; } +};