-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvisitor.cpp
More file actions
29 lines (24 loc) · 754 Bytes
/
Copy pathvisitor.cpp
File metadata and controls
29 lines (24 loc) · 754 Bytes
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
// Simple Visitor Pattern example
class Instance;
class Netlist;
void DoNothingC(Instance *) {}
void
traverse_netlist_c(Netlist * n,
void (*v)(Instance *) = DoNothingC) {
// ...
// every time we encounter an instance, call the visitor
Instance * inst;
v(inst); // always calls this pointer
}
struct DoNothingInstanceVisitor {
void operator()(Instance *) const {}
};
template<typename InstanceVisitor = DoNothingInstanceVisitor>
void
traverse_netlist(Netlist * n,
InstanceVisitor v = InstanceVisitor()) {
// ...
// every time we encounter an instance, call the visitor
Instance * inst; // = whatever
v(inst); // optimized away for DoNothingInstanceVisitor
}