Wt examples  3.7.1
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 30 of file SimpleChatServer.h.

Member Enumeration Documentation

◆ Type

Enumeration for the event type.

Enumerator
Login 
Logout 
Rename 
Message 

Definition at line 35 of file SimpleChatServer.h.

Constructor & Destructor Documentation

◆ ChatEvent() [1/2]

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

Definition at line 69 of file SimpleChatServer.h.

70  : type_(Message), user_(user), message_(message)
71  { }
Wt::WString message_
Wt::WString user_

◆ ChatEvent() [2/2]

ChatEvent::ChatEvent ( Type  type,
const Wt::WString user,
const Wt::WString data = Wt::WString::Empty 
)
inlineprivate

Definition at line 73 of file SimpleChatServer.h.

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

Member Function Documentation

◆ data()

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

Get the extra data for this event.

Definition at line 51 of file SimpleChatServer.h.

51 { return data_; }
Wt::WString data_

◆ formattedHTML()

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.

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

◆ message()

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

Get the message of the event.

Definition at line 47 of file SimpleChatServer.h.

47 { return message_; }
Wt::WString message_

◆ type()

Type ChatEvent::type ( ) const
inline

Get the event type.

Definition at line 39 of file SimpleChatServer.h.

39 { return type_; }

◆ user()

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

Get the user who caused the event.

Definition at line 43 of file SimpleChatServer.h.

43 { return user_; }
Wt::WString user_

Friends And Related Function Documentation

◆ SimpleChatServer

friend class SimpleChatServer
friend

Definition at line 78 of file SimpleChatServer.h.

Member Data Documentation

◆ data_

Wt::WString ChatEvent::data_
private

Definition at line 63 of file SimpleChatServer.h.

◆ message_

Wt::WString ChatEvent::message_
private

Definition at line 64 of file SimpleChatServer.h.

◆ type_

Type ChatEvent::type_
private

Definition at line 61 of file SimpleChatServer.h.

◆ user_

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 Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13