diff --git a/indexer/feature.cpp b/indexer/feature.cpp index 4d40732657..98fea4ec02 100644 --- a/indexer/feature.cpp +++ b/indexer/feature.cpp @@ -235,14 +235,14 @@ void FeatureBuilder1::Serialize(buffer_t & data) const PushBackByteSink sink(data); if (m_bLinear || m_bArea) - feature::SavePoints(m_Geometry, 0, sink); + serial::SaveOuterPath(m_Geometry, 0, sink); if (m_bArea) { WriteVarUint(sink, uint32_t(m_Holes.size())); for (list::const_iterator i = m_Holes.begin(); i != m_Holes.end(); ++i) - feature::SavePoints(*i, 0, sink); + serial::SaveOuterPath(*i, 0, sink); } // check for correct serialization @@ -274,7 +274,7 @@ void FeatureBuilder1::Deserialize(buffer_t & data) if (m_bLinear || m_bArea) { - feature::LoadPoints(m_Geometry, 0, src); + serial::LoadOuterPath(src, 0, m_Geometry); CalcRect(m_Geometry, m_LimitRect); } @@ -284,7 +284,7 @@ void FeatureBuilder1::Deserialize(buffer_t & data) for (uint32_t i = 0; i < count; ++i) { m_Holes.push_back(points_t()); - feature::LoadPoints(m_Holes.back(), 0, src); + serial::LoadOuterPath(src, 0, m_Holes.back()); } } diff --git a/indexer/feature_impl.hpp b/indexer/feature_impl.hpp index 99e0bcc05a..4559a22e98 100644 --- a/indexer/feature_impl.hpp +++ b/indexer/feature_impl.hpp @@ -1,15 +1,9 @@ #pragma once -#include "cell_id.hpp" - -#include "../coding/write_to_sink.hpp" -#include "../coding/varint.hpp" +#include "point_to_int64.hpp" #include "../geometry/point2d.hpp" -#include "../std/algorithm.hpp" -#include "../std/iterator.hpp" - namespace feature { @@ -27,82 +21,6 @@ namespace feature } } - namespace detail - { - inline void TransformPoints(vector const & points, vector & cells) - { - cells.reserve(points.size()); - transform(points.begin(), points.end(), back_inserter(cells), &pts::FromPoint); - } - - template - void WriteCellsSimple(vector const & cells, int64_t base, TSink & sink) - { - for (size_t i = 0; i < cells.size(); ++i) - WriteVarInt(sink, i == 0 ? cells[0] - base : cells[i] - cells[i-1]); - } - - template - void WriteCells(vector const & cells, int64_t base, TSink & sink) - { - vector buffer; - MemWriter > writer(buffer); - - WriteCellsSimple(cells, base, writer); - - uint32_t const count = static_cast(buffer.size()); - WriteVarUint(sink, count); - sink.Write(&buffer[0], count); - } - - template class points_emitter - { - TCont & m_points; - int64_t m_id; - - public: - points_emitter(TCont & points, uint32_t count, int64_t base) - : m_points(points), m_id(base) - { - m_points.reserve(count); - } - void operator() (int64_t id) - { - m_points.push_back(pts::ToPoint(m_id += id)); - } - }; - - template - void ReadPoints(TCont & points, int64_t base, TSource & src) - { - uint32_t const count = ReadVarUint(src); - vector buffer(count); - char * p = &buffer[0]; - src.Read(p, count); - - ReadVarInt64Array(p, p + count, points_emitter(points, count / 2, base)); - } - } - - template - void SavePoints(vector const & points, int64_t base, TSink & sink) - { - ASSERT_GREATER ( points.size(), 1, () ); - - vector cells; - detail::TransformPoints(points, cells); - - detail::WriteCells(cells, base, sink); - } - - template - void LoadPoints(TCont & points, int64_t base, TSource & src) - { - detail::ReadPoints(points, base, src); - - ASSERT_GREATER ( points.size(), 1, () ); - } - static int g_arrScales[] = { 7, 10, 14, 17 }; // 17 = scales::GetUpperScale() diff --git a/indexer/geometry_serialization.cpp b/indexer/geometry_serialization.cpp index a672c89602..cd83bb24bf 100644 --- a/indexer/geometry_serialization.cpp +++ b/indexer/geometry_serialization.cpp @@ -52,7 +52,8 @@ namespace serial (*fn)(upoints, pts::GetBasePoint(base), pts::GetMaxPoint(), deltas); } - void Decode(DecodeFunT fn, DeltasT const & deltas, int64_t base, OutPointsT & points, size_t reserveF/* = 1*/) + template + void DecodeImpl(TDecodeFun fn, DeltasT const & deltas, int64_t base, TOutPoints & points, size_t reserveF) { size_t const count = deltas.size() * reserveF; @@ -67,6 +68,16 @@ namespace serial transform(upoints.begin(), upoints.end(), back_inserter(points), &pts::U2D); } + void Decode(DecodeFunT fn, DeltasT const & deltas, int64_t base, OutPointsT & points, size_t reserveF) + { + DecodeImpl(fn, deltas, base, points, reserveF); + } + + void Decode(DecodeFunT fn, DeltasT const & deltas, int64_t base, vector & points, size_t reserveF) + { + DecodeImpl(fn, deltas, base, points, reserveF); + } + void const * LoadInner(DecodeFunT fn, void const * pBeg, size_t count, int64_t base, OutPointsT & points) { DeltasT deltas; diff --git a/indexer/geometry_serialization.hpp b/indexer/geometry_serialization.hpp index d29f0bf058..fe42a4b772 100644 --- a/indexer/geometry_serialization.hpp +++ b/indexer/geometry_serialization.hpp @@ -30,13 +30,20 @@ namespace serial typedef vector PointsT; typedef vector DeltasT; + /// @name Encode and Decode function types. + //@{ typedef void (*EncodeFunT)(PointsT const &, m2::PointU const &, m2::PointU const &, DeltasT &); typedef void (*DecodeFunT)(DeltasT const &, m2::PointU const &, m2::PointU const &, PointsT &); + //@} void Encode(EncodeFunT fn, vector const & points, int64_t base, DeltasT & deltas); typedef buffer_vector OutPointsT; + /// @name Overloads for different out container types. + //@{ void Decode(DecodeFunT fn, DeltasT const & deltas, int64_t base, OutPointsT & points, size_t reserveF = 1); + void Decode(DecodeFunT fn, DeltasT const & deltas, int64_t base, vector & points, size_t reserveF = 1); + //@} template void SaveInner(EncodeFunT fn, vector const & points, int64_t base, TSink & sink) @@ -69,8 +76,8 @@ namespace serial void const * LoadInner(DecodeFunT fn, void const * pBeg, size_t count, int64_t base, OutPointsT & points); - template - void LoadOuter(DecodeFunT fn, TSource & src, int64_t base, OutPointsT & points, size_t reserveF = 1) + template + void LoadOuter(DecodeFunT fn, TSource & src, int64_t base, TPoints & points, size_t reserveF = 1) { uint32_t const count = ReadVarUint(src); vector buffer(count); @@ -103,8 +110,8 @@ namespace serial return LoadInner(&geo_coding::DecodePolyline, pBeg, count, base, points); } - template - void LoadOuterPath(TSource & src, int64_t base, OutPointsT & points) + template + void LoadOuterPath(TSource & src, int64_t base, TPoints & points) { LoadOuter(&geo_coding::DecodePolyline, src, base, points); }