diff --git a/generator/generator_tests/transit_test.cpp b/generator/generator_tests/transit_test.cpp index 2c18796259..9ca0963243 100644 --- a/generator/generator_tests/transit_test.cpp +++ b/generator/generator_tests/transit_test.cpp @@ -251,11 +251,11 @@ UNIT_TEST(DeserializerFromJson_Lines) vector 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); } diff --git a/generator/transit_generator.cpp b/generator/transit_generator.cpp index 0025c21001..5dbdfcc91c 100644 --- a/generator/transit_generator.cpp +++ b/generator/transit_generator.cpp @@ -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 stopIds; + (*this)(stopIds, name); + rs = StopIdRanges({stopIds}); +} + void BuildTransit(string const & mwmDir, string const & countryId, string const & osmIdsToFeatureIdPath, string const & transitDir) { diff --git a/generator/transit_generator.hpp b/generator/transit_generator.hpp index 2336a23a20..8e598fb9a0 100644 --- a/generator/transit_generator.hpp +++ b/generator/transit_generator.hpp @@ -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 void operator()(std::vector & vs, char const * name = nullptr) diff --git a/routing_common/routing_common_tests/transit_test.cpp b/routing_common/routing_common_tests/transit_test.cpp index e216ab4d1b..a5a04b8f90 100644 --- a/routing_common/routing_common_tests/transit_test.cpp +++ b/routing_common/routing_common_tests/transit_test.cpp @@ -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); } } diff --git a/routing_common/transit_serdes.hpp b/routing_common/transit_serdes.hpp index eee0640740..ffaba9def2 100644 --- a/routing_common/transit_serdes.hpp +++ b/routing_common/transit_serdes.hpp @@ -102,6 +102,11 @@ public: (*this)(id.GetFeatureId(), name); } + void operator()(StopIdRanges const & rs, char const * name = nullptr) + { + (*this)(rs.GetIds(), name); + } + template void operator()(std::vector 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 & vs, char const * /* name */ = nullptr) { auto const size = ReadVarUint(m_source); diff --git a/routing_common/transit_types.cpp b/routing_common/transit_types.cpp index 0845f233ea..13d958bbba 100644 --- a/routing_common/transit_types.cpp +++ b/routing_common/transit_types.cpp @@ -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 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 ------------------------------------------------------------------------------------------ diff --git a/routing_common/transit_types.hpp b/routing_common/transit_types.hpp index 7346c0359a..4fe96760f2 100644 --- a/routing_common/transit_types.hpp +++ b/routing_common/transit_types.hpp @@ -23,6 +23,7 @@ using FeatureId = uint32_t; using OsmId = uint64_t; using Weight = double; using Anchor = uint8_t; +using Ranges = std::vector>; LineId constexpr kInvalidLineId = std::numeric_limits::max(); StopId constexpr kInvalidStopId = std::numeric_limits::max(); @@ -297,12 +298,30 @@ private: std::vector 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 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 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 m_stopIds; + StopIdRanges m_stopIds; }; class Shape