Drake
basic_id_index.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <unordered_map>
4 
11 
12 namespace drake {
13 namespace maliput {
14 namespace api {
15 
16 
17 /// Basic general-purpose concrete implementation of the
18 /// RoadGeometry::IdIndex interface.
20  public:
22 
23  BasicIdIndex() = default;
24  ~BasicIdIndex() override = default;
25 
26  /// Adds @p lane to the index.
27  ///
28  /// @throws if @p lane's id() already exists in the index.
29  /// @pre @p lane is not nullptr.
30  void AddLane(const Lane* lane);
31 
32  /// Adds @p segment to the index.
33  ///
34  /// @throws if @p segment's id() already exists in the index.
35  /// @pre @p segment is not nullptr.
36  void AddSegment(const Segment* segment);
37 
38  /// Adds @p junction to the index.
39  ///
40  /// @throws if @p junction's id() already exists in the index.
41  /// @pre @p junction is not nullptr.
42  void AddJunction(const Junction* junction);
43 
44  /// Adds @p branch_point to the index.
45  ///
46  /// @throws if @p branch_point's id() already exists in the index.
47  /// @pre @p branch_point is not nullptr.
48  void AddBranchPoint(const BranchPoint* branch_point);
49 
50  /// Walks the object graph rooted at @p road_geometry and adds all
51  /// components (Lane, Segment, Junction, BranchPoint) to the index.
52  ///
53  /// @throws if the graph of @p road_geometry contains any duplicate id's,
54  /// or if any of its id's already exist in the index.
55  /// @pre @p road_geometry is not nullptr.
56  void WalkAndAddAll(const RoadGeometry* road_geometry);
57 
58  private:
59  const Lane* DoGetLane(const LaneId& id) const final;
60  const Segment* DoGetSegment(const SegmentId& id) const final;
61  const Junction* DoGetJunction(const JunctionId& id) const final;
62  const BranchPoint* DoGetBranchPoint(const BranchPointId& id) const final;
63 
64  std::unordered_map<JunctionId, const Junction*> junction_map_;
65  std::unordered_map<SegmentId, const Segment*> segment_map_;
66  std::unordered_map<LaneId, const Lane*> lane_map_;
67  std::unordered_map<BranchPointId, const BranchPoint*> branch_point_map_;
68 };
69 
70 
71 } // namespace api
72 } // namespace maliput
73 } // namespace drake
void WalkAndAddAll(const RoadGeometry *road_geometry)
Walks the object graph rooted at road_geometry and adds all components (Lane, Segment, Junction, BranchPoint) to the index.
Definition: basic_id_index.cc:30
A BranchPoint is a node in the network of a RoadGeometry at which Lanes connect to one another...
Definition: branch_point.h:67
Definition: automotive_demo.cc:90
Basic general-purpose concrete implementation of the RoadGeometry::IdIndex interface.
Definition: basic_id_index.h:19
Abstract API for the geometry of a road network, including both the network topology and the geometry...
Definition: road_geometry.h:30
void AddJunction(const Junction *junction)
Adds junction to the index.
Definition: basic_id_index.cc:19
Abstract interface for a collection of methods which allow accessing objects in a RoadGeometry&#39;s obje...
Definition: road_geometry.h:170
void AddLane(const Lane *lane)
Adds lane to the index.
Definition: basic_id_index.cc:9
TypeSpecificIdentifier< class BranchPoint > BranchPointId
Definition: branch_point.h:19
A Lane represents a lane of travel in a road network.
Definition: lane.h:35
TypeSpecificIdentifier< class Junction > JunctionId
Persistent identifier for a Junction element.
Definition: junction.h:17
A Segment represents a bundle of adjacent Lanes which share a continuously traversable road surface...
Definition: segment.h:27
A Junction is a closed set of Segments which have physically coplanar road surfaces, in the sense that RoadPositions with the same h value (height above surface) in the domains of two Segments map to the same GeoPosition.
Definition: junction.h:27
void AddSegment(const Segment *segment)
Adds segment to the index.
Definition: basic_id_index.cc:14
void AddBranchPoint(const BranchPoint *branch_point)
Adds branch_point to the index.
Definition: basic_id_index.cc:24
~BasicIdIndex() override=default
#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
Provides careful macros to selectively enable or disable the special member functions for copy-constr...