Design Pattern Examples
Overview of object-oriented design patterns
Visitor_Village.cpp
Go to the documentation of this file.
1
5
6#include "Visitor_Village.h"
8
9
11{
12
14 {
15 Name = "Village of Self-Sufficiency";
16
17 {
18 shops.push_back(std::make_unique<Visitor_Restaurant>());
19 Visitor_Shop::unique_ptr_t& shop = shops.back();
20 shop->SetName("Joe's Burger Joint");
21 shop->SetAddress("47 Millings Rd.");
22 shop->SetVillage(this);
23 shop->SetIngredientsForItems(MapOfStrings{
24 { "hamburger", { "ground beef", "hamburger buns", "ketchup", "mustard", "mayonnaise", "lettuce", "tomato", "onion", "pickles" } }
25 });
26 }
27
28 {
29 shops.push_back(std::make_unique<Visitor_Butcher>());
30 Visitor_Shop::unique_ptr_t& shop = shops.back();
31 shop->SetName("Amelia's Butcher Shop");
32 shop->SetAddress("12 Klaxon Ave.");
33 shop->SetVillage(this);
34 shop->SetIngredientsForItems(MapOfStrings{
35 {"ground beef", { } }
36 });
37 }
38
39 {
40 shops.push_back(std::make_unique<Visitor_Baker>());
41 Visitor_Shop::unique_ptr_t& shop = shops.back();
42 shop->SetName("Oxel's Breads and Buns Bakery");
43 shop->SetAddress("131 Worthington Dr.");
44 shop->SetVillage(this);
45 shop->SetIngredientsForItems(MapOfStrings{
46 {"hamburger buns", { } }
47 });
48 }
49
50 {
51 shops.push_back(std::make_unique<Visitor_CondimentGrocer>());
52 Visitor_Shop::unique_ptr_t& shop = shops.back();
53 shop->SetName("Connie's Condiments");
54 shop->SetAddress("83 Millings Rd.");
55 shop->SetVillage(this);
56 shop->SetIngredientsForItems(MapOfStrings{
57 { "ketchup", { "fresh ketchup" } },
58 { "mustard", { "fresh mustard" } },
59 { "mayonnaise", { "fresh mayonnaise" } }
60 });
61 }
62
63 {
64 shops.push_back(std::make_unique<Visitor_VegetableGrocer>());
65 Visitor_Shop::unique_ptr_t& shop = shops.back();
66 shop->SetName("Florence's Vegetables");
67 shop->SetAddress("32 Main St.");
68 shop->SetVillage(this);
69 shop->SetIngredientsForItems(MapOfStrings{
70 { "lettuce", { } },
71 { "tomato", { } },
72 { "onion", { } },
73 { "cucumber", { } },
74 { "mustard seed", { } }
75 });
76 }
77
78 {
79 shops.push_back(std::make_unique<Visitor_PickleGrocer>());
80 Visitor_Shop::unique_ptr_t& shop = shops.back();
81 shop->SetName("Larry's Pickle Emporium");
82 shop->SetAddress("34 Main St.");
83 shop->SetVillage(this);
84 shop->SetIngredientsForItems(MapOfStrings{
85 {"pickles", { "vinegar", "cucumber", "salt" } }
86 });
87 }
88
89 {
90 shops.push_back(std::make_unique<Visitor_Maker>());
91 Visitor_Shop::unique_ptr_t& shop = shops.back();
92 shop->SetName("Klyde and Sons Ketchup Makers");
93 shop->SetAddress("800 Overtown Rd.");
94 shop->SetVillage(this);
95 shop->SetIngredientsForItems(MapOfStrings{
96 {"fresh ketchup", { } }
97 });
98 }
99
100 {
101 shops.push_back(std::make_unique<Visitor_Maker>());
102 Visitor_Shop::unique_ptr_t& shop = shops.back();
103 shop->SetName("Molly's Mustard Mart");
104 shop->SetAddress("810 Overtown Rd.");
105 shop->SetVillage(this);
106 shop->SetIngredientsForItems(MapOfStrings{
107 {"fresh mustard", { "vinegar", "mustard seed" } }
108 });
109 }
110
111 {
112 shops.push_back(std::make_unique<Visitor_Maker>());
113 Visitor_Shop::unique_ptr_t& shop = shops.back();
114 shop->SetName("Turk's Mayo Supply");
115 shop->SetAddress("820 Overtown Rd.");
116 shop->SetVillage(this);
117 shop->SetIngredientsForItems(MapOfStrings{
118 {"fresh mayonnaise", { } }
119 });
120 }
121
122 {
123 shops.push_back(std::make_unique<Visitor_Maker>());
124 Visitor_Shop::unique_ptr_t& shop = shops.back();
125 shop->SetName("Vinnies' Sour Flavors");
126 shop->SetAddress("830 Overtown Rd.");
127 shop->SetVillage(this);
128 shop->SetIngredientsForItems(MapOfStrings{
129 { "vinegar", { } }
130 });
131 }
132
133 {
134 shops.push_back(std::make_unique<Visitor_Maker>());
135 Visitor_Shop::unique_ptr_t& shop = shops.back();
136 shop->SetName("Jessie's Salt Works");
137 shop->SetAddress("920 Overtown Rd.");
138 shop->SetVillage(this);
139 shop->SetIngredientsForItems(MapOfStrings{
140 {"salt", { } }
141 });
142 }
143 }
144
145
147 {
148 for(auto& shop : shops)
149 {
150 shop->Accept(visitor);
151 }
152 }
153
154} // end namespace
Declaration of the Visitor base class and the various shop classes used in the Visitor Pattern.
std::unique_ptr< Visitor_Shop > unique_ptr_t
Alias to make it easier to refer to a unique instance of this class.
std::vector< Visitor_Shop::unique_ptr_t > shops
List of shops in this village.
All visitors must implement this base class and then override one or more of the VisitXXX() methods,...
Declaration of the Visitor_Village class used in the Visitor Pattern.
The namespace containing all Design Pattern Examples implemented in C++.
Represents a list of structures that map strings to ConstStringList objects.