Design Pattern Examples
Overview of object-oriented design patterns
HandlerChain_Message_Class.h
Go to the documentation of this file.
1
6
7#pragma once
8#ifndef __HANDLERCHAIN_MESSAGE_CLASS_H__
9#define __HANDLERCHAIN_MESSAGE_CLASS_H__
10
11#include <string>
12
13#include "helpers/formatstring.h"
14
16{
17
22 {
28 Close = 0,
29
34
39 };
40
41
42
43 //========================================================================
44 //========================================================================
45 //========================================================================
46
47
48
55 {
59 int X;
60
64 int Y;
65
71 MessagePosition(int x, int y)
72 : X(x)
73 , Y(y)
74 {
75 }
76
81 std::string ToString()
82 {
83 return Helpers::formatstring("x=%2d,y=%2d", X, Y);
84 }
85 };
86
87
88
89 //========================================================================
90 //========================================================================
91 //========================================================================
92
93
94
99 struct Message
100 {
105
112
120 Message(enum MessageType type, struct MessagePosition position)
121 : MessageType(type)
122 , Position(position)
123 {
124 }
125
130 std::string ToString()
131 {
132 std::string messageTypeAsString;
133 switch (MessageType)
134 {
136 messageTypeAsString = "Close";
137 break;
138
140 messageTypeAsString = "ButtonDown";
141 break;
142
144 messageTypeAsString = "ButtonUp";
145 break;
146
147 default:
148 messageTypeAsString = "Unknown message type";
149 break;
150 }
151 return Helpers::formatstring("%s at (%s)", messageTypeAsString.c_str(), Position.ToString().c_str());
152 }
153 };
154
155} // end namespace
156
157#endif // __HANDLERCHAIN_MESSAGE_CLASS_H__
The namespace containing all Design Pattern Examples implemented in C++.
MessageType
Type of message handled by MessageWindow.
@ ButtonUp
Take an action on the currently selected window.
@ ButtonDown
Selects a window based on position.
@ Close
Window is asked to close itself, generally sent by the window itself in response to a button up in a ...
std::string formatstring(const char *fmt,...)
Use the given string and arguments to return a buffer containing the formatted string....
Represents a message sent to the windows. A message contains a type and a position.
enum MessageType MessageType
Value from the MessageType enumeration indicating the type of this message.
std::string ToString()
Convert this message to a string.
MessagePosition Position
Position of message when the message was sent. In a real system, this would generally represent the p...
Message(enum MessageType type, struct MessagePosition position)
Constructor.
Position of the message in global coordinates (same scope of coordinates as windows)....
std::string ToString()
Convert this position to a string.