moved everything to namespace chat to avoid namespace pollution
This commit is contained in:
parent
07284e5dc7
commit
75f77766c1
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace chat
|
||||||
|
{
|
||||||
enum class message : char
|
enum class message : char
|
||||||
{
|
{
|
||||||
HELLO = 1, NEPTUN = 2, PASSW = 3,
|
HELLO = 1, NEPTUN = 2, PASSW = 3,
|
||||||
@ -21,10 +23,12 @@ class chat_message
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
chat_message(message header, std::string content = "")
|
chat_message(message header, std::string content = "")
|
||||||
:_header(header), _content(content) {}
|
: _header(header), _content(content)
|
||||||
|
{}
|
||||||
|
|
||||||
chat_message(std::underlying_type<message>::type header_integral, std::string content)
|
chat_message(std::underlying_type<message>::type header_integral, std::string content)
|
||||||
:_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 static_cast<char>(_header) + _content + static_cast<char>(message::TERM); }
|
{ return static_cast<char>(_header) + _content + static_cast<char>(message::TERM); }
|
||||||
@ -33,3 +37,4 @@ public:
|
|||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const chat_message& msg)
|
std::ostream& operator<<(std::ostream& os, const chat_message& msg)
|
||||||
{ return os << msg.get(); }
|
{ return os << msg.get(); }
|
||||||
|
}
|
@ -8,9 +8,13 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace chat
|
||||||
|
{
|
||||||
|
using namespace chat;
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
using boost::asio::ip::tcp;
|
using boost::asio::ip::tcp;
|
||||||
|
|
||||||
|
|
||||||
class client_network_manager
|
class client_network_manager
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -88,6 +92,10 @@ public:
|
|||||||
void send(chat_message message)
|
void send(chat_message message)
|
||||||
{
|
{
|
||||||
_ios.post([this, message]
|
_ios.post([this, message]
|
||||||
{ asio::async_write(_socket, asio::buffer(message.get()), [](boost::system::error_code, size_t){}); });
|
{
|
||||||
|
asio::async_write(_socket, asio::buffer(message.get()), [](boost::system::error_code, size_t)
|
||||||
|
{});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user