Encapsulate a chat event. More...
#include <SimpleChatServer.h>
Public Types | |
| enum | Type { Login, Logout, Message } |
Enumeration for the event type. More... | |
Public Member Functions | |
| Type | type () const |
| Get the event type. | |
| const Wt::WString & | user () const |
| Get the user who caused the event. | |
| const Wt::WString & | message () const |
| Get the message of the event. | |
| const Wt::WString | formattedHTML (const Wt::WString &user) const |
| Get the message formatted as HTML, rendered for the given user. | |
Private Member Functions | |
| ChatEvent (const Wt::WString &user, const Wt::WString &message) | |
| ChatEvent (Type type, const Wt::WString &user) | |
Private Attributes | |
| Type | type_ |
| Wt::WString | user_ |
| Wt::WString | message_ |
Friends | |
| class | SimpleChatServer |
Encapsulate a chat event.
Definition at line 24 of file SimpleChatServer.h.
| enum ChatEvent::Type |
Enumeration for the event type.
Definition at line 29 of file SimpleChatServer.h.
{ Login, Logout, Message };
| ChatEvent::ChatEvent | ( | const Wt::WString & | user, | |
| const Wt::WString & | message | |||
| ) | [inline, private] |
| ChatEvent::ChatEvent | ( | Type | type, | |
| const Wt::WString & | user | |||
| ) | [inline, private] |
Definition at line 59 of file SimpleChatServer.h.
| const WString ChatEvent::formattedHTML | ( | const Wt::WString & | user | ) | const |
Get the message formatted as HTML, rendered for the given user.
Definition at line 14 of file SimpleChatServer.C.
{
switch (type_) {
case Login:
return "<span class='chat-info'>"
+ user_ + " joined the conversation.</span>";
case Logout:
return "<span class='chat-info'>"
+ ((user == user_) ? "You" : user_)
+ " logged out.</span>";
case Message:{
WString result;
result = WString("<span class='")
+ ((user == user_) ? "chat-self" : "chat-user")
+ "'>" + user_ + ":</span>";
if (message_.toUTF8().find(user.toUTF8()) != std::string::npos)
return result + "<span class='chat-highlight'>" + message_ + "</span>";
else
return result + message_;
}
default:
return "";
}
}
| const Wt::WString& ChatEvent::message | ( | ) | const [inline] |
Get the message of the event.
Definition at line 41 of file SimpleChatServer.h.
{ return message_; }
| Type ChatEvent::type | ( | ) | const [inline] |
| const Wt::WString& ChatEvent::user | ( | ) | const [inline] |
Get the user who caused the event.
Definition at line 37 of file SimpleChatServer.h.
{ return user_; }
friend class SimpleChatServer [friend] |
Definition at line 63 of file SimpleChatServer.h.
Wt::WString ChatEvent::message_ [private] |
Definition at line 50 of file SimpleChatServer.h.
Type ChatEvent::type_ [private] |
Definition at line 48 of file SimpleChatServer.h.
Wt::WString ChatEvent::user_ [private] |
Definition at line 49 of file SimpleChatServer.h.
1.7.1