Remove obsolete feature-points serialization functions.

This commit is contained in:
vng 2011-02-08 00:06:04 +02:00 committed by Alex Zolotarev
parent 5c736831eb
commit 2680e4a2a7
4 changed files with 28 additions and 92 deletions

View file

@ -235,14 +235,14 @@ void FeatureBuilder1::Serialize(buffer_t & data) const
PushBackByteSink<buffer_t> 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<points_t>::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());
}
}

View file

@ -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<m2::PointD> const & points, vector<int64_t> & cells)
{
cells.reserve(points.size());
transform(points.begin(), points.end(), back_inserter(cells), &pts::FromPoint);
}
template <class TSink>
void WriteCellsSimple(vector<int64_t> 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 <class TSink>
void WriteCells(vector<int64_t> const & cells, int64_t base, TSink & sink)
{
vector<char> buffer;
MemWriter<vector<char> > writer(buffer);
WriteCellsSimple(cells, base, writer);
uint32_t const count = static_cast<uint32_t>(buffer.size());
WriteVarUint(sink, count);
sink.Write(&buffer[0], count);
}
template <class TCont> 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 <class TCont, class TSource>
void ReadPoints(TCont & points, int64_t base, TSource & src)
{
uint32_t const count = ReadVarUint<uint32_t>(src);
vector<char> buffer(count);
char * p = &buffer[0];
src.Read(p, count);
ReadVarInt64Array(p, p + count, points_emitter<TCont>(points, count / 2, base));
}
}
template <class TSink>
void SavePoints(vector<m2::PointD> const & points, int64_t base, TSink & sink)
{
ASSERT_GREATER ( points.size(), 1, () );
vector<int64_t> cells;
detail::TransformPoints(points, cells);
detail::WriteCells(cells, base, sink);
}
template <class TCont, class TSource>
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()

View file

@ -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 <class TDecodeFun, class TOutPoints>
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<m2::PointD> & 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;

View file

@ -30,13 +30,20 @@ namespace serial
typedef vector<m2::PointU> PointsT;
typedef vector<uint64_t> 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<m2::PointD> const & points, int64_t base, DeltasT & deltas);
typedef buffer_vector<m2::PointD, 32> 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<m2::PointD> & points, size_t reserveF = 1);
//@}
template <class TSink>
void SaveInner(EncodeFunT fn, vector<m2::PointD> 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 <class TSource>
void LoadOuter(DecodeFunT fn, TSource & src, int64_t base, OutPointsT & points, size_t reserveF = 1)
template <class TSource, class TPoints>
void LoadOuter(DecodeFunT fn, TSource & src, int64_t base, TPoints & points, size_t reserveF = 1)
{
uint32_t const count = ReadVarUint<uint32_t>(src);
vector<char> buffer(count);
@ -103,8 +110,8 @@ namespace serial
return LoadInner(&geo_coding::DecodePolyline, pBeg, count, base, points);
}
template <class TSource>
void LoadOuterPath(TSource & src, int64_t base, OutPointsT & points)
template <class TSource, class TPoints>
void LoadOuterPath(TSource & src, int64_t base, TPoints & points)
{
LoadOuter(&geo_coding::DecodePolyline, src, base, points);
}