Implementation of the State_Exercise() function as used in the State Pattern. More...
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "helpers/dynamicstring.h"
#include "helpers/split.h"
#include "helpers/strdup.h"
#include "State_RemoveComments.h"
#include "State_Exercise.h"
Go to the source code of this file.
Functions | |
static void | _State_DisplayText (const char *textToDisplay) |
Helper function to display text from the State exercise. Text is displayed with line numbers. | |
void | State_Exercise (void) |
Example of using the State Pattern. | |
Variables | |
static const char * | textToFilter |
Implementation of the State_Exercise() function as used in the State Pattern.
Definition in file State_Exercise.c.
|
static |
Helper function to display text from the State exercise. Text is displayed with line numbers.
textToDisplay | Text to display. |
Definition at line 27 of file State_Exercise.c.
References split(), STRDUP, SplitList::strings, and SplitList::strings_count.
Referenced by DesignPatternExamples_cpp::State_Exercise(), and State_Exercise().
void State_Exercise | ( | void | ) |
Example of using the State Pattern.
The State pattern alters the behavior of the class hierarchy based on some state. This is the basis of a Finite State Machine.
In this exercise, the State class is a filter that parses text to remove C++-style line and block comments. It needs to be smart enough to ignore comment characters inside quotes.
The filtering process starts with creating the context that drives the state machine. Internal classes are provided for each state.
Definition at line 83 of file State_Exercise.c.
References _State_DisplayText(), DynamicString_Clear(), State_RemoveComments(), DynamicString::string, and textToFilter.
|
static |
Definition at line 52 of file State_Exercise.c.
Referenced by State_Exercise::Run(), DesignPatternExamples_cpp::State_Exercise(), and State_Exercise().