Design Pattern Examples
Overview of object-oriented design patterns
c/Visitor_Village.h File Reference

Declaration of the Village structure and its supporting functions, Village_Initialize(), Village_Clear(), Village_Load(), Village_AddShop(), and Village_VisitShop(), as used in the Visitor Pattern. More...

Include dependency graph for c/Visitor_Village.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Village
 Represents a collection of shops that can be visited. More...
 

Macros

#define __VISITOR_VILLAGE_H__
 

Typedefs

typedef struct Village Village
 Represents a collection of shops that can be visited.
 

Functions

void Village_Initialize (Village *village)
 Initialize the specified Village object.
 
void Village_Clear (Village *village)
 Clear the specified Village object, releasing any allocated memory associated with the village and its contents. The Village object is left in an newly-initialized state.
 
bool Village_Load (Village *village)
 Set up the specified Village object with all the shops that can be visited.
 
bool Village_VisitShop (Village *village, OrderVisitor *visitor)
 Visit all shops in the given Village object to find the ingredients specified in the OrderVisitor object.
 

Detailed Description

Declaration of the Village structure and its supporting functions, Village_Initialize(), Village_Clear(), Village_Load(), Village_AddShop(), and Village_VisitShop(), as used in the Visitor Pattern.

Definition in file c/Visitor_Village.h.

Macro Definition Documentation

◆ __VISITOR_VILLAGE_H__

#define __VISITOR_VILLAGE_H__

Definition at line 10 of file c/Visitor_Village.h.

Typedef Documentation

◆ Village

typedef struct Village Village

Represents a collection of shops that can be visited.

Function Documentation

◆ Village_Clear()

void Village_Clear ( Village village)

Clear the specified Village object, releasing any allocated memory associated with the village and its contents. The Village object is left in an newly-initialized state.

Parameters
villageThe Village object to clear.

Definition at line 72 of file Visitor_Village.c.

References Shop_Destroy(), Village::shops, Village::shops_count, and Village_Initialize().

Referenced by Visitor_Exercise().

◆ Village_Initialize()

void Village_Initialize ( Village village)

Initialize the specified Village object.

Parameters
villageThe Village object to initialize.

Definition at line 59 of file Visitor_Village.c.

References Village::Name, Village::shops, and Village::shops_count.

Referenced by Village_Clear(), and Visitor_Exercise().

◆ Village_Load()

bool Village_Load ( Village village)

Set up the specified Village object with all the shops that can be visited.

Parameters
villageThe Village object to load.
Returns
Returns true if the Village object was loaded successfully; otherwise, returns false, indicating an out of memory condition (or a NULL argument).

Definition at line 88 of file Visitor_Village.c.

References Visitor_Shop::IngredientsForItems, MapOfStrings_AddArray(), Village::Name, Shop_Create(), Shop_Destroy(), and Village_AddShop().

Referenced by Visitor_Exercise().

◆ Village_VisitShop()

bool Village_VisitShop ( Village village,
OrderVisitor visitor 
)

Visit all shops in the given Village object to find the ingredients specified in the OrderVisitor object.

Parameters
villageThe Village object whose shops are to be visited.
visitorThe OrderVisitor object describing what is being ordered.
Returns
Returns true if the order was placed successfully; otherwise, returns false, indicating an out of memory condition (or a NULL argument).

Definition at line 338 of file Visitor_Village.c.

References OrderVisitor_VisitShop(), Village::shops, and Village::shops_count.

Referenced by Shop_PlaceOrder(), and Visitor_Exercise().