forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
symbolic_formula_visitor.h
63 lines (57 loc) · 2.48 KB
/
symbolic_formula_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
57
58
59
60
61
62
63
#pragma once
#ifndef DRAKE_COMMON_SYMBOLIC_HEADER
#error Do not directly include this file. Include "drake/common/symbolic.h".
#endif
#include <utility>
#include "drake/common/drake_assert.h"
#include "drake/common/symbolic.h"
namespace drake {
namespace symbolic {
/// Calls visitor object @p v with a symbolic formula @p f, and arguments @p
/// args. Visitor object is expected to implement the following methods which
/// take @p f and @p args: `VisitFalse`, `VisitTrue`, `VisitVariable`,
/// `VisitEqualTo`, VisitNotEqualTo, VisitGreaterThan,
/// `VisitGreaterThanOrEqualTo`, `VisitLessThan`, `VisitLessThanOrEqualTo`,
/// `VisitConjunction`, `VisitDisjunction`, `VisitNegation`, `VisitForall`,
/// `VisitIsnan`, `VisitPositiveSemidefinite`.
///
/// Check the implementation of @c NegationNormalFormConverter class in
/// drake/common/test/symbolic_formula_visitor_test.cc file to find an example.
template <typename Result, typename Visitor, typename... Args>
Result VisitFormula(Visitor* v, const Formula& f, Args&&... args) {
switch (f.get_kind()) {
case FormulaKind::False:
return v->VisitFalse(f, std::forward<Args>(args)...);
case FormulaKind::True:
return v->VisitTrue(f, std::forward<Args>(args)...);
case FormulaKind::Var:
return v->VisitVariable(f, std::forward<Args>(args)...);
case FormulaKind::Eq:
return v->VisitEqualTo(f, std::forward<Args>(args)...);
case FormulaKind::Neq:
return v->VisitNotEqualTo(f, std::forward<Args>(args)...);
case FormulaKind::Gt:
return v->VisitGreaterThan(f, std::forward<Args>(args)...);
case FormulaKind::Geq:
return v->VisitGreaterThanOrEqualTo(f, std::forward<Args>(args)...);
case FormulaKind::Lt:
return v->VisitLessThan(f, std::forward<Args>(args)...);
case FormulaKind::Leq:
return v->VisitLessThanOrEqualTo(f, std::forward<Args>(args)...);
case FormulaKind::And:
return v->VisitConjunction(f, std::forward<Args>(args)...);
case FormulaKind::Or:
return v->VisitDisjunction(f, std::forward<Args>(args)...);
case FormulaKind::Not:
return v->VisitNegation(f, std::forward<Args>(args)...);
case FormulaKind::Forall:
return v->VisitForall(f, std::forward<Args>(args)...);
case FormulaKind::Isnan:
return v->VisitIsnan(f, std::forward<Args>(args)...);
case FormulaKind::PositiveSemidefinite:
return v->VisitPositiveSemidefinite(f, std::forward<Args>(args)...);
}
DRAKE_UNREACHABLE();
}
} // namespace symbolic
} // namespace drake