8#include "helpers/formatstring.h"
21 std::string _SortOptionToString(
SortOptions sortOption)
23 std::string optionAsString;
27 case SortOptions::ByName:
28 optionAsString =
"ByName";
31 case SortOptions::ByAge:
32 optionAsString =
"ByAge";
35 case SortOptions::ByHeight:
36 optionAsString =
"ByHeight";
43 return optionAsString;
64 sortEntries = std::make_shared<Strategy_SortEntries_ByName>(reversedSort);
68 sortEntries = std::make_shared < Strategy_SortEntries_ByAge>(reversedSort);
72 sortEntries = std::make_shared < Strategy_SortEntries_ByHeight>(reversedSort);
77 std::string message =
Helpers::formatstring(
"Unrecognized sort option: %s", _SortOptionToString(sortOption).c_str());
78 throw std::runtime_error(message.c_str());
Declaration of the Strategy_SortEntries_ClassFactory class and implementation of the various Strategy...
static ISortEntries::shared_ptr_t Create(SortOptions sortOption, bool reversedSort)
Generate an instance of a sorting strategy based on the given sorting option and reversed sort flag....
The namespace containing all Design Pattern Examples implemented in C++.
SortOptions
Identifies the different sorting strategies available.
@ ByHeight
Sort numerically by height in ascending order.
@ ByAge
Sort numerically by age in ascending order.
@ ByName
Sort alphabetically name in ascending order.
std::string formatstring(const char *fmt,...)
Use the given string and arguments to return a buffer containing the formatted string....
std::shared_ptr< ISortEntries > shared_ptr_t
Alias to make it easier to work with a shared pointer.