Implementation of the various decorator functions that are called from the Decorator_Exercise() function as used in the Decorator Pattern. More...
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "helpers/dynamicstring.h"
#include "helpers/formatstring.h"
#include "Decorator_Exercise.h"
Go to the source code of this file.
Functions | |
DynamicString * | _Decorate (DynamicString *s, const char *decoration) |
Helper function for applying decorations to the given string. | |
DynamicString * | RedForegroundDecorator (DynamicString *s) |
Represents the RedForeground decorator, which alters the wrapped content to render as red text. | |
DynamicString * | WhiteBackgroundDecorator (DynamicString *s) |
Represents the WhiteBackground decorator, which alters the wrapped content to render the background color as white. | |
DynamicString * | UnderlineDecorator (DynamicString *s) |
Represents the Underline decorator, which alters the wrapped content to render it as underlined. | |
void | Decorator_Exercise (void) |
Example of using the Decorator Pattern. | |
Implementation of the various decorator functions that are called from the Decorator_Exercise() function as used in the Decorator Pattern.
Definition in file Decorator_Exercise.c.
DynamicString * _Decorate | ( | DynamicString * | s, |
const char * | decoration | ||
) |
Helper function for applying decorations to the given string.
s | A DynamicString object that contains the string to be decorated. |
decoration | A string passed to sprintf() that wraps the %s (which represents the given string) in some kind of decoration. |
Definition at line 29 of file Decorator_Exercise.c.
References DynamicString_Set(), formatstring(), and DynamicString::string.
Referenced by RedForegroundDecorator(), UnderlineDecorator(), and WhiteBackgroundDecorator().
void Decorator_Exercise | ( | void | ) |
Example of using the Decorator Pattern.
The Decorator pattern is used when some data element at run time needs to have its behavior altered. This is supported by providing wrapper functions called decorators that take an instance of the data element and return the data element. Each wrapper function alters the data element and returns it so it can be passed to the next wrapper function.
Definition at line 97 of file Decorator_Exercise.c.
References DynamicString_Clear(), DynamicString_Initialize(), DynamicString_Set(), RedForegroundDecorator(), DynamicString::string, UnderlineDecorator(), and WhiteBackgroundDecorator().
DynamicString * RedForegroundDecorator | ( | DynamicString * | s | ) |
Represents the RedForeground decorator, which alters the wrapped content to render as red text.
s | A DynamicString object that contains the string to be decorated. |
Definition at line 52 of file Decorator_Exercise.c.
References _Decorate().
Referenced by Decorator_Exercise().
DynamicString * UnderlineDecorator | ( | DynamicString * | s | ) |
Represents the Underline decorator, which alters the wrapped content to render it as underlined.
s | A DynamicString object that contains the string to be decorated. |
Definition at line 78 of file Decorator_Exercise.c.
References _Decorate().
Referenced by Decorator_Exercise().
DynamicString * WhiteBackgroundDecorator | ( | DynamicString * | s | ) |
Represents the WhiteBackground decorator, which alters the wrapped content to render the background color as white.
s | A DynamicString object that contains the string to be decorated. |
Definition at line 65 of file Decorator_Exercise.c.
References _Decorate().
Referenced by Decorator_Exercise().