Wt examples  3.2.1
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
ChatEvent Class Reference

Encapsulate a chat event. More...

#include <SimpleChatServer.h>

List of all members.

Public Types

enum  Type { Login, Logout, Rename, Message }
 Enumeration for the event type. More...

Public Member Functions

Type type () const
 Get the event type.
const Wt::WStringuser () const
 Get the user who caused the event.
const Wt::WStringmessage () const
 Get the message of the event.
const Wt::WStringdata () const
 Get the extra data for this event.
const Wt::WString formattedHTML (const Wt::WString &user, Wt::TextFormat format) 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, const Wt::WString &data=Wt::WString::Empty)

Private Attributes

Type type_
Wt::WString user_
Wt::WString data_
Wt::WString message_

Friends

class SimpleChatServer

Detailed Description

Encapsulate a chat event.

Definition at line 30 of file SimpleChatServer.h.


Member Enumeration Documentation

Enumeration for the event type.

Enumerator:
Login 
Logout 
Rename 
Message 

Definition at line 35 of file SimpleChatServer.h.


Constructor & Destructor Documentation

ChatEvent::ChatEvent ( const Wt::WString user,
const Wt::WString message 
)
inlineprivate

Definition at line 69 of file SimpleChatServer.h.

: type_(Message), user_(user), message_(message)
{ }
ChatEvent::ChatEvent ( Type  type,
const Wt::WString user,
const Wt::WString data = Wt::WString::Empty 
)
inlineprivate

Definition at line 73 of file SimpleChatServer.h.

: type_(type), user_(user), data_(data)
{ }

Member Function Documentation

const Wt::WString& ChatEvent::data ( ) const
inline

Get the extra data for this event.

Definition at line 51 of file SimpleChatServer.h.

{ return data_; }
const WString ChatEvent::formattedHTML ( const Wt::WString user,
Wt::TextFormat  format 
) const

Get the message formatted as HTML, rendered for the given user.

The format indicates how the message should be formatted.

Definition at line 15 of file SimpleChatServer.C.

{
switch (type_) {
case Login:
return WString::fromUTF8("<span class='chat-info'>")
+ WWebWidget::escapeText(user_) + " joined.</span>";
case Logout:
return WString::fromUTF8("<span class='chat-info'>")
+ ((user == user_) ?
WString::fromUTF8("You") :
WWebWidget::escapeText(user_))
+ " logged out.</span>";
case Rename:
return "<span class='chat-info'>"
+ ((user == data_ || user == user_) ?
"You are" :
(WWebWidget::escapeText(user_) + " is"))
+ " now known as " + WWebWidget::escapeText(data_) + ".</span>";
case Message:{
WString result;
result = WString("<span class='")
+ ((user == user_) ?
"chat-self" :
"chat-user")
+ "'>" + WWebWidget::escapeText(user_) + ":</span>";
WString msg
= (format == XHTMLText ? message_ : WWebWidget::escapeText(message_));
if (message_.toUTF8().find(user.toUTF8()) != std::string::npos)
return result + "<span class='chat-highlight'>" + msg + "</span>";
else
return result + msg;
}
default:
return "";
}
}
const Wt::WString& ChatEvent::message ( ) const
inline

Get the message of the event.

Definition at line 47 of file SimpleChatServer.h.

{ return message_; }
Type ChatEvent::type ( ) const
inline

Get the event type.

Definition at line 39 of file SimpleChatServer.h.

{ return type_; }
const Wt::WString& ChatEvent::user ( ) const
inline

Get the user who caused the event.

Definition at line 43 of file SimpleChatServer.h.

{ return user_; }

Friends And Related Function Documentation

friend class SimpleChatServer
friend

Definition at line 78 of file SimpleChatServer.h.


Member Data Documentation

Wt::WString ChatEvent::data_
private

Definition at line 63 of file SimpleChatServer.h.

Wt::WString ChatEvent::message_
private

Definition at line 64 of file SimpleChatServer.h.

Type ChatEvent::type_
private

Definition at line 61 of file SimpleChatServer.h.

Wt::WString ChatEvent::user_
private

Definition at line 62 of file SimpleChatServer.h.


The documentation for this class was generated from the following files:

Generated on Tue Jun 19 2012 for the C++ Web Toolkit (Wt) by doxygen 1.8.1