fixed chat_message: now enum class message has underlying type of char
This commit is contained in:
		@@ -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(); }
 | 
			
		||||
		Reference in New Issue
	
	Block a user