-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
system_visitor.h
56 lines (42 loc) · 1.33 KB
/
system_visitor.h
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
51
52
53
54
55
56
#pragma once
#include "drake/common/default_scalars.h"
namespace drake {
namespace systems {
template <typename T>
class System;
template <typename T>
class Diagram;
/** Provides a "Visitor Pattern" for System and Diagram. Rather than adding
more virtual methods to the System base class, or performing a dynamic_cast to
test if a System is a Diagram, you may use the visitor pattern enabled by this
class, e.g.:
@code
template <typename T>
class MySystemVisitor : public SystemVisitor {
...
}
MySystemVisitor<T> visitor;
system.Accept(visitor);
@endcode
will call the correct `Visit` overload.
@note This method does *not* recurse through the subsystems of a Diagram, but
that is easy to do: just call Diagram::GetSystems() in your visitor and then
call Accept on the subsystems.
@tparam_default_scalar
*/
template <typename T>
class SystemVisitor {
public:
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(SystemVisitor)
virtual ~SystemVisitor() = default;
/** This method will be called by System<T>::accept() if the System *is not* a
Diagram<T>. */
virtual void VisitSystem(const System<T>& system) = 0;
/** This method will be called by System<T>::accept() if the System *is* a
Diagram<T>. */
virtual void VisitDiagram(const Diagram<T>& diagram) = 0;
protected:
SystemVisitor() = default;
};
} // namespace systems
} // namespace drake