From fa69cb0ab31abd95627389accc06ecbcad4863d5 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Tue, 31 Oct 2017 17:27:41 +0300 Subject: [PATCH] Adding operator()(TransitHeader) for FixedSizeSerializer and FixedSizeDeserializer. --- generator/transit_generator.cpp | 4 ++-- routing/transit_graph_loader.cpp | 2 +- routing_common/routing_common_tests/transit_test.cpp | 6 +++--- routing_common/transit_serdes.hpp | 10 ++++------ routing_common/transit_types.hpp | 11 ++++------- 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/generator/transit_generator.cpp b/generator/transit_generator.cpp index e1d7e44f39..3f9b59731b 100644 --- a/generator/transit_generator.cpp +++ b/generator/transit_generator.cpp @@ -283,7 +283,7 @@ void BuildTransit(string const & mwmDir, string const & countryId, auto const startOffset = w.Pos(); Serializer serializer(w); FixedSizeSerializer numberSerializer(w); - VisitHeader(numberSerializer, header); + numberSerializer(header); vector stops; DeserializeFromJson(root, "stops", mapping, stops); @@ -319,7 +319,7 @@ void BuildTransit(string const & mwmDir, string const & countryId, CHECK(header.IsValid(), (header)); auto const endOffset = w.Pos(); w.Seek(startOffset); - VisitHeader(numberSerializer, header); + numberSerializer(header); w.Seek(endOffset); LOG(LINFO, (TRANSIT_FILE_TAG, "section is ready. Header:", header)); } diff --git a/routing/transit_graph_loader.cpp b/routing/transit_graph_loader.cpp index 07c7182b4b..cffce6b41b 100644 --- a/routing/transit_graph_loader.cpp +++ b/routing/transit_graph_loader.cpp @@ -62,7 +62,7 @@ unique_ptr TransitGraphLoader::CreateTransitGraph(NumMwmId numMwmI transit::FixedSizeDeserializer> numberDeserializer(src); transit::TransitHeader header; - VisitHeader(numberDeserializer, header); + numberDeserializer(header); vector stops; deserializer(stops); diff --git a/routing_common/routing_common_tests/transit_test.cpp b/routing_common/routing_common_tests/transit_test.cpp index 646236a407..585a76c22b 100644 --- a/routing_common/routing_common_tests/transit_test.cpp +++ b/routing_common/routing_common_tests/transit_test.cpp @@ -61,14 +61,14 @@ UNIT_TEST(Transit_HeaderRewriting) // Writing. FixedSizeSerializer>> serializer(writer); - VisitHeader(serializer, header); + serializer(header); auto const endOffset = writer.Pos(); // Rewriting. header = bigHeader; writer.Seek(0 /* start offset */); - VisitHeader(serializer, header); + serializer(header); TEST_EQUAL(writer.Pos(), endOffset, ()); // Reading. @@ -76,7 +76,7 @@ UNIT_TEST(Transit_HeaderRewriting) ReaderSource src(reader); TransitHeader deserializedHeader; FixedSizeDeserializer> deserializer(src); - VisitHeader(deserializer, deserializedHeader); + deserializer(deserializedHeader); TEST(deserializedHeader.IsEqualForTesting(bigHeader), (deserializedHeader, bigHeader)); } diff --git a/routing_common/transit_serdes.hpp b/routing_common/transit_serdes.hpp index a4a939cb31..869258293a 100644 --- a/routing_common/transit_serdes.hpp +++ b/routing_common/transit_serdes.hpp @@ -233,6 +233,8 @@ public: WriteToSink(m_sink, t); } + void operator()(TransitHeader const & header) { header.Visit(*this); } + private: Sink & m_sink; }; @@ -250,14 +252,10 @@ public: ReadPrimitiveFromSource(m_source, t); } + void operator()(TransitHeader & header) { header.Visit(*this); } + private: Source & m_source; }; - -template -void VisitHeader(T & t, TransitHeader & header) -{ - header.Visit(t); -} } // namespace transit } // namespace routing diff --git a/routing_common/transit_types.hpp b/routing_common/transit_types.hpp index 965ea6de8b..4e3efc503e 100644 --- a/routing_common/transit_types.hpp +++ b/routing_common/transit_types.hpp @@ -14,8 +14,6 @@ namespace routing { namespace transit { -struct TransitHeader; - using Anchor = uint8_t; using FeatureId = uint32_t; using LineId = uint32_t; @@ -39,14 +37,13 @@ TransferId constexpr kInvalidTransferId = std::numeric_limits::max() Weight constexpr kInvalidWeight = -1.0; #define DECLARE_TRANSIT_TYPE_FRIENDS \ - template \ - friend class Serializer; \ - template \ - friend class Deserializer; \ + template friend class Serializer; \ + template friend class Deserializer; \ friend class DeserializerFromJson; \ template \ friend void TestCommonSerialization(Obj const & obj); \ - template friend void VisitHeader(T & t, TransitHeader & header); \ + template friend class FixedSizeSerializer; \ + template friend class FixedSizeDeserializer; \ struct TransitHeader {