-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisitor.cpp
50 lines (38 loc) · 1.1 KB
/
Visitor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//============================================================================
// Name : Visitor.cpp
// Created on : 17.04.2020
// Author : Tokmakov Andrey
// Version : 1.0
// Copyright : Your copyright notice
// Description : Visitor pattern tests
//============================================================================
#include "Visitor.h"
void Visitor_Pattern_Tests::Foo::accept(IVisitor & v) {
v.visit(*this);
}
void Visitor_Pattern_Tests::Bar::accept(IVisitor & v) {
v.visit(*this);
}
void Visitor_Pattern_Tests::Baz::accept(IVisitor & v) {
v.visit(*this);
}
void Visitor_Pattern_Tests::CustorVisitor::visit(Foo & ref) {
value = "Foo";
}
void Visitor_Pattern_Tests::CustorVisitor::visit(Bar & ref) {
value = "Bar";
}
void Visitor_Pattern_Tests::CustorVisitor::visit(Baz & ref) {
value = "Baz";
}
void Visitor_Pattern_Tests::test() {
Foo foo;
Bar bar;
Baz baz;
IElement *elements[] = { &foo, &bar, &baz };
CustorVisitor visitor;
for (auto elem : elements) {
elem->accept(visitor);
std::cout << visitor.value << std::endl;
}
}