ChatEvent Class Reference
[Chat example]

Encapsulate a chat event. More...

#include <SimpleChatServer.h>

List of all members.

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::WStringuser () const
 Get the user who caused the event.
const Wt::WStringmessage () 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


Detailed Description

Encapsulate a chat event.

Definition at line 24 of file SimpleChatServer.h.


Member Enumeration Documentation

Enumeration for the event type.

Enumerator:
Login 
Logout 
Message 

Definition at line 29 of file SimpleChatServer.h.

00029 { Login, Logout, Message };


Constructor & Destructor Documentation

ChatEvent::ChatEvent ( const Wt::WString user,
const Wt::WString message 
) [inline, private]

Definition at line 55 of file SimpleChatServer.h.

00056     : type_(Message), user_(user), message_(message)
00057   { }

ChatEvent::ChatEvent ( Type  type,
const Wt::WString user 
) [inline, private]

Definition at line 59 of file SimpleChatServer.h.

00060     : type_(type), user_(user)
00061   { }


Member Function Documentation

Type ChatEvent::type (  )  const [inline]

Get the event type.

Definition at line 33 of file SimpleChatServer.h.

00033 { return type_; }

const Wt::WString& ChatEvent::user (  )  const [inline]

Get the user who caused the event.

Definition at line 37 of file SimpleChatServer.h.

00037 { return user_; }

const Wt::WString& ChatEvent::message (  )  const [inline]

Get the message of the event.

Definition at line 41 of file SimpleChatServer.h.

00041 { return message_; }

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.

00015 {
00016   switch (type_) {
00017   case Login:
00018     return "<span class='chat-info'>"
00019       + user_ + " joined the conversation.</span>";
00020   case Logout:
00021     return "<span class='chat-info'>"
00022       + ((user == user_) ? "You" : user_)
00023       + " logged out.</span>";
00024   case Message:{
00025     WString result;
00026 
00027     result = WString("<span class='")
00028       + ((user == user_) ? "chat-self" : "chat-user")
00029       + "'>" + user_ + ":</span>";
00030 
00031     if (message_.toUTF8().find(user.toUTF8()) != std::string::npos)
00032       return result + "<span class='chat-highlight'>" + message_ + "</span>";
00033     else
00034       return result + message_;
00035   }
00036   default:
00037     return "";
00038   }
00039 }


Friends And Related Function Documentation

friend class SimpleChatServer [friend]

Definition at line 63 of file SimpleChatServer.h.


Member Data Documentation

Definition at line 48 of file SimpleChatServer.h.

Definition at line 49 of file SimpleChatServer.h.

Definition at line 50 of file SimpleChatServer.h.


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

Generated on Thu May 20 18:14:56 2010 for Wt by doxygen 1.5.6