1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
#pragma once
#include "transit/transit_types.hpp"
#include "base/assert.hpp"
#include <memory>
#include <utility>
#include <vector>
namespace routing
{
class TransitInfo final
{
public:
enum class Type
{
Gate,
Edge,
Transfer
};
struct Edge
{
Edge() = default;
explicit Edge(transit::Edge const & edge)
: m_lineId(edge.GetLineId())
, m_stop1Id(edge.GetStop1Id())
, m_stop2Id(edge.GetStop2Id())
, m_shapeIds(edge.GetShapeIds())
{
ASSERT(!edge.GetTransfer(), ());
}
transit::LineId m_lineId = transit::kInvalidLineId;
transit::StopId m_stop1Id = transit::kInvalidStopId;
transit::StopId m_stop2Id = transit::kInvalidStopId;
std::vector<transit::ShapeId> m_shapeIds;
};
struct Gate
{
Gate() = default;
explicit Gate(transit::Gate const & gate) : m_featureId(gate.GetFeatureId()) {}
transit::FeatureId m_featureId = transit::kInvalidFeatureId;
};
struct Transfer
{
Transfer() = default;
explicit Transfer(transit::Edge const & edge)
: m_stop1Id(edge.GetStop1Id()), m_stop2Id(edge.GetStop2Id())
{
ASSERT(edge.GetTransfer(), ());
}
transit::StopId m_stop1Id = transit::kInvalidStopId;
transit::StopId m_stop2Id = transit::kInvalidStopId;
};
explicit TransitInfo(transit::Gate const & gate)
: m_type(Type::Gate), m_edge(), m_gate(gate), m_transfer()
{
}
explicit TransitInfo(transit::Edge const & edge)
: m_type(edge.GetTransfer() ? Type::Transfer : Type::Edge)
, m_edge(edge.GetTransfer() ? Edge() : Edge(edge))
, m_gate()
, m_transfer(edge.GetTransfer() ? Transfer(edge) : Transfer())
{
}
Type GetType() const { return m_type; }
Edge const & GetEdge() const
{
ASSERT_EQUAL(m_type, Type::Edge, ());
return m_edge;
}
Gate const & GetGate() const
{
ASSERT_EQUAL(m_type, Type::Gate, ());
return m_gate;
}
Transfer const & GetTransfer() const
{
ASSERT_EQUAL(m_type, Type::Transfer, ());
return m_transfer;
}
private:
Type const m_type;
// Valid for m_type == Type::Edge only.
Edge const m_edge;
// Valid for m_type == Type::Gate only.
Gate const m_gate;
// Valid for m_type == Type::Transfer only.
Transfer const m_transfer;
};
class TransitInfoWrapper final
{
public:
explicit TransitInfoWrapper(std::unique_ptr<TransitInfo> ptr) : m_ptr(move(ptr)) {}
explicit TransitInfoWrapper(TransitInfoWrapper && rhs) { swap(m_ptr, rhs.m_ptr); }
explicit TransitInfoWrapper(TransitInfoWrapper const & rhs)
{
if (rhs.m_ptr)
m_ptr = my::make_unique<TransitInfo>(*rhs.m_ptr);
}
TransitInfoWrapper & operator=(TransitInfoWrapper && rhs)
{
swap(m_ptr, rhs.m_ptr);
return *this;
}
TransitInfoWrapper & operator=(TransitInfoWrapper const & rhs)
{
m_ptr.reset();
if (rhs.m_ptr)
m_ptr = my::make_unique<TransitInfo>(*rhs.m_ptr);
return *this;
}
bool HasTransitInfo() const { return m_ptr != nullptr; }
TransitInfo const & Get() const
{
ASSERT(HasTransitInfo(), ());
return *m_ptr;
}
void Set(std::unique_ptr<TransitInfo> ptr) { m_ptr = move(ptr); }
private:
std::unique_ptr<TransitInfo> m_ptr;
};
inline std::string DebugPrint(TransitInfo::Type type)
{
switch (type)
{
case TransitInfo::Type::Gate: return "Gate";
case TransitInfo::Type::Edge: return "Edge";
case TransitInfo::Type::Transfer: return "Transfer";
}
}
} // namespace routing
|