From 21370ee3d9635139c460addabdf60abb559369c7 Mon Sep 17 00:00:00 2001 From: vng Date: Mon, 21 Dec 2015 13:27:58 +0300 Subject: [PATCH] Avoid some copy-paste. --- generator/feature_builder.cpp | 71 +++++++++-------------------------- generator/feature_builder.hpp | 2 +- generator/osm_source.cpp | 4 +- 3 files changed, 21 insertions(+), 56 deletions(-) diff --git a/generator/feature_builder.cpp b/generator/feature_builder.cpp index bbb2497891..6fd9d1b676 100644 --- a/generator/feature_builder.cpp +++ b/generator/feature_builder.cpp @@ -10,6 +10,7 @@ #include "geometry/region2d.hpp" +#include "coding/bit_streams.hpp" #include "coding/byte_stream.hpp" #include "base/logging.hpp" @@ -354,11 +355,11 @@ bool FeatureBuilder1::CheckValid() const return true; } -void FeatureBuilder1::SerializeBase(TBuffer & data, serial::CodingParams const & params, bool needSerializeAdditionalInfo) const +void FeatureBuilder1::SerializeBase(TBuffer & data, serial::CodingParams const & params, bool saveAddInfo) const { PushBackByteSink sink(data); - m_params.Write(sink, needSerializeAdditionalInfo); + m_params.Write(sink, saveAddInfo); if (m_params.GetGeomType() == GEOM_POINT) serial::SavePoint(sink, m_center, params); @@ -372,7 +373,7 @@ void FeatureBuilder1::Serialize(TBuffer & data) const serial::CodingParams cp; - SerializeBase(data, cp); + SerializeBase(data, cp, true /* store additional info from FeatureParams */); PushBackByteSink sink(data); @@ -540,7 +541,6 @@ uint64_t FeatureBuilder1::GetWayIDForRouting() const return 0; } - bool FeatureBuilder2::PreSerialize(SupportingData const & data) { // make flags actual before header serialization @@ -560,41 +560,6 @@ bool FeatureBuilder2::PreSerialize(SupportingData const & data) return TBase::PreSerialize(); } -namespace -{ - template class BitSink - { - TSink & m_sink; - uint8_t m_pos; - uint8_t m_current; - - public: - BitSink(TSink & sink) : m_sink(sink), m_pos(0), m_current(0) {} - - void Finish() - { - if (m_pos > 0) - { - WriteToSink(m_sink, m_current); - m_pos = 0; - m_current = 0; - } - } - - void Write(uint8_t value, uint8_t count) - { - ASSERT_LESS ( count, 9, () ); - ASSERT_EQUAL ( value >> count, 0, () ); - - if (m_pos + count > 8) - Finish(); - - m_current |= (value << m_pos); - m_pos += count; - } - }; -} - void FeatureBuilder2::Serialize(SupportingData & data, serial::CodingParams const & params) { data.m_buffer.clear(); @@ -612,24 +577,24 @@ void FeatureBuilder2::Serialize(SupportingData & data, serial::CodingParams cons trgCount -= 2; } - BitSink< PushBackByteSink > bitSink(sink); - EGeomType const type = m_params.GetGeomType(); - if (type == GEOM_LINE) { - bitSink.Write(ptsCount, 4); - if (ptsCount == 0) - bitSink.Write(data.m_ptsMask, 4); - } - else if (type == GEOM_AREA) - { - bitSink.Write(trgCount, 4); - if (trgCount == 0) - bitSink.Write(data.m_trgMask, 4); - } + BitWriter> bitSink(sink); - bitSink.Finish(); + if (type == GEOM_LINE) + { + bitSink.Write(ptsCount, 4); + if (ptsCount == 0) + bitSink.Write(data.m_ptsMask, 4); + } + else if (type == GEOM_AREA) + { + bitSink.Write(trgCount, 4); + if (trgCount == 0) + bitSink.Write(data.m_trgMask, 4); + } + } if (type == GEOM_LINE) { diff --git a/generator/feature_builder.hpp b/generator/feature_builder.hpp index 084a40894c..b2005d10b9 100644 --- a/generator/feature_builder.hpp +++ b/generator/feature_builder.hpp @@ -87,7 +87,7 @@ public: /// @name Serialization. //@{ void Serialize(TBuffer & data) const; - void SerializeBase(TBuffer & data, serial::CodingParams const & params, bool needSearializeAdditionalInfo = true) const; + void SerializeBase(TBuffer & data, serial::CodingParams const & params, bool saveAddInfo) const; void Deserialize(TBuffer & data); //@} diff --git a/generator/osm_source.cpp b/generator/osm_source.cpp index 8519c72528..d543ee1ffe 100644 --- a/generator/osm_source.cpp +++ b/generator/osm_source.cpp @@ -519,9 +519,9 @@ bool GenerateFeaturesImpl(feature::GenerateInfo & info) bucketer.GetNames(info.m_bucketNames); } - catch (Reader::Exception const & e) + catch (Reader::Exception const & ex) { - LOG(LCRITICAL, ("Error with file ", e.what())); + LOG(LCRITICAL, ("Error with file", ex.Msg())); } return true;