added chat_message.hpp to represent messages

This commit is contained in:
Kjistóf 2016-11-29 17:54:00 +01:00
parent be89be49da
commit c6750bbb54
2 changed files with 30 additions and 36 deletions

View File

@ -1,36 +0,0 @@
#pragma once
#include <string>
#include <boost/asio.hpp>
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);
};

30
chat_messages.hpp Normal file
View File

@ -0,0 +1,30 @@
#pragma once
#include <string>
#include <type_traits>
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<message>::type header_integral, std::string content)
:_header(static_cast<message>(header_integral)), _content(content) {}
std::string get()
{ return std::to_string(static_cast<std::underlying_type<message>::type>(_header)) + _content; }
};