Design Pattern Examples
Overview of object-oriented design patterns
HandlerChain_Message.c File Reference

Implementation of the Message and MessagePosition structures, along with the functions, MessagePosition_ToString(), Message_Initialize(), and Message_ToString(), as used in the HandlerChain Pattern. More...

#include <stdlib.h>
#include <stdio.h>
#include "helpers/formatstring.h"
#include "HandlerChain_Message.h"
Include dependency graph for HandlerChain_Message.c:

Go to the source code of this file.

Functions

bool MessagePosition_ToString (MessagePosition *position, DynamicString *output)
 Convert a MessagePosition object to a string representation.
 
void Message_Initialize (Message *message, MessageType type, int x, int y)
 Initialize a Message structure.
 
bool Message_ToString (Message *message, DynamicString *output)
 Convert a Message object to a string representation.
 

Detailed Description

Implementation of the Message and MessagePosition structures, along with the functions, MessagePosition_ToString(), Message_Initialize(), and Message_ToString(), as used in the HandlerChain Pattern.

Definition in file HandlerChain_Message.c.

Function Documentation

◆ Message_Initialize()

void Message_Initialize ( Message message,
MessageType  type,
int  x,
int  y 
)

Initialize a Message structure.

Parameters
messageThe Message structure to initialize.
typeValue from the MessageType enumeration indicating the type of message being created.
xHorizontal position of the message.
yVertical position of the message.

Definition at line 51 of file HandlerChain_Message.c.

References Message::MessageType, Message::Position, MessagePosition::X, and MessagePosition::Y.

Referenced by _HandleButtonUpMessage(), _HandleChain_DestroyWindows(), _HandleCloseMessage(), and HandlerChain_Exercise().

◆ Message_ToString()

bool Message_ToString ( Message message,
DynamicString output 
)

Convert a Message object to a string representation.

Parameters
messageThe Message object to convert.
outputThe string representation of the Message object. Call DynamicString_Initialize() on this object before passing as an argument.
Returns
Returns true if the message was successfully converted to a string; otherwise, returns false, indicating an out of memory condition (or a NULL argument).

Definition at line 64 of file HandlerChain_Message.c.

References ButtonDown, ButtonUp, Close, Destroy, DynamicString_Append(), DynamicString_Clear(), DynamicString_Initialize(), formatstring(), MessagePosition_ToString(), Message::MessageType, Message::Position, and DynamicString::string.

◆ MessagePosition_ToString()

bool MessagePosition_ToString ( MessagePosition position,
DynamicString output 
)

Convert a MessagePosition object to a string representation.

Parameters
positionThe MessagePosition object to convert.
outputA DynamicString in which to store the string representation of the position argument. Call DynamicString_Initialize() on this object before passing as an argument.
Returns
Returns true if the message position was successfully converted to a string; otherwise, returns false, indicating an out of memory condition (or a NULL argument).

Definition at line 17 of file HandlerChain_Message.c.

References DynamicString_Append(), formatstring(), MessagePosition::X, and MessagePosition::Y.

Referenced by Message_ToString().