Design Pattern Examples
Overview of object-oriented design patterns
Visitor_OrderVisitor.c File Reference

Implementation of the OrderVisitor structure's supporting functions, OrderVisitor_Initialize(), OrderVisitor_Clear(), and OrderVisitor_VisitShop(), as used in the Visitor Pattern. More...

Include dependency graph for Visitor_OrderVisitor.c:

Go to the source code of this file.

Functions

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 object is initialized as if brand new.
 
bool OrderVisitor_VisitShop (OrderVisitor *order, Visitor_Shop *shop)
 Represents a visit to the specified Visitor_Shop with the specified order.
 

Detailed Description

Implementation of the OrderVisitor structure's supporting functions, OrderVisitor_Initialize(), OrderVisitor_Clear(), and OrderVisitor_VisitShop(), as used in the Visitor Pattern.

Definition in file Visitor_OrderVisitor.c.

Function Documentation

◆ OrderVisitor_Clear()

void OrderVisitor_Clear ( OrderVisitor visitor)

Clear the specified OrderVisitor object, freeing up any memory that it was using. The resulting object is initialized as if brand new.

Parameters
visitorThe OrderVisitor object to clear.

Definition at line 25 of file Visitor_OrderVisitor.c.

References ConstStringList_Clear(), OrderVisitor::ItemsReceived, OrderVisitor::ItemsToOrder, and OrderVisitor_Initialize().

Referenced by Shop_PlaceOrder(), and Visitor_Exercise().

◆ OrderVisitor_Initialize()

void OrderVisitor_Initialize ( OrderVisitor visitor)

Initialize the specified OrderVisitor object.

Alternatively, declare the OrderVisitor instance like this:

OrderVisitor map = { 0 };
Represents a visitor used for ordering items from various shops. The user starts with an instance of ...
Parameters
visitorThe OrderVisitor object to initialize.

Definition at line 12 of file Visitor_OrderVisitor.c.

References ConstStringList_Initialize(), OrderVisitor::ItemsReceived, OrderVisitor::ItemsToOrder, and OrderVisitor::ShopNameReceivedFrom.

Referenced by OrderVisitor_Clear(), and Visitor_Exercise().

◆ OrderVisitor_VisitShop()

bool OrderVisitor_VisitShop ( OrderVisitor order,
Visitor_Shop shop 
)

Represents a visit to the specified Visitor_Shop with the specified order.

Parameters
orderThe OrderVisitor object representing what is being ordered from the shop.
shopThe Visitor_Shop that is being visited and, if it carries the ingredients, receives the order. Otherwise, the shop ignores the visit.
Returns
Returns true if the shop was visited (but not necessarily received an order); otherwise, returns false, indicating an out of memory condition (or a NULL argument).

Definition at line 38 of file Visitor_OrderVisitor.c.

References OrderVisitor::ItemsReceived, OrderVisitor::ItemsToOrder, Visitor_Shop::Name, PlaceOrderResponse_OrderAccepted, Shop_PickupOrder(), Shop_PlaceOrder(), and OrderVisitor::ShopNameReceivedFrom.

Referenced by Village_VisitShop().