Apollo 10.0
自动驾驶开放平台
roads_xml_parser.cc
浏览该文件的文档.
1/* Copyright 2017 The Apollo Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14=========================================================================*/
15#include <string>
16
22
23namespace {
24bool IsRoadBelongToJunction(const std::string& road_id) {
25 ACHECK(!road_id.empty());
26 return road_id != "-1";
27}
28} // namespace
29
30namespace apollo {
31namespace hdmap {
32namespace adapter {
33
34Status RoadsXmlParser::Parse(const tinyxml2::XMLElement& xml_node,
35 std::vector<RoadInternal>* roads) {
36 CHECK_NOTNULL(roads);
37
38 auto road_node = xml_node.FirstChildElement("road");
39 while (road_node) {
40 // road attributes
41 std::string id;
42 std::string junction_id;
43 int checker = UtilXmlParser::QueryStringAttribute(*road_node, "id", &id);
44 checker += UtilXmlParser::QueryStringAttribute(*road_node, "junction",
45 &junction_id);
46 if (checker != tinyxml2::XML_SUCCESS) {
47 std::string err_msg = "Error parsing road attributes";
49 }
50
51 RoadInternal road_internal;
52 road_internal.id = id;
53 road_internal.road.mutable_id()->set_id(id);
54 if (IsRoadBelongToJunction(junction_id)) {
55 road_internal.road.mutable_junction_id()->set_id(junction_id);
56 }
57
58 std::string type;
59 checker = UtilXmlParser::QueryStringAttribute(*road_node, "type", &type);
60 if (checker != tinyxml2::XML_SUCCESS) {
61 // forward compatibility with old data
62 type = "CITYROAD";
63 }
64 PbRoadType pb_road_type;
65 RETURN_IF_ERROR(to_pb_road_type(type, &pb_road_type));
66 road_internal.road.set_type(pb_road_type);
67
68 // lanes
69 RETURN_IF_ERROR(LanesXmlParser::Parse(*road_node, road_internal.id,
70 &road_internal.sections));
71
72 // objects
73 Parse_road_objects(*road_node, &road_internal);
74 // signals
75 Parse_road_signals(*road_node, &road_internal);
76
77 roads->push_back(road_internal);
78 road_node = road_node->NextSiblingElement("road");
79 }
80
81 return Status::OK();
82}
83
84void RoadsXmlParser::Parse_road_objects(const tinyxml2::XMLElement& xml_node,
85 RoadInternal* road_info) {
86 CHECK_NOTNULL(road_info);
87
88 // objects
89 auto sub_node = xml_node.FirstChildElement("objects");
90 if (sub_node != nullptr) {
91 // stop line
92 ObjectsXmlParser::ParseStopLines(*sub_node, &road_info->stop_lines);
93 // crosswalks
94 ObjectsXmlParser::ParseCrosswalks(*sub_node, &road_info->crosswalks);
95 // clearareas
96 ObjectsXmlParser::ParseClearAreas(*sub_node, &road_info->clear_areas);
97 // speed_bumps
98 ObjectsXmlParser::ParseSpeedBumps(*sub_node, &road_info->speed_bumps);
99 // parking_spaces
101 // pnc_junctions
103 }
104}
105
106void RoadsXmlParser::Parse_road_signals(const tinyxml2::XMLElement& xml_node,
107 RoadInternal* road_info) {
108 CHECK_NOTNULL(road_info);
109
110 // signals
111 auto sub_node = xml_node.FirstChildElement("signals");
112 if (sub_node != nullptr) {
113 // traffic lights
114 SignalsXmlParser::ParseTrafficLights(*sub_node, &road_info->traffic_lights);
115 // stop signs
116 SignalsXmlParser::ParseStopSigns(*sub_node, &road_info->stop_signs);
117 // yield signs
118 SignalsXmlParser::ParseYieldSigns(*sub_node, &road_info->yield_signs);
119 }
120}
121
122Status RoadsXmlParser::to_pb_road_type(const std::string& type,
123 PbRoadType* pb_road_type) {
124 CHECK_NOTNULL(pb_road_type);
125
126 std::string upper_type = UtilXmlParser::ToUpper(type);
127
128 if (upper_type == "UNKNOWN") {
129 *pb_road_type = apollo::hdmap::Road::UNKNOWN;
130 } else if (upper_type == "HIGHWAY") {
131 *pb_road_type = apollo::hdmap::Road::HIGHWAY;
132 } else if (upper_type == "CITYROAD") {
133 *pb_road_type = apollo::hdmap::Road::CITY_ROAD;
134 } else if (upper_type == "PARK") {
135 *pb_road_type = apollo::hdmap::Road::PARK;
136 } else {
137 std::string err_msg = "Error or unsupport road type";
139 }
140
141 return Status::OK();
142}
143
144} // namespace adapter
145} // namespace hdmap
146} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
static Status OK()
generate a success status.
Definition status.h:60
static Status Parse(const tinyxml2::XMLElement &xml_node, const std::string &road_id, std::vector< RoadSectionInternal > *sections)
static Status ParseSpeedBumps(const tinyxml2::XMLElement &xml_node, std::vector< PbSpeedBump > *speed_bumps)
static Status ParseCrosswalks(const tinyxml2::XMLElement &xml_node, std::vector< PbCrosswalk > *crosswalks)
static Status ParseClearAreas(const tinyxml2::XMLElement &xml_node, std::vector< PbClearArea > *clear_areas)
static Status ParsePNCJunctions(const tinyxml2::XMLElement &xml_node, std::vector< PbPNCJunction > *pnc_junctions)
static Status ParseStopLines(const tinyxml2::XMLElement &xml_node, std::vector< StopLineInternal > *stop_lines)
static Status ParseParkingSpaces(const tinyxml2::XMLElement &xml_node, std::vector< PbParkingSpace > *parking_spaces)
static Status Parse(const tinyxml2::XMLElement &xml_node, std::vector< RoadInternal > *roads)
static Status ParseStopSigns(const tinyxml2::XMLElement &xml_node, std::vector< StopSignInternal > *stop_signs)
static Status ParseYieldSigns(const tinyxml2::XMLElement &xml_node, std::vector< YieldSignInternal > *yield_signs)
static Status ParseTrafficLights(const tinyxml2::XMLElement &xml_node, std::vector< TrafficLightInternal > *traffic_lights)
static std::string ToUpper(const std::string &s)
static tinyxml2::XMLError QueryStringAttribute(const tinyxml2::XMLElement &xml_node, const std::string &name, std::string *value)
#define ACHECK(cond)
Definition log.h:80
#define RETURN_IF_ERROR(expr)
Definition status.h:25
apollo::hdmap::Road_Type PbRoadType
class register implement
Definition arena_queue.h:37
std::vector< PbPNCJunction > pnc_junctions
std::vector< PbClearArea > clear_areas
std::vector< RoadSectionInternal > sections
std::vector< PbSpeedBump > speed_bumps
std::vector< PbParkingSpace > parking_spaces
std::vector< StopLineInternal > stop_lines
std::vector< PbCrosswalk > crosswalks