Implementation of the Visitor_Shop structure's supporting functions, Shop_Create(), Shop_Destroy(), Shop_PlaceOrder(), and Shop_PickupOrder(), as used in the Visitor Pattern. More...
#include <stdio.h>
#include <memory.h>
#include "helpers/dynamicstring.h"
#include "Visitor_Village.h"
Go to the source code of this file.
Functions | |
static bool | _StringizeStringList (ConstStringList *list, DynamicString *output) |
Convert a string list to a comma-delimited string. Useful for displaying the list. | |
static bool | Shop_DoesShopSellItem (Visitor_Shop *shop, const char *item) |
Determine if the given Visitor_Shop object sells the specified item. | |
static bool | Shop_IsItemInStock (Visitor_Shop *shop, const char *item) |
Determine if given Visitor_Shop object has the specified item in stock. | |
static bool | Shop_AddItemToInventory (Visitor_Shop *shop, const char *item) |
Add the specified item to the given Visitor_Shop object's inventory. | |
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. | |
Implementation of the Visitor_Shop structure's supporting functions, Shop_Create(), Shop_Destroy(), Shop_PlaceOrder(), and Shop_PickupOrder(), as used in the Visitor Pattern.
Definition in file Visitor_Shop.c.
|
static |
Convert a string list to a comma-delimited string. Useful for displaying the list.
list | The ConstStringList object containing the strings to be stringized |
output | A DynamicString object that returns the resulting string. |
Definition at line 25 of file Visitor_Shop.c.
References DynamicString_Append(), _ConstStringList::strings, and _ConstStringList::strings_count.
Referenced by Shop_PickupOrder(), and Shop_PlaceOrder().
|
static |
Add the specified item to the given Visitor_Shop object's inventory.
shop | The Visitor_Shop to access. |
item | The item to add |
Definition at line 107 of file Visitor_Shop.c.
References MapOfInt::entries, Visitor_Shop::Inventory, MapOfInt_Add(), MapOfInt_Find(), and MapOfIntEntry::value.
Referenced by Shop_PlaceOrder().
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().
|
static |
Determine if the given Visitor_Shop object sells the specified item.
shop | The Visitor_Shop to access. |
item | The item to look for |
Definition at line 61 of file Visitor_Shop.c.
References Visitor_Shop::IngredientsForItems, and MapOfStrings_Find().
Referenced by Shop_PickupOrder(), and Shop_PlaceOrder().
|
static |
Determine if given Visitor_Shop object has the specified item in stock.
shop | The Visitor_Shop to access. |
item | The item to look for |
Definition at line 82 of file Visitor_Shop.c.
References MapOfInt::entries, Visitor_Shop::Inventory, MapOfInt_Find(), and MapOfIntEntry::value.
Referenced by Shop_PickupOrder(), and Shop_PlaceOrder().
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().