Wt examples: ChatEvent Class Reference

Wt examples 4.10.4

Loading...
Searching...
No Matches
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.
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 & | data () 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 29 of file SimpleChatServer.h.

## Member Enumeration Documentation

## ◆ Type

enum ChatEvent::Type

Enumeration for the event type.

Enumerator
Login |
Logout |
Rename |
Message |

Definition at line 34 of file SimpleChatServer.h.

34{ Login, Logout, Rename, Message };
ChatEvent::Login
@ Login
Definition SimpleChatServer.h:34
ChatEvent::Logout
@ Logout
Definition SimpleChatServer.h:34
ChatEvent::Rename
@ Rename
Definition SimpleChatServer.h:34
ChatEvent::Message
@ Message
Definition SimpleChatServer.h:34

## Constructor & Destructor Documentation

## ◆ ChatEvent() [1/2]

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

Definition at line 68 of file SimpleChatServer.h.

69 : type_(Message), user_(user), message_(message)
70 { }
ChatEvent::user_
Wt::WString user_
Definition SimpleChatServer.h:61
ChatEvent::message
const Wt::WString & message() const
Get the message of the event.
Definition SimpleChatServer.h:46
ChatEvent::type_
Type type_
Definition SimpleChatServer.h:60
ChatEvent::message_
Wt::WString message_
Definition SimpleChatServer.h:63
ChatEvent::user
const Wt::WString & user() const
Get the user who caused the event.
Definition SimpleChatServer.h:42

## ◆ ChatEvent() [2/2]

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

Definition at line 72 of file SimpleChatServer.h.

74 : type_(type), user_(user), data_(data)
75 { }
ChatEvent::type
Type type() const
Get the event type.
Definition SimpleChatServer.h:38
ChatEvent::data
const Wt::WString & data() const
Get the extra data for this event.
Definition SimpleChatServer.h:50
ChatEvent::data_
Wt::WString data_
Definition SimpleChatServer.h:62

## Member Function Documentation

## ◆ data()

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

Get the extra data for this event.

Definition at line 50 of file SimpleChatServer.h.

50{ return data_; }

## ◆ formattedHTML()

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}
Wt
Definition AddresseeEdit.h:16

## ◆ message()

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

Get the message of the event.

Definition at line 46 of file SimpleChatServer.h.

46{ return message_; }

## ◆ type()

Type ChatEvent::type | ( |  | ) | const
| inline

Get the event type.

Definition at line 38 of file SimpleChatServer.h.

38{ return type_; }

## ◆ user()

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

Get the user who caused the event.

Definition at line 42 of file SimpleChatServer.h.

42{ return user_; }

## Friends And Related Symbol Documentation

## ◆ SimpleChatServer

friend class SimpleChatServer
| friend

Definition at line 77 of file SimpleChatServer.h.

## Member Data Documentation

## ◆ data_

Wt::WString ChatEvent::data_
| private

Definition at line 62 of file SimpleChatServer.h.

## ◆ message_

Wt::WString ChatEvent::message_
| private

Definition at line 63 of file SimpleChatServer.h.

## ◆ type_

Type ChatEvent::type_
| private

Definition at line 60 of file SimpleChatServer.h.

## ◆ user_

Wt::WString ChatEvent::user_
| private

Definition at line 61 of file SimpleChatServer.h.

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

- simplechat/SimpleChatServer.h
- simplechat/SimpleChatServer.C