14#include "helpers/enablevtmode.h"
15#include "helpers/stringlist.h"
85 "DesignPatternExamples_c (v" APP_VERSION
") by Stephen P. Lepisto\n"
86 "usage: DesignPatternExamples_c [options] [exercise_name][[ exercise_name][...]]\n"
88 "Runs through a series of exercises showing off design patterns. If no\n"
89 "exercise_name is given, then run through all exercises.\n"
95 " Show just the version number of this application.\n"
99 printf(
"%s\n", usage);
101 printf(
"Exercises available:\n");
102 for (
size_t index = 0;
exercises[index].name != NULL; index++)
113 printf(
"%s\n", APP_VERSION);
136 bool optionsValid =
true;
140 printf(
"Error! ParseOptions() requires non-NULL pointer to the Options structure.\n");
146 for (
int index = 1; index < argc; index++)
148 if (strcmp(argv[index],
"--help") == 0 ||
149 strcmp(argv[index],
"-?") == 0 ||
150 strcmp(argv[index],
"/?") == 0)
153 optionsValid =
false;
156 if (strcmp(argv[index],
"--version") == 0)
159 optionsValid =
false;
164 printf(
"Error! Out of memory storing exercise name in the Options structure.");
179 {
"Adapter", Adapter_Exercise},
180 {
"Bridge", Bridge_Exercise},
181 {
"Command", Command_Exercise},
182 {
"Composite", Composite_Exercise},
183 {
"Decorator", Decorator_Exercise},
184 {
"Facade", Facade_Exercise},
185 {
"Flyweight", Flyweight_Exercise},
186 {
"HandlerChain", HandlerChain_Exercise},
187 {
"Interpreter", Interpreter_Exercise},
188 {
"Iterator", Iterator_Exercise},
189 {
"Mediator", Mediator_Exercise},
190 {
"Memento", Memento_Exercise},
191 {
"NullObject", NullObject_Exercise},
192 {
"Observer", Observer_Exercise},
193 {
"Proxy", Proxy_Exercise},
194 {
"State", State_Exercise},
195 {
"Strategy", Strategy_Exercise},
196 {
"Visitor", Visitor_Exercise},
209 srand((
unsigned int)(time(NULL)));
215 for (
int index = 0;
exercises[index].name != NULL; index++)
Declaration of the Adapter_Exercise() function as used in the Adapter Pattern.
Declaration of the Bridge_Exercise() function as used in the Bridge Pattern.
Declaration of the Command_Exercise() function as used in the Command Pattern.
Declaration of the Composite_Exercise() function as used in the Composite Pattern.
Declaration of the Decorator_Exercise() function as used in the Decorator Pattern.
Declaration of the Facade_Exercise() function as used in the Facade Pattern.
Declaration of the Flyweight_Exercise() function as used in the Flyweight Pattern.
Declaration of the HandlerChain_Exercise() function as used in the HandlerChain Pattern.
Declaration of the Interpreter_Exercise() function as used in the Interpreter Pattern.
Declaration of the Iterator_Exercise() function as used in the Iterator Pattern.
Declaration of the Memento_Exercise() function as used in the Memento Pattern.
Declaration of the NullObject_Exercise() function as used in the Null Object Pattern.
Declaration of the Observer_Exercise() function as used in the Observer Pattern.
Declaration of the Proxy_Exercise() function as used in the Proxy Pattern.
Declaration of the State_Exercise() function as used in the State Pattern.
Declaration of the Strategy_Exercise() function as used in the Strategy Pattern.
Declaration of the Visitor_Exercise() function as used in the Visitor Pattern.
void enableVTMode(void)
Enables the virtual terminal processing mode on the current Windows Console. When the program ends,...
std::vector< std::string > StringList
Typedef for a vector of std::string.
struct _Exercise Exercise
Represents a single exercise or example for a design pattern.
Exercise ExerciseList[]
Alias for an array of Exercise objects.
static void Help(ExerciseList exercises)
Helper function to show usage information for this program.
struct _Options Options
Represents the command line options provided to the program, if any.
static void ShowVersion(void)
Helper function to show just the version of the application.
void(* Action)(void)
Alias for a function pointer, using C# as inspiration for the name.
static bool ParseOptions(int argc, char **argv, Options *options, ExerciseList exercises)
Helper function to parse the given options and store the results in the given Options structure....
int main(int argc, char **argv)
Main entry point into this example program.
void StringList_Clear(StringList *stringList)
Clear the specified string list. All strings in the list are released. The string list can then be us...
int StringList_Find(StringList *stringList, const char *string)
Search the given string list for the given string. If found, return the index of the found string.
void StringList_Initialize(StringList *stringList)
Initialize the given string list.
bool StringList_AddString(StringList *stringList, const char *string)
Add a string to the given string list.
Represents a single exercise or example for a design pattern.
Action exercise_to_run
Function to call to run the exercise.
const char * name
Name of the exercise.
Represents the command line options provided to the program, if any.
StringList exercise_names
List of names of exercise to run. If this list is empty, run all exercises.