9#include "helpers/formatstring.h"
10#include "helpers/stringlist.h"
27 bool match = left.size() == right.size();
31 for (StringList::iterator leftIter = std::begin(left);
32 leftIter != std::end(left);
35 if (std::find(std::begin(right), std::end(right), *leftIter) == std::end(right))
76 std::ostringstream output;
78 for (std::string& item : items)
80 if (output.tellp() != 0)
92 bool orderPlaced =
false;
96 for (std::string& item : items)
102 outOfStockItems.push_back(item);
104 itemsInThisShop.push_back(item);
108 if (!itemsInThisShop.empty())
116 if (!outOfStockItems.empty())
118 for (std::string& itemToOrder : outOfStockItems)
124 Name().c_str(), itemToOrder.c_str())
149 Name().c_str(), itemToOrder.c_str())
161 for (std::string& item : items)
168 itemsToBePickedUp.push_back(item);
174 Name().c_str(), item.c_str())
180 if (!itemsToBePickedUp.empty())
184 for (std::string& itemToBePickedUp : itemsToBePickedUp)
189 itemsReceivedFromThisShop.push_back(itemToBePickedUp);
193 std::string output =
StringizeList(itemsReceivedFromThisShop);
Declaration of the Visitor base class and the various shop classes used in the Visitor Pattern.
Implementation of the OrderVisitor class used in the Visitor Pattern.
A visitor used for ordering items from various shops. The user starts with an instance of this class ...
StringList ItemsReceived
List of items received from an order/pickup process.
void PickupOrder(StringList items, StringList &itemsToBePickedUp)
Pick up the items sold by this shop (assumes the items were ordered already). Basically,...
bool DoesShopSellItem(std::string item)
Determine if this shop sells the specified item.
std::string StringizeList(StringList items)
Convert a string list to a comma-delimited string. Useful for displaying the list.
Visitor_Village * village
MapOfStrings ingredientsForItems
bool PlaceOrder(StringList items)
Place an order for the specified items. If the inventory is empty, replenish the inventory by visitin...
std::map< std::string, int > Inventory
Inventory for this shop.
void AddItemToInventory(std::string item)
Add the specified item to this shop's inventory.
std::string Name()
Name of the shop.
bool IsItemInStock(std::string item)
Determine if this shop has the specified item in stock.
void Accept(Visitor *visitor)
Declaration of the Visitor_Village class used in the Visitor Pattern.
std::vector< std::string > StringList
Typedef for a vector of std::string.
The namespace containing all Design Pattern Examples implemented in C++.
std::string formatstring(const char *fmt,...)
Use the given string and arguments to return a buffer containing the formatted string....