Keep ranges of stop ids in lines.

This commit is contained in:
Vladimir Byko-Ianko 2017-10-25 11:58:43 +03:00 committed by mpimenov
parent 1629527527
commit 86966941d1
7 changed files with 51 additions and 9 deletions

View file

@ -251,11 +251,11 @@ UNIT_TEST(DeserializerFromJson_Lines)
vector<Line> const expected = {Line(19207936 /* line id */, "1" /* number */, "Московская линия" /* title */,
"subway" /* type */, 2 /* network id */,
{343262691, 343259523, 343252898, 209191847, 2947858576} /* stop ids */),
{{343262691, 343259523, 343252898, 209191847, 2947858576}} /* stop ids */),
Line(19207937 /* line id */, "2" /* number */, "Московская линия" /* title */,
"subway" /* type */, 2 /* network id */,
{246659391, 246659390, 209191855, 209191854, 209191853,
209191852, 209191851} /* stop ids */)};
{{246659391, 246659390, 209191855, 209191854, 209191853,
209191852, 209191851}} /* stop ids */)};
TestDeserializerFromJson(jsonBuffer, "lines", expected);
}

View file

@ -230,6 +230,13 @@ void DeserializerFromJson::operator()(FeatureIdentifiers & id, char const * name
id = FeatureIdentifiers(osmId.EncodedId() /* osm id */, it->second[0] /* feature id */);
}
void DeserializerFromJson::operator()(StopIdRanges & rs, char const * name)
{
vector<StopId> stopIds;
(*this)(stopIds, name);
rs = StopIdRanges({stopIds});
}
void BuildTransit(string const & mwmDir, string const & countryId,
string const & osmIdsToFeatureIdPath, string const & transitDir)
{

View file

@ -40,6 +40,7 @@ public:
void operator()(m2::PointD & p, char const * name = nullptr);
void operator()(ShapeId & id, char const * name = nullptr);
void operator()(FeatureIdentifiers & id, char const * name = nullptr);
void operator()(StopIdRanges & rs, char const * name = nullptr);
template <typename T>
void operator()(std::vector<T> & vs, char const * name = nullptr)

View file

@ -126,7 +126,12 @@ UNIT_TEST(Transit_LineSerialization)
}
{
Line line(10 /* line id */, "11" /* number */, "Линия" /* title */,
"subway" /* type */, 12 /* network id */, {13, 14, 15} /* stop ids */);
"subway" /* type */, 12 /* network id */, {{13, 14, 15}} /* stop ids */);
TestSerialization(line);
}
{
Line line(100 /* line id */, "101" /* number */, "Линия" /* title */,
"subway" /* type */, 103 /* network id */, {{1, 2, 3}, {7, 8, 9}} /* stop ids */);
TestSerialization(line);
}
}

View file

@ -102,6 +102,11 @@ public:
(*this)(id.GetFeatureId(), name);
}
void operator()(StopIdRanges const & rs, char const * name = nullptr)
{
(*this)(rs.GetIds(), name);
}
template <typename T>
void operator()(std::vector<T> const & vs, char const * /* name */ = nullptr)
{
@ -178,6 +183,11 @@ public:
id = FeatureIdentifiers(kInvalidOsmId, featureId);
}
void operator()(StopIdRanges & rs, char const * name = nullptr)
{
operator()(rs.m_ids, name);
}
void operator()(vector<m2::PointD> & vs, char const * /* name */ = nullptr)
{
auto const size = ReadVarUint<uint64_t, Source>(m_source);

View file

@ -212,7 +212,7 @@ bool Transfer::IsValid() const
// Line -------------------------------------------------------------------------------------------
Line::Line(LineId id, std::string const & number, std::string const & title,
std::string const & type, NetworkId networkId, std::vector<StopId> const & stopIds)
std::string const & type, NetworkId networkId, Ranges const & stopIds)
: m_id(id)
, m_number(number)
, m_title(title)
@ -230,7 +230,7 @@ bool Line::IsEqualForTesting(Line const & line) const
bool Line::IsValid() const
{
return m_id != kInvalidLineId && m_networkId != kInvalidNetworkId && !m_stopIds.empty();
return m_id != kInvalidLineId && m_networkId != kInvalidNetworkId && m_stopIds.IsValid();
}
// Shape ------------------------------------------------------------------------------------------

View file

@ -23,6 +23,7 @@ using FeatureId = uint32_t;
using OsmId = uint64_t;
using Weight = double;
using Anchor = uint8_t;
using Ranges = std::vector<std::vector<StopId>>;
LineId constexpr kInvalidLineId = std::numeric_limits<LineId>::max();
StopId constexpr kInvalidStopId = std::numeric_limits<StopId>::max();
@ -297,12 +298,30 @@ private:
std::vector<TitleAnchor> m_titleAnchors;
};
class StopIdRanges
{
public:
StopIdRanges() = default;
explicit StopIdRanges(Ranges const & ids) : m_ids(ids) {}
bool operator==(StopIdRanges const & rhs) const { return m_ids == rhs.m_ids; }
bool IsEqualForTesting(StopIdRanges const & rhs) const { return *this == rhs; }
bool IsValid() const { return !m_ids.empty(); }
Ranges const & GetIds() const { return m_ids; }
private:
DECLARE_TRANSIT_TYPE_FRIENDS
DECLARE_VISITOR_AND_DEBUG_PRINT(StopIdRanges, visitor(m_ids, "ids"))
Ranges m_ids;
};
class Line
{
public:
Line() = default;
Line(LineId id, std::string const & number, std::string const & title, std::string const & type,
NetworkId networkId, std::vector<StopId> const & stopIds);
NetworkId networkId, Ranges const & stopIds);
bool IsEqualForTesting(Line const & line) const;
bool IsValid() const;
@ -311,7 +330,7 @@ public:
std::string const & GetTitle() const { return m_title; }
std::string const & GetType() const { return m_type; }
NetworkId GetNetworkId() const { return m_networkId; }
std::vector<StopId> const & GetStopIds() const { return m_stopIds; }
Ranges const & GetStopIds() const { return m_stopIds.GetIds(); }
private:
DECLARE_TRANSIT_TYPE_FRIENDS
@ -325,7 +344,7 @@ private:
std::string m_title;
std::string m_type;
NetworkId m_networkId = kInvalidNetworkId;
std::vector<StopId> m_stopIds;
StopIdRanges m_stopIds;
};
class Shape