Design Pattern Examples
Overview of object-oriented design patterns
Strategy_SortStrategy.h
Go to the documentation of this file.
1
5
6#pragma once
7#ifndef __STRATEGY_SORTSTRATEGY_H__
8#define __STRATEGY_SORTSTRATEGY_H__
9
10#include <stdbool.h>
11
15typedef struct
16{
20 const char* Name;
21
25 int Age;
26
30 int Height;
32
33
34//=============================================================================
35//=============================================================================
36
37
44typedef enum
45{
50
55
60
62
67typedef bool (*CompareFunction)(const EntryInformation*, const EntryInformation*);
68
72typedef struct
73{
74 const char* name;
78
79//-----------------------------------------------------------------------------
80
89void SortStrategy_Initialize(SortStrategy* strategy, SortOptions sortOption, bool reversedSort);
90
91#endif // __STRATEGY_SORTSTRATEGY_H__
92
SortOptions
Represents the difference sorting strategies supported.
@ Sort_ByAge
Sort numerically by age in ascending order.
@ Sort_ByHeight
Sort numerically by height in ascending order.
@ Sort_ByName
Sort alphabetically name in ascending order.
void SortStrategy_Initialize(SortStrategy *strategy, SortOptions sortOption, bool reversedSort)
Initialize a SortStrategy object with the desired strategy.
bool(* CompareFunction)(const EntryInformation *, const EntryInformation *)
Alias for a function that compares two EntryInformation objects to determine if the left comes before...
Represents an individual with a Name, Age, and Height.
int Age
Age of this individual, in years.
const char * Name
Name of this individual.
int Height
Height of this individual, in inches.
Represents the strategy to use for sorting EntryInformation objects.
bool reversedSort
True if to reverse the order of the sort.
const char * name
Name of the strategy (for display purposes)
CompareFunction compareFunction
Compare function that determines the order of two entries.