fixed chat_message: now enum class message has underlying type of char
This commit is contained in:
parent
28f1fe7655
commit
f8c57c8e24
@ -1,15 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum class message
|
enum class message : char
|
||||||
{
|
{
|
||||||
HELLO = 1, NEPTUN = 2, PASSW = 3,
|
HELLO = 1, NEPTUN = 2, PASSW = 3,
|
||||||
SERVER_DIRECTION = 4, MESSAGE = 5,
|
SERVER_DIRECTION = 4, MESSAGE = 5,
|
||||||
PING = 6, PONG = 7, BYE = 8,
|
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) {}
|
:_header(static_cast<message>(header_integral)), _content(content) {}
|
||||||
|
|
||||||
std::string get() const
|
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(); }
|
Loading…
Reference in New Issue
Block a user