Drake
simple_rulebook.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <unordered_map>
5 #include <vector>
6 
12 
13 namespace drake {
14 namespace maliput {
15 namespace simplerulebook {
16 
17 
18 /// SimpleRulebook is a simple concrete implementation of the
19 /// api::rules::RoadRulebook abstract interface.
21  public:
23 
24  /// Constructs an empty SimpleRulebook (i.e., containing no rules).
26 
27  ~SimpleRulebook() override;
28 
29  /// Removes all rules.
30  void RemoveAll();
31 
32  /// Adds a new RightOfWayRule.
33  ///
34  /// Throws std::runtime_error if a rule with the same ID already exists
35  /// in the SimpleRulebook.
36  void AddRule(const api::rules::RightOfWayRule& rule);
37 
38  /// Removes the RightOfWayRule labelled by `id`.
39  ///
40  /// Throws std::runtime_error if no such rule exists.
42 
43  /// Adds a new SpeedLimitRule.
44  ///
45  /// Throws std::runtime_error if a rule with the same ID already exists
46  /// in the SimpleRulebook.
47  void AddRule(const api::rules::SpeedLimitRule& rule);
48 
49  /// Removes the SpeedLimitRule labelled by `id`.
50  ///
51  /// Throws std::runtime_error if no such rule exists.
53 
54  private:
56  const std::vector<api::rules::LaneSRange>& ranges,
57  double tolerance) const override;
59  const api::rules::RightOfWayRule::Id& id) const override;
61  const api::rules::SpeedLimitRule::Id& id) const override;
62 
63  template <class T>
64  void AddAnyRule(const T& rule,
65  std::unordered_map<typename T::Id, T>* map);
66  template <class T>
67  T GetAnyRule(const typename T::Id& id,
68  const std::unordered_map<typename T::Id, T>& map) const;
69  template <class T>
70  void RemoveAnyRule(const typename T::Id& id,
71  std::unordered_map<typename T::Id, T>* map);
72 
73  // ID->Rule indices for each rule type
74  template <class T>
75  using IdIndex = std::unordered_map<typename T::Id, T>;
76  IdIndex<api::rules::RightOfWayRule> right_of_ways_;
77  IdIndex<api::rules::SpeedLimitRule> speed_limits_;
78 
79  // An index from LaneSRange to collections of rule ID's of all types.
80  class RangeIndex;
81  std::unique_ptr<RangeIndex> index_;
82 };
83 
84 
85 } // namespace simplerulebook
86 } // namespace maliput
87 } // namespace drake
Rule describing right-of-way, a.k.a.
Definition: right_of_way_rule.h:40
void RemoveRule(const api::rules::RightOfWayRule::Id &id)
Removes the RightOfWayRule labelled by id.
Definition: simple_rulebook.cc:183
Abstract interface for querying "rules of the road".
Definition: road_rulebook.h:24
Definition: bullet_model.cc:22
void AddRule(const api::rules::RightOfWayRule &rule)
Adds a new RightOfWayRule.
Definition: simple_rulebook.cc:173
void RemoveAll()
Removes all rules.
Definition: simple_rulebook.cc:166
Rule describing speed limits.
Definition: speed_limit_rule.h:22
SimpleRulebook is a simple concrete implementation of the api::rules::RoadRulebook abstract interface...
Definition: simple_rulebook.h:20
boolean< T > T
Definition: drake_bool_deprecated.h:26
SimpleRulebook()
Constructs an empty SimpleRulebook (i.e., containing no rules).
Definition: simple_rulebook.cc:128
Results of a FindRules() query.
Definition: road_rulebook.h:32
#define DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(Classname)
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN deletes the special member functions for copy-construction, copy-assignment, move-construction, and move-assignment.
Definition: drake_copyable.h:33
const double tolerance
Definition: dynamic_bicycle_car_test.cc:42
Provides careful macros to selectively enable or disable the special member functions for copy-constr...