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

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

#include "Visitor_Shop.h"
Include dependency graph for Visitor_OrderVisitor.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  OrderVisitor
 Represents a visitor used for ordering items from various shops. The user starts with an instance of this class and a list of what they want to order. More...
 

Macros

#define __VISITOR_ORDERVISITOR_H__
 

Typedefs

typedef struct OrderVisitor OrderVisitor
 Represents a visitor used for ordering items from various shops. The user starts with an instance of this class and a list of what they want to order.
 

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

Declaration of the OrderVisitor structure and its supporting functions, OrderVisitor_Initialize(), OrderVisitor_Clear(), and OrderVisitor_VisitShop(), as used in the Visitor Pattern.

Definition in file Visitor_OrderVisitor.h.

Macro Definition Documentation

◆ __VISITOR_ORDERVISITOR_H__

#define __VISITOR_ORDERVISITOR_H__

Definition at line 9 of file Visitor_OrderVisitor.h.

Typedef Documentation

◆ OrderVisitor

typedef struct OrderVisitor OrderVisitor

Represents a visitor used for ordering items from various shops. The user starts with an instance of this class and a list of what they want to order.

Later, a shop will used this visitor to order ingredients to make a requested item.

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().