Declaration of the Visitor_Shop structure and its supporting functions, Shop_Create(), Shop_Destroy(), Shop_PlaceOrder(), and Shop_PickupOrder(), as used in the Visitor Pattern. More...
Go to the source code of this file.
Classes | |
struct | Visitor_Shop |
Represents a shop in the village that can be visited. More... | |
Macros | |
#define | __VISITOR_SHOP_H__ |
Enumerations | |
enum | PlaceOrderReponse { PlaceOrderResponse_OrderAccepted , PlaceOrderResponse_OrderIgnored , PlaceOrderResponse_Error } |
Represents the possible responses from the Shop_PlaceOrder() function. More... | |
Functions | |
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, address, and Village object. | |
void | Shop_Destroy (Visitor_Shop *shop) |
Destroy an instance of the Visitor_Shop structure, freeing up any memory that may have been allocated to the shop. After this function returns, the pointer to the Visitor_Shop is no longer valid. | |
PlaceOrderReponse | Shop_PlaceOrder (Visitor_Shop *shop, ConstStringList *itemsToOrder) |
Visit the specified Visitor_Shop object to try to place an order as described in the OrderVisitor object. | |
bool | Shop_PickupOrder (Visitor_Shop *shop, ConstStringList *items, ConstStringList *itemsToBePickedUp) |
Pick up the items sold by this shop (assumes the items were ordered already). Basically, this reduces the inventory for the given items that are sold by this shop. | |
Declaration of the Visitor_Shop structure and its supporting functions, Shop_Create(), Shop_Destroy(), Shop_PlaceOrder(), and Shop_PickupOrder(), as used in the Visitor Pattern.
Definition in file c/Visitor_Shop.h.
#define __VISITOR_SHOP_H__ |
Definition at line 9 of file c/Visitor_Shop.h.
enum PlaceOrderReponse |
Represents the possible responses from the Shop_PlaceOrder() function.
Definition at line 19 of file c/Visitor_Shop.h.
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, address, and Village object.
name | The name of the shop. |
address | The address of the shop. |
village | The Village in which this shop exists. |
Definition at line 140 of file Visitor_Shop.c.
References Visitor_Shop::Address, Visitor_Shop::IngredientsForItems, Visitor_Shop::Inventory, MapOfInt_Initialize(), MapOfStrings_Initialize(), Visitor_Shop::Name, and Visitor_Shop::Village.
Referenced by Village_Load().
void Shop_Destroy | ( | Visitor_Shop * | shop | ) |
Destroy an instance of the Visitor_Shop structure, freeing up any memory that may have been allocated to the shop. After this function returns, the pointer to the Visitor_Shop is no longer valid.
shop | The Visitor_Shop object to destroy. |
Definition at line 163 of file Visitor_Shop.c.
References Visitor_Shop::IngredientsForItems, Visitor_Shop::Inventory, MapOfInt_Clear(), and MapOfStrings_Clear().
Referenced by Village_Clear(), and Village_Load().
bool Shop_PickupOrder | ( | Visitor_Shop * | shop, |
ConstStringList * | items, | ||
ConstStringList * | itemsToBePickedUp | ||
) |
Pick up the items sold by this shop (assumes the items were ordered already). Basically, this reduces the inventory for the given items that are sold by this shop.
shop | The Visitor_Shop object to visit. The shop might not carry the requested ingredients, in which case, the visit is ignored. |
items | Items that were ordered, some of which may be sold by this shop. |
itemsToBePickedUp | List to be filled in with the item names that were picked up. |
Definition at line 331 of file Visitor_Shop.c.
References _StringizeStringList(), ConstStringList_AddString(), ConstStringList_Clear(), ConstStringList_Initialize(), DynamicString_Clear(), MapOfInt::entries, Visitor_Shop::Inventory, MapOfInt_Find(), Visitor_Shop::Name, Shop_DoesShopSellItem(), Shop_IsItemInStock(), DynamicString::string, _ConstStringList::strings, _ConstStringList::strings_count, and MapOfIntEntry::value.
Referenced by OrderVisitor_VisitShop().
PlaceOrderReponse Shop_PlaceOrder | ( | Visitor_Shop * | shop, |
ConstStringList * | itemsToOrder | ||
) |
Visit the specified Visitor_Shop object to try to place an order as described in the OrderVisitor object.
shop | The Visitor_Shop object to visit. The shop might not carry the requested ingredients, in which case, the visit is ignored. |
itemsToOrder | A ConstStringList object containing a list of the ingredients to order. |
Definition at line 177 of file Visitor_Shop.c.
References _StringizeStringList(), ConstStringList_AddString(), ConstStringList_AddStrings(), ConstStringList_AreListsEqual(), ConstStringList_Clear(), DynamicString_Clear(), DynamicString_Initialize(), MapOfStrings::entries, Visitor_Shop::IngredientsForItems, OrderVisitor::ItemsReceived, OrderVisitor::ItemsToOrder, MapOfStrings_Find(), Visitor_Shop::Name, OrderVisitor_Clear(), PlaceOrderResponse_Error, PlaceOrderResponse_OrderAccepted, PlaceOrderResponse_OrderIgnored, Shop_AddItemToInventory(), Shop_DoesShopSellItem(), Shop_IsItemInStock(), DynamicString::string, _ConstStringList::strings, _ConstStringList::strings_count, MapOfStringsEntry::value, Visitor_Shop::Village, and Village_VisitShop().
Referenced by OrderVisitor_VisitShop().