forked from organicmaps/organicmaps
Avoid some copy-paste.
This commit is contained in:
parent
e5f261bbf8
commit
21370ee3d9
3 changed files with 21 additions and 56 deletions
|
@ -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<TBuffer> 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<TBuffer> 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 TSink> 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<TBuffer> > 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<PushBackByteSink<TBuffer>> 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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
//@}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue