39 printf(
"\nVisitor Exercise\n");
41 printf(
" Creating Village\n");
53 printf(
" Ordering a hamburger from a shop in the %s\n", village.
Name);
63 printf(
" We received a %s from %s.\n",
69 printf(
" Failed to receive a hamburger\n");
76 printf(
" Error! Out of memory condition adding item to list of things to order!\n");
83 printf(
" Error! Out of memory loading the village!\n");
void Visitor_Exercise(void)
Example of using the Visitor Pattern.
void OrderVisitor_Initialize(OrderVisitor *visitor)
Initialize the specified OrderVisitor object.
void OrderVisitor_Clear(OrderVisitor *visitor)
Clear the specified OrderVisitor object, freeing up any memory that it was using. The resulting objec...
void Village_Clear(Village *village)
Clear the specified Village object, releasing any allocated memory associated with the village and it...
bool Village_VisitShop(Village *village, OrderVisitor *visitor)
Visit all shops in the given Village object to find the ingredients specified in the OrderVisitor obj...
bool Village_Load(Village *village)
Set up the specified Village object with all the shops that can be visited.
void Village_Initialize(Village *village)
Initialize the specified Village object.
bool ConstStringList_AddString(ConstStringList *stringList, const char *string)
Add a string to the given string list.
Declaration of the Visitor_Exercise() function as used in the Visitor Pattern.
Declaration of the Visitor_Village class used in the Visitor Pattern.
size_t strings_count
Number of strings in the strings list.
const char ** strings
Pointer to an array of zero-terminated string pointers. These strings are constant and will not be du...
Represents a visitor used for ordering items from various shops. The user starts with an instance of ...
ConstStringList ItemsToOrder
Items to be ordered from any shop that sells the item.
ConstStringList ItemsReceived
List of items received from an order/pickup process.
const char * ShopNameReceivedFrom
Name of the shop that provided the item(s). Borrowed pointer.
Represents a collection of shops that can be visited.
const char * Name
Name of the village.