11#include "helpers/replace.h"
12#include "helpers/stringlist.h"
13#include "helpers/enablevtmode.h"
43 typedef std::function<void()>
Action;
74 name = nameOfExercise;
105 "{0} (v" APP_VERSION
") by Stephen P. Lepisto\n"
106 "usage: {0} [options] [exercise_name][[ exercise_name][...]]\n"
108 "Runs through a series of exercises showing off design patterns. If no\n"
109 "exercise_name is given, then run through all exercises.\n"
115 " Show just the version number of this application.\n"
119 std::string appName =
"DesignPatternExamples_cpp";
122 std::cout << std::endl <<
"Exercises available:" << std::endl;
125 std::cout <<
" " << exercise.name << std::endl;
134 std::cout << APP_VERSION << std::endl;
152 bool optionsValid =
true;
158 for (std::string argument : args)
160 if (argument ==
"--help" ||
165 optionsValid =
false;
168 else if (argument ==
"--version")
171 optionsValid =
false;
221 auto foundIter = std::find(
229 exercise.exercise_to_run();
253 srand(
static_cast<unsigned int>(time(
nullptr)));
256 for (
int argIndex = 1; argIndex < argc; ++argIndex)
258 args.push_back(std::string(argv[argIndex]));
Contains all the top-level Design Pattern Examples to match C#.
std::vector< Exercise > ExerciseList
Alias for a list of Exercise instances.
void Run(StringList args)
Run the specified examples.
void ShowVersion()
Helper function to show just the version of the application.
void Help(ExerciseList exercises)
Helper method to show usage information for this program.
bool ParseOptions(StringList args, ExerciseList exercises, Options &options)
Helper method to parse the given options and store the results in the given Options structure....
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.
std::vector< std::string > StringList
Typedef for a vector of std::string.
The namespace containing all Design Pattern Examples implemented in C++.
void Bridge_Exercise()
Example of using the Bridge design pattern.
void Interpreter_Exercise()
Example of using the Interpreter design pattern.
void NullObject_Exercise()
Example of using the Null Object design pattern.
void Decorator_Exercise()
Example of using the Decorator design pattern.
void State_Exercise()
Example of using the State design pattern.
std::function< void()> Action
Alias for a function pointer, using C# as inspiration for the name.
void Iterator_Exercise()
Example of using the Iterator design pattern.
void Command_Exercise()
Example of using the Command design pattern.
void Strategy_Exercise()
Example of using the Strategy design pattern.
void Adapter_Exercise()
Example of using the Adapter Pattern.
void Memento_Exercise()
Example of using the Memento design pattern.
void HandlerChain_Exercise()
Example of using the Handle Chain or Chain of Responsibility design pattern.
void Flyweight_Exercise()
Example of using the Flyweight design pattern.
void Facade_Exercise()
Example of using the Facade design pattern.
void Proxy_Exercise()
Example of using the Proxy design pattern.
void Observer_Exercise()
Example of using the Observer design pattern.
void Composite_Exercise()
Example of using the Composite design pattern.
void Mediator_Exercise()
Example of using the Mediator design pattern.
void Visitor_Exercise()
Example of using the Visitor design pattern.
void enableVTMode()
On Windows, enable the virtual terminal processing mode on the Console's output handle....
std::string Replace(const std::string &s, const char *str1, const char *str2, bool bCaseInsensitive)
Replace all occurrences of narrow string str1 with narrow string str2 in s. If str2 is empty then all...
int main(int argc, char **argv)
Main entry point into this example program.
Represents a single exercise or example for a design pattern.
Action exercise_to_run
Method to call to run the exercise.
Exercise(const char *nameOfExercise, Action exercise)
Constructor.
std::string 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.