fixed chat_message: now enum class message has underlying type of char

This commit is contained in:
Kjistóf 2016-12-03 11:51:27 +01:00
parent 28f1fe7655
commit f8c57c8e24
1 changed files with 8 additions and 3 deletions

View File

@ -1,15 +1,16 @@
#pragma once
#include <string>
#include <type_traits>
#include <ostream>
enum class message
enum class message : char
{
HELLO = 1, NEPTUN = 2, PASSW = 3,
SERVER_DIRECTION = 4, MESSAGE = 5,
PING = 6, PONG = 7, BYE = 8,
LOGIN = 9, LOGOUT = 10
LOGIN = 9, LOGOUT = 10, TERM = 0x7f
};
@ -26,5 +27,9 @@ public:
:_header(static_cast<message>(header_integral)), _content(content) {}
std::string get() const
{ return std::to_string(static_cast<std::underlying_type<message>::type>(_header)) + _content; }
{ return static_cast<char>(_header) + _content + static_cast<char>(message::TERM); }
};
std::ostream& operator<<(std::ostream& os, const chat_message& msg)
{ return os << msg.get(); }