Skip to content

Commit 806ccbc

Browse files
committed
refactor: change enums to scoped enums for better type safety and scoping
1 parent 1cda0f8 commit 806ccbc

File tree

11 files changed

+55
-55
lines changed

11 files changed

+55
-55
lines changed

include/Geometries/RoadGeometry.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
namespace odr
88
{
99

10-
enum GeometryType
10+
enum class GeometryType
1111
{
12-
GeometryType_Line,
13-
GeometryType_Spiral,
14-
GeometryType_Arc,
15-
GeometryType_ParamPoly3
12+
Line,
13+
Spiral,
14+
Arc,
15+
ParamPoly3
1616
};
1717

1818
struct RoadGeometry

include/Junction.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ namespace odr
3737

3838
struct JunctionConnection
3939
{
40-
enum ContactPoint
40+
enum class ContactPoint
4141
{
42-
ContactPoint_None,
43-
ContactPoint_Start,
44-
ContactPoint_End
42+
None,
43+
Start,
44+
End
4545
};
4646

4747
JunctionConnection(std::string id, std::string incoming_road, std::string connecting_road, ContactPoint contact_point);
4848

4949
std::string id = "";
5050
std::string incoming_road = "";
5151
std::string connecting_road = "";
52-
ContactPoint contact_point = ContactPoint_None;
52+
ContactPoint contact_point = ContactPoint::None;
5353

5454
std::set<JunctionLaneLink> lane_links;
5555
};

include/Log.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace odr
1111
namespace log
1212
{
1313

14-
enum Level
14+
enum class Level
1515
{
1616
Debug = 0,
1717
Info = 1,

include/Road.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ struct RoadMark;
2121

2222
struct Crossfall : public CubicSpline
2323
{
24-
enum Side
24+
enum class Side
2525
{
26-
Side_Both,
27-
Side_Left,
28-
Side_Right
26+
Both,
27+
Left,
28+
Right
2929
};
3030

3131
Crossfall() = default;
@@ -37,26 +37,26 @@ struct Crossfall : public CubicSpline
3737

3838
struct RoadLink
3939
{
40-
enum ContactPoint
40+
enum class ContactPoint
4141
{
42-
ContactPoint_None,
43-
ContactPoint_Start,
44-
ContactPoint_End
42+
None,
43+
Start,
44+
End
4545
};
4646

47-
enum Type
47+
enum class Type
4848
{
49-
Type_None,
50-
Type_Road,
51-
Type_Junction
49+
None,
50+
Road,
51+
Junction
5252
};
5353

5454
RoadLink() = default;
5555
RoadLink(std::string id, Type type, ContactPoint contact_point);
5656

5757
std::string id = "";
58-
Type type = Type_None;
59-
ContactPoint contact_point = ContactPoint_None;
58+
Type type = Type::None;
59+
ContactPoint contact_point = ContactPoint::None;
6060
};
6161

6262
struct RoadNeighbor

include/RoadObject.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ struct RoadObjectRepeat
3838

3939
struct RoadObjectCorner
4040
{
41-
enum Type
41+
enum class Type
4242
{
43-
Type_Local_RelZ, // z relative to road’s reference line
44-
Type_Local_AbsZ, // absolute z value
45-
Type_Road
43+
Local_RelZ, // z relative to road’s reference line
44+
Local_AbsZ, // absolute z value
45+
Road
4646
};
4747

4848
RoadObjectCorner(int id, Vec3D pt, double height, Type type);
4949

5050
int id = 0;
5151
Vec3D pt;
5252
double height = 0;
53-
Type type = Type_Road;
53+
Type type = Type::Road;
5454
};
5555

5656
struct RoadObjectOutline

src/Geometries/Arc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace odr
77
{
88
Arc::Arc(double s0, double x0, double y0, double hdg0, double length, double curvature) :
9-
RoadGeometry(s0, x0, y0, hdg0, length, GeometryType_Arc), curvature(curvature)
9+
RoadGeometry(s0, x0, y0, hdg0, length, GeometryType::Arc), curvature(curvature)
1010
{
1111
}
1212

src/Geometries/Line.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace odr
88
{
99

10-
Line::Line(double s0, double x0, double y0, double hdg0, double length) : RoadGeometry(s0, x0, y0, hdg0, length, GeometryType_Line) {}
10+
Line::Line(double s0, double x0, double y0, double hdg0, double length) : RoadGeometry(s0, x0, y0, hdg0, length, GeometryType::Line) {}
1111

1212
std::unique_ptr<RoadGeometry> Line::clone() const
1313
{

src/Geometries/ParamPoly3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ParamPoly3::ParamPoly3(double s0,
2323
double cV,
2424
double dV,
2525
bool pRange_normalized) :
26-
RoadGeometry(s0, x0, y0, hdg0, length, GeometryType_ParamPoly3),
26+
RoadGeometry(s0, x0, y0, hdg0, length, GeometryType::ParamPoly3),
2727
aU(aU),
2828
bU(bU),
2929
cU(cU),

src/Geometries/Spiral.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace odr
99
{
1010

1111
Spiral::Spiral(double s0, double x0, double y0, double hdg0, double length, double curv_start, double curv_end) :
12-
RoadGeometry(s0, x0, y0, hdg0, length, GeometryType_Spiral), curv_start(curv_start), curv_end(curv_end)
12+
RoadGeometry(s0, x0, y0, hdg0, length, GeometryType::Spiral), curv_start(curv_start), curv_end(curv_end)
1313
{
1414
this->c_dot = (curv_end - curv_start) / length;
1515
this->s_start = curv_start / c_dot;

src/OpenDriveMap.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ OpenDriveMap::OpenDriveMap(const std::string& xodr_file,
117117
junction_id.c_str(),
118118
contact_point_str.c_str());
119119
const JunctionConnection::ContactPoint junction_conn_contact_point =
120-
(contact_point_str == "start") ? JunctionConnection::ContactPoint_Start : JunctionConnection::ContactPoint_End;
120+
(contact_point_str == "start") ? JunctionConnection::ContactPoint::Start : JunctionConnection::ContactPoint::End;
121121

122122
const std::string junction_connection_id = connection_node.attribute("id").as_string("");
123123
JunctionConnection& junction_connection = junction.id_to_connection
@@ -201,9 +201,9 @@ OpenDriveMap::OpenDriveMap(const std::string& xodr_file,
201201
road_id.c_str(),
202202
is_predecessor ? "predecessor" : "successor",
203203
type_str.c_str());
204-
link.type = (type_str == "road") ? RoadLink::Type_Road : RoadLink::Type_Junction;
204+
link.type = (type_str == "road") ? RoadLink::Type::Road : RoadLink::Type::Junction;
205205

206-
if (link.type == RoadLink::Type_Road)
206+
if (link.type == RoadLink::Type::Road)
207207
{
208208
// junction connection has no contact point
209209
std::string contact_point_str = road_link_node.attribute("contactPoint").as_string("");
@@ -214,7 +214,7 @@ OpenDriveMap::OpenDriveMap(const std::string& xodr_file,
214214
road_id.c_str(),
215215
is_predecessor ? "predecessor" : "successor",
216216
contact_point_str.c_str());
217-
link.contact_point = (contact_point_str == "start") ? RoadLink::ContactPoint_Start : RoadLink::ContactPoint_End;
217+
link.contact_point = (contact_point_str == "start") ? RoadLink::ContactPoint::Start : RoadLink::ContactPoint::End;
218218
}
219219
}
220220
}
@@ -379,11 +379,11 @@ OpenDriveMap::OpenDriveMap(const std::string& xodr_file,
379379
std::string side_str = side.as_string("");
380380
std::transform(side_str.begin(), side_str.end(), side_str.begin(), [](unsigned char c) { return std::tolower(c); });
381381
if (side_str == "left")
382-
road.crossfall.sides[s0] = Crossfall::Side_Left;
382+
road.crossfall.sides[s0] = Crossfall::Side::Left;
383383
else if (side_str == "right")
384-
road.crossfall.sides[s0] = Crossfall::Side_Right;
384+
road.crossfall.sides[s0] = Crossfall::Side::Right;
385385
else
386-
road.crossfall.sides[s0] = Crossfall::Side_Both;
386+
road.crossfall.sides[s0] = Crossfall::Side::Both;
387387
}
388388
}
389389

@@ -579,7 +579,7 @@ OpenDriveMap::OpenDriveMap(const std::string& xodr_file,
579579
if (with_road_objects)
580580
{
581581
const RoadObjectCorner::Type default_local_outline_type =
582-
abs_z_for_for_local_road_obj_outline ? RoadObjectCorner::Type_Local_AbsZ : RoadObjectCorner::Type_Local_RelZ;
582+
abs_z_for_for_local_road_obj_outline ? RoadObjectCorner::Type::Local_AbsZ : RoadObjectCorner::Type::Local_RelZ;
583583

584584
for (pugi::xml_node object_node : road_node.child("objects").children("object"))
585585
{
@@ -705,7 +705,7 @@ OpenDriveMap::OpenDriveMap(const std::string& xodr_file,
705705
RoadObjectCorner road_object_corner_road(corner_road_node.attribute("id").as_int(-1),
706706
pt_road,
707707
corner_road_node.attribute("height").as_double(0),
708-
RoadObjectCorner::Type_Road);
708+
RoadObjectCorner::Type::Road);
709709
road_object_outline.outline.push_back(road_object_corner_road);
710710
}
711711

@@ -875,14 +875,14 @@ RoutingGraph OpenDriveMap::get_routing_graph() const
875875
if (!lanesection)
876876
{
877877
const RoadLink& road_link = predecessors ? current_road.predecessor : current_road.successor;
878-
if (road_link.type == RoadLink::Type_Road && road_link.contact_point != RoadLink::ContactPoint_None)
878+
if (road_link.type == RoadLink::Type::Road && road_link.contact_point != RoadLink::ContactPoint::None)
879879
{
880880
auto next_road_iter = id_to_road.find(road_link.id);
881881
if (next_road_iter != id_to_road.end())
882882
{
883883
const Road& next_road = next_road_iter->second;
884-
lanesection = (road_link.contact_point == RoadLink::ContactPoint_Start) ? next_road.s_to_lanesection.begin()->second
885-
: next_road.s_to_lanesection.rbegin()->second;
884+
lanesection = (road_link.contact_point == RoadLink::ContactPoint::Start) ? next_road.s_to_lanesection.begin()->second
885+
: next_road.s_to_lanesection.rbegin()->second;
886886
}
887887
}
888888
}
@@ -963,11 +963,11 @@ RoutingGraph OpenDriveMap::get_routing_graph() const
963963
const Road& connecting_road = connecting_road_iter->second;
964964

965965
const LaneSection& incoming_lanesec =
966-
(incoming_road.successor.type == RoadLink::Type_Junction && incoming_road.successor.id == junction.id)
966+
(incoming_road.successor.type == RoadLink::Type::Junction && incoming_road.successor.id == junction.id)
967967
? incoming_road.s_to_lanesection.rbegin()->second
968968
: incoming_road.s_to_lanesection.begin()->second;
969969

970-
const LaneSection& connecting_lanesec = (conn.contact_point == JunctionConnection::ContactPoint_Start)
970+
const LaneSection& connecting_lanesec = (conn.contact_point == JunctionConnection::ContactPoint::Start)
971971
? connecting_road.s_to_lanesection.begin()->second
972972
: connecting_road.s_to_lanesection.rbegin()->second;
973973

0 commit comments

Comments
 (0)