28 if (village != NULL && shop != NULL)
31 if (village->
shops == NULL)
39 new_list = realloc(village->
shops, new_size);
43 village->
shops = new_list;
64 village->
shops = NULL;
76 for (
size_t index = 0; index < village->
shops_count; index++)
90 static const char* empty_ingredients[] = {NULL};
96 village->
Name =
"Village of Self-Sufficiency";
98 shop =
Shop_Create(
"Joe's Burger Joint",
"47 Millings Rd.", village);
101 static const char* hamburger_ingredients[] = {
"ground beef",
"hamburger buns",
"ketchup",
"mustard",
"mayonnaise",
"lettuce",
"tomato",
"onion",
"pickles", NULL};
118 shop =
Shop_Create(
"Amelia's Butcher Shop",
"12 Klaxon Ave.", village);
136 shop =
Shop_Create(
"Oxel's Breads and Buns Bakery",
"131 Worthington Dr.", village);
154 shop =
Shop_Create(
"Connie's Condiments",
"83 Millings Rd.", village);
157 static const char* ketchup_ingredients[] = {
"fresh ketchup", NULL};
158 static const char* mustard_ingredients[] = {
"fresh mustard", NULL};
159 static const char* mayonnaise_ingredients[] = {
"fresh mayonnaise", NULL};
184 shop =
Shop_Create(
"Florence's Vegetables",
"32 Main St.", village);
222 shop =
Shop_Create(
"Larry's Pickle Emporium",
"34 Main St.", village);
225 static const char* pickles_ingredients[] = {
"vinegar",
"cucumber",
"salt", NULL };
242 shop =
Shop_Create(
"Klyde and Sons Ketchup Makers",
"800 Overtown Rd.", village);
260 shop =
Shop_Create(
"Molly's Mustard Mart",
"810 Overtown Rd.", village);
263 static const char* fresh_mustard_ingredients[] = {
"vinegar",
"mustard seed", NULL };
280 shop =
Shop_Create(
"Turk's Mayo Supply",
"820 Overtown Rd.", village);
298 shop =
Shop_Create(
"Vinnies' Sour Flavors",
"830 Overtown Rd.", village);
316 shop =
Shop_Create(
"Jessie's Salt Works",
"920 Overtown Rd.", village);
340 bool success =
false;
342 if (village != NULL && visitor != NULL)
345 for (
size_t index = 0; index < village->
shops_count; index++)
bool OrderVisitor_VisitShop(OrderVisitor *order, Visitor_Shop *shop)
Represents a visit to the specified Visitor_Shop with the specified order.
void Shop_Destroy(Visitor_Shop *shop)
Destroy an instance of the Visitor_Shop structure, freeing up any memory that may have been allocated...
Visitor_Shop * Shop_Create(const char *name, const char *address, struct Village *village)
Creates a new instance of a Visitor_Shop structure, and initializes it with the given name,...
static bool Village_AddShop(Village *village, Visitor_Shop *shop)
Add a Visitor_Shop object to the specified Village. The Village object takes ownership of the Visitor...
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.
Declaration of the Visitor_Village class used in the Visitor Pattern.
bool MapOfStrings_AddArray(MapOfStrings *map, const char *key, const char **value)
Add a key/value association to the given MapOfStrings object, where the value is provided as a NULL-t...
Represents a visitor used for ordering items from various shops. The user starts with an instance of ...
Represents a collection of shops that can be visited.
const char * Name
Name of the village.
size_t shops_count
Number of shops in the shops list.
Visitor_Shop ** shops
List of shops in this village.
Represents a shop in the village that can be visited.
MapOfStrings IngredientsForItems
Maps ingredient to list of items need for ingredient.