Factor out serial::SavePoint, serial::LoadPoint.

This commit is contained in:
vng 2011-09-16 22:23:25 +03:00 committed by Alex Zolotarev
parent 5f05cd052b
commit 3e2ecdc144
6 changed files with 26 additions and 37 deletions

View file

@ -257,8 +257,7 @@ void FeatureBuilder1::SerializeBase(buffer_t & data, serial::CodingParams const
m_Params.Write(sink);
if (m_Params.GetGeomType() == GEOM_POINT)
WriteVarUint(sink, EncodeDelta(PointD2PointU(m_Center.x, m_Center.y, params.GetCoordBits()),
params.GetBasePoint()));
serial::SavePoint(sink, m_Center, params);
}
void FeatureBuilder1::Serialize(buffer_t & data) const
@ -304,10 +303,7 @@ void FeatureBuilder1::Deserialize(buffer_t & data)
EGeomType const type = m_Params.GetGeomType();
if (type == GEOM_POINT)
{
CoordPointT const center = PointU2PointD(
DecodeDelta(ReadVarUint<uint64_t>(source), cp.GetBasePoint()), cp.GetCoordBits());
m_Center = m2::PointD(center.first, center.second);
m_Center = serial::LoadPoint(source, cp);
m_LimitRect.Add(m_Center);
return;
}

View file

@ -31,15 +31,14 @@ namespace serial
template <typename WriterT> void Save(WriterT & writer) const
{
WriteVarUint(writer, GetCoordBits());
WriteVarUint(writer, static_cast<uint64_t>(GetBasePointInt64()));
WriteVarUint(writer, m_BasePointUint64);
}
template <typename SourceT> void Load(SourceT & src)
{
uint32_t const coordBits = ReadVarUint<uint32_t>(src);
ASSERT_LESS(coordBits, 32, ());
uint64_t const basePointUint64 = ReadVarUint<uint64_t>(src);
*this = CodingParams(coordBits, basePointUint64);
*this = CodingParams(coordBits, ReadVarUint<uint64_t>(src));
}
private:

View file

@ -1,27 +1,10 @@
#pragma once
#include "point_to_int64.hpp"
#include "../geometry/point2d.hpp"
namespace feature
{
namespace pts
{
inline int64_t FromPoint(m2::PointD const & p, uint32_t coordBits)
{
return PointToInt64(p.x, p.y, coordBits);
}
inline m2::PointD ToPoint(int64_t i, uint32_t coordBits)
{
CoordPointT const pt = Int64ToPoint(i, coordBits);
return m2::PointD(pt.first, pt.second);
}
}
static int g_arrWorldScales[] = { 2, 5, 7, 9 }; // 9 = scales::GetUpperWorldScale()
static int g_arrCountryScales[] = { 10, 12, 14, 17 }; // 17 = scales::GetUpperScale()

View file

@ -46,12 +46,7 @@ void LoaderCurrent::ParseCommon()
if (type == GEOM_POINT)
{
serial::CodingParams const & cp = GetDefCodingParams();
CoordPointT const center = PointU2PointD(
DecodeDelta(ReadVarUint<uint64_t>(source), cp.GetBasePoint()), cp.GetCoordBits());
m_pF->m_Center = m2::PointD(center.first, center.second);
m_pF->m_Center = serial::LoadPoint(source, GetDefCodingParams());
m_pF->m_LimitRect.Add(m_pF->m_Center);
}

View file

@ -2,7 +2,6 @@
#include "mercator.hpp"
#include "point_to_int64.hpp"
#include "geometry_coding.hpp"
#include "coding_params.hpp"
#include "../geometry/pointu_to_uint64.hpp"
@ -76,9 +75,12 @@ namespace serial
geo_coding::OutPointsT adapt(upoints);
(*fn)(make_read_adapter(deltas), pts::GetBasePoint(params), pts::GetMaxPoint(params), adapt);
// It is may be not empty, when storing triangles.
if (points.empty())
if (points.size() < 2)
{
// Do not call reserve when loading triangles - they are accumulated to one vector.
points.reserve(count);
}
transform(upoints.begin(), upoints.begin() + adapt.size(), back_inserter(points),
bind(&pts::U2D, _1, params.GetCoordBits()));
}

View file

@ -2,6 +2,8 @@
#include "geometry_coding.hpp"
#include "tesselator_decl.hpp"
#include "point_to_int64.hpp"
#include "coding_params.hpp"
#include "../geometry/point2d.hpp"
@ -18,8 +20,6 @@
namespace serial
{
class CodingParams;
template <class TCont, class TSink>
inline void WriteVarUintArray(TCont const & v, TSink & sink)
{
@ -51,6 +51,20 @@ namespace serial
vector<m2::PointD> & points, size_t reserveF = 1);
//@}
template <class TSink>
void SavePoint(TSink & sink, m2::PointD const & pt, CodingParams const & cp)
{
WriteVarUint(sink, EncodeDelta(PointD2PointU(pt.x, pt.y, cp.GetCoordBits()), cp.GetBasePoint()));
}
template <class TSource>
m2::PointD LoadPoint(TSource & src, CodingParams const & cp)
{
CoordPointT const c = PointU2PointD(
DecodeDelta(ReadVarUint<uint64_t>(src), cp.GetBasePoint()), cp.GetCoordBits());
return m2::PointD(c.first, c.second);
}
template <class TSink>
void SaveInner(EncodeFunT fn, vector<m2::PointD> const & points,
CodingParams const & params, TSink & sink)