refactor list of const static int into scoped enum
This commit is contained in:
@@ -47,7 +47,7 @@ struct OriginalEdgeData
|
||||
OriginalEdgeData()
|
||||
: via_node(std::numeric_limits<unsigned>::max()),
|
||||
name_id(std::numeric_limits<unsigned>::max()),
|
||||
turn_instruction(std::numeric_limits<unsigned char>::max()), compressed_geometry(false)
|
||||
turn_instruction(TurnInstruction::NoTurn), compressed_geometry(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -43,12 +43,12 @@ struct PathData
|
||||
PathData()
|
||||
: node(std::numeric_limits<unsigned>::max()), name_id(std::numeric_limits<unsigned>::max()),
|
||||
segment_duration(std::numeric_limits<unsigned>::max()),
|
||||
turn_instruction(std::numeric_limits<TurnInstruction>::max())
|
||||
turn_instruction(TurnInstruction::NoTurn)
|
||||
{
|
||||
}
|
||||
|
||||
PathData(NodeID no, unsigned na, unsigned tu, unsigned dur)
|
||||
: node(no), name_id(na), segment_duration(dur), turn_instruction(tu)
|
||||
PathData(NodeID node, unsigned name_id, TurnInstruction turn_instruction, unsigned segment_duration)
|
||||
: node(node), name_id(name_id), segment_duration(segment_duration), turn_instruction(turn_instruction)
|
||||
{
|
||||
}
|
||||
NodeID node;
|
||||
|
||||
@@ -62,7 +62,7 @@ struct SegmentInformation
|
||||
const double length,
|
||||
const TurnInstruction turn_instruction)
|
||||
: location(location), name_id(name_id), duration(duration), length(length), bearing(0),
|
||||
turn_instruction(turn_instruction), necessary(turn_instruction != 0)
|
||||
turn_instruction(turn_instruction), necessary(turn_instruction != TurnInstruction::NoTurn)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
@@ -28,76 +28,58 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef TURN_INSTRUCTIONS_H
|
||||
#define TURN_INSTRUCTIONS_H
|
||||
|
||||
typedef unsigned char TurnInstruction;
|
||||
enum class TurnInstruction : unsigned char
|
||||
{
|
||||
NoTurn = 0, GoStraight, TurnSlightRight, TurnRight, TurnSharpRight, UTurn,
|
||||
TurnSharpLeft, TurnLeft, TurnSlightLeft, ReachViaPoint, HeadOn, EnterRoundAbout,
|
||||
LeaveRoundAbout, StayOnRoundAbout, StartAtEndOfStreet, ReachedYourDestination,
|
||||
EnterAgainstAllowedDirection, LeaveAgainstAllowedDirection,
|
||||
InverseAccessRestrictionFlag = 127,
|
||||
AccessRestrictionFlag = 128,
|
||||
AccessRestrictionPenalty = 129
|
||||
};
|
||||
|
||||
// This is a hack until c++0x is available enough to use scoped enums
|
||||
struct TurnInstructionsClass
|
||||
{
|
||||
TurnInstructionsClass() = delete;
|
||||
TurnInstructionsClass(const TurnInstructionsClass&) = delete;
|
||||
|
||||
const static TurnInstruction NoTurn = 0; // Give no instruction at all
|
||||
const static TurnInstruction GoStraight = 1; // Tell user to go straight!
|
||||
const static TurnInstruction TurnSlightRight = 2;
|
||||
const static TurnInstruction TurnRight = 3;
|
||||
const static TurnInstruction TurnSharpRight = 4;
|
||||
const static TurnInstruction UTurn = 5;
|
||||
const static TurnInstruction TurnSharpLeft = 6;
|
||||
const static TurnInstruction TurnLeft = 7;
|
||||
const static TurnInstruction TurnSlightLeft = 8;
|
||||
const static TurnInstruction ReachViaPoint = 9;
|
||||
const static TurnInstruction HeadOn = 10;
|
||||
const static TurnInstruction EnterRoundAbout = 11;
|
||||
const static TurnInstruction LeaveRoundAbout = 12;
|
||||
const static TurnInstruction StayOnRoundAbout = 13;
|
||||
const static TurnInstruction StartAtEndOfStreet = 14;
|
||||
const static TurnInstruction ReachedYourDestination = 15;
|
||||
const static TurnInstruction EnterAgainstAllowedDirection = 16;
|
||||
const static TurnInstruction LeaveAgainstAllowedDirection = 17;
|
||||
|
||||
const static TurnInstruction AccessRestrictionFlag = 128;
|
||||
const static TurnInstruction InverseAccessRestrictionFlag =
|
||||
0x7f; // ~128 does not work without a warning.
|
||||
|
||||
const static int AccessRestrictionPenalty =
|
||||
1 << 15; // unrelated to the bit set in the restriction flag
|
||||
|
||||
static inline TurnInstruction GetTurnDirectionOfInstruction(const double angle)
|
||||
{
|
||||
if (angle >= 23 && angle < 67)
|
||||
{
|
||||
return TurnSharpRight;
|
||||
return TurnInstruction::TurnSharpRight;
|
||||
}
|
||||
if (angle >= 67 && angle < 113)
|
||||
{
|
||||
return TurnRight;
|
||||
return TurnInstruction::TurnRight;
|
||||
}
|
||||
if (angle >= 113 && angle < 158)
|
||||
{
|
||||
return TurnSlightRight;
|
||||
return TurnInstruction::TurnSlightRight;
|
||||
}
|
||||
if (angle >= 158 && angle < 202)
|
||||
{
|
||||
return GoStraight;
|
||||
return TurnInstruction::GoStraight;
|
||||
}
|
||||
if (angle >= 202 && angle < 248)
|
||||
{
|
||||
return TurnSlightLeft;
|
||||
return TurnInstruction::TurnSlightLeft;
|
||||
}
|
||||
if (angle >= 248 && angle < 292)
|
||||
{
|
||||
return TurnLeft;
|
||||
return TurnInstruction::TurnLeft;
|
||||
}
|
||||
if (angle >= 292 && angle < 336)
|
||||
{
|
||||
return TurnSharpLeft;
|
||||
return TurnInstruction::TurnSharpLeft;
|
||||
}
|
||||
return UTurn;
|
||||
return TurnInstruction::UTurn;
|
||||
}
|
||||
|
||||
static inline bool TurnIsNecessary(const short turnInstruction)
|
||||
static inline bool TurnIsNecessary(const TurnInstruction turn_instruction)
|
||||
{
|
||||
if (NoTurn == turnInstruction || StayOnRoundAbout == turnInstruction)
|
||||
if (TurnInstruction::NoTurn == turn_instruction || TurnInstruction::StayOnRoundAbout == turn_instruction)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user