Wt examples  4.0.0
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
ChatEvent Class Reference

Encapsulate a chat event. More...

#include <SimpleChatServer.h>

Public Types

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

Public Member Functions

Type type () const
 Get the event type. More...
 
const Wt::WStringuser () const
 Get the user who caused the event. More...
 
const Wt::WStringmessage () const
 Get the message of the event. More...
 
const Wt::WStringdata () const
 Get the extra data for this event. More...
 
const Wt::WString formattedHTML (const Wt::WString &user, Wt::TextFormat format) const
 Get the message formatted as HTML, rendered for the given user. More...
 

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 31 of file SimpleChatServer.h.

Member Enumeration Documentation

Enumeration for the event type.

Enumerator
Login 
Logout 
Rename 
Message 

Definition at line 36 of file SimpleChatServer.h.

Constructor & Destructor Documentation

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

Definition at line 70 of file SimpleChatServer.h.

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

Definition at line 74 of file SimpleChatServer.h.

76  : type_(type), user_(user), data_(data)
77  { }
Type type() const
Get the event type.
Wt::WString user_
Wt::WString data_

Member Function Documentation

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

Get the extra data for this event.

Definition at line 52 of file SimpleChatServer.h.

52 { return data_; }
Wt::WString data_
const Wt::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 13 of file SimpleChatServer.C.

15 {
16  switch (type_) {
17  case Login:
18  return Wt::WString("<span class='chat-info'>")
19  + Wt::WWebWidget::escapeText(user_) + " joined.</span>";
20  case Logout:
21  return Wt::WString("<span class='chat-info'>")
22  + ((user == user_) ?
23  Wt::WString("You") :
24  Wt::WWebWidget::escapeText(user_))
25  + " logged out.</span>";
26  case Rename:
27  return "<span class='chat-info'>"
28  + ((user == data_ || user == user_) ?
29  "You are" :
30  (Wt::WWebWidget::escapeText(user_) + " is"))
31  + " now known as " + Wt::WWebWidget::escapeText(data_) + ".</span>";
32  case Message:{
33  Wt::WString result;
34 
35  result = Wt::WString("<span class='")
36  + ((user == user_) ?
37  "chat-self" :
38  "chat-user")
39  + "'>" + Wt::WWebWidget::escapeText(user_) + ":</span>";
40 
41  Wt::WString msg
42  = (format == Wt::TextFormat::XHTML ? message_ : Wt::WWebWidget::escapeText(message_));
43 
44  if (message_.toUTF8().find(user.toUTF8()) != std::string::npos)
45  return result + "<span class='chat-highlight'>" + msg + "</span>";
46  else
47  return result + msg;
48  }
49  default:
50  return "";
51  }
52 }
std::string toUTF8() const
Wt::WString message_
Wt::WString user_
Wt::WString data_
const Wt::WString& ChatEvent::message ( ) const
inline

Get the message of the event.

Definition at line 48 of file SimpleChatServer.h.

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

Get the event type.

Definition at line 40 of file SimpleChatServer.h.

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

Get the user who caused the event.

Definition at line 44 of file SimpleChatServer.h.

44 { return user_; }
Wt::WString user_

Friends And Related Function Documentation

friend class SimpleChatServer
friend

Definition at line 79 of file SimpleChatServer.h.

Member Data Documentation

Wt::WString ChatEvent::data_
private

Definition at line 64 of file SimpleChatServer.h.

Wt::WString ChatEvent::message_
private

Definition at line 65 of file SimpleChatServer.h.

Type ChatEvent::type_
private

Definition at line 62 of file SimpleChatServer.h.

Wt::WString ChatEvent::user_
private

Definition at line 63 of file SimpleChatServer.h.


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

Generated on Mon Sep 4 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11