[indexer] enum feature::EHeaderTypeMask is changed to enum class feature::HeaderGeomType

This commit is contained in:
Arsentiy Milchakov 2019-04-16 21:11:31 +03:00 committed by Tatiana Yan
parent b2aac0af7c
commit 585e1eec5a
3 changed files with 59 additions and 53 deletions

View file

@ -196,7 +196,7 @@ FeatureType::FeatureType(SharedLoadInfo const * loadInfo, Buffer buffer)
FeatureType::FeatureType(osm::MapObject const & emo)
{
EHeaderTypeMask geomType = HEADER_GEOM_POINT;
HeaderGeomType headerGeomType = HeaderGeomType::Point;
m_limitRect.MakeEmpty();
switch (emo.GetGeomType())
@ -205,18 +205,18 @@ FeatureType::FeatureType(osm::MapObject const & emo)
// It is not possible because of FeatureType::GetFeatureType() never returns GEOM_UNDEFINED.
UNREACHABLE();
case feature::GEOM_POINT:
geomType = HEADER_GEOM_POINT;
headerGeomType = HeaderGeomType::Point;
m_center = emo.GetMercator();
m_limitRect.Add(m_center);
break;
case feature::GEOM_LINE:
geomType = HEADER_GEOM_LINE;
headerGeomType = HeaderGeomType::Line;
m_points = Points(emo.GetPoints().begin(), emo.GetPoints().end());
for (auto const & p : m_points)
m_limitRect.Add(p);
break;
case feature::GEOM_AREA:
geomType = HEADER_GEOM_AREA;
headerGeomType = HeaderGeomType::Area;
m_triangles = Points(emo.GetTriangesAsPoints().begin(), emo.GetTriangesAsPoints().end());
for (auto const & p : m_triangles)
m_limitRect.Add(p);
@ -240,7 +240,7 @@ FeatureType::FeatureType(osm::MapObject const & emo)
copy(emo.GetTypes().begin(), emo.GetTypes().end(), m_types.begin());
m_parsed.m_types = true;
m_header = CalculateHeader(emo.GetTypes().Size(), geomType, m_params);
m_header = CalculateHeader(emo.GetTypes().Size(), headerGeomType, m_params);
m_parsed.m_header2 = true;
m_id = emo.GetID();
@ -250,10 +250,11 @@ feature::EGeomType FeatureType::GetFeatureType() const
{
// FeatureType::FeatureType(osm::MapObject const & emo) expects
// that GEOM_UNDEFINED is never be returned.
switch (m_header & HEADER_GEOTYPE_MASK)
auto const headerGeomType = static_cast<HeaderGeomType>(m_header & HEADER_GEOTYPE_MASK);
switch (headerGeomType)
{
case HEADER_GEOM_LINE: return GEOM_LINE;
case HEADER_GEOM_AREA: return GEOM_AREA;
case HeaderGeomType::Line: return GEOM_LINE;
case HeaderGeomType::Area: return GEOM_AREA;
default: return GEOM_POINT;
}
}
@ -337,9 +338,9 @@ void FeatureType::ParseHeader2()
uint8_t ptsCount = 0, ptsMask = 0, trgCount = 0, trgMask = 0;
BitSource bitSource(m_data + m_offsets.m_header2);
uint8_t const typeMask = Header(m_data) & HEADER_GEOTYPE_MASK;
auto const headerGeomType = static_cast<HeaderGeomType>(Header(m_data) & HEADER_GEOTYPE_MASK);
if (typeMask == HEADER_GEOM_LINE)
if (headerGeomType == HeaderGeomType::Line)
{
ptsCount = bitSource.Read(4);
if (ptsCount == 0)
@ -347,7 +348,7 @@ void FeatureType::ParseHeader2()
else
ASSERT_GREATER(ptsCount, 1, ());
}
else if (typeMask == HEADER_GEOM_AREA)
else if (headerGeomType == HeaderGeomType::Area)
{
trgCount = bitSource.Read(4);
if (trgCount == 0)
@ -357,7 +358,7 @@ void FeatureType::ParseHeader2()
ArrayByteSource src(bitSource.RoundPtr());
serial::GeometryCodingParams const & cp = m_loadInfo->GetDefGeometryCodingParams();
if (typeMask == HEADER_GEOM_LINE)
if (headerGeomType == HeaderGeomType::Line)
{
if (ptsCount > 0)
{
@ -380,7 +381,7 @@ void FeatureType::ParseHeader2()
ReadOffsets(*m_loadInfo, src, ptsMask, m_offsets.m_pts);
}
}
else if (typeMask == HEADER_GEOM_AREA)
else if (headerGeomType == HeaderGeomType::Area)
{
if (trgCount > 0)
{
@ -421,7 +422,8 @@ uint32_t FeatureType::ParseGeometry(int scale)
CHECK(m_loadInfo, ());
ParseHeader2();
if ((Header(m_data) & HEADER_GEOTYPE_MASK) == HEADER_GEOM_LINE)
auto const headerGeomType = static_cast<HeaderGeomType>(Header(m_data) & HEADER_GEOTYPE_MASK);
if (headerGeomType == HeaderGeomType::Line)
{
size_t const count = m_points.size();
if (count < 2)
@ -479,7 +481,8 @@ uint32_t FeatureType::ParseTriangles(int scale)
CHECK(m_loadInfo, ());
ParseHeader2();
if ((Header(m_data) & HEADER_GEOTYPE_MASK) == HEADER_GEOM_AREA)
auto const headerGeomType = static_cast<HeaderGeomType>(Header(m_data) & HEADER_GEOTYPE_MASK);
if (headerGeomType == HeaderGeomType::Area)
{
if (m_triangles.empty())
{

View file

@ -131,7 +131,7 @@ private:
namespace feature
{
uint8_t CalculateHeader(size_t const typesCount, EHeaderTypeMask const headerGeomType,
uint8_t CalculateHeader(size_t const typesCount, HeaderGeomType const headerGeomType,
FeatureParamsBase const & params)
{
ASSERT(typesCount != 0, ("Feature should have at least one type."));
@ -143,21 +143,21 @@ uint8_t CalculateHeader(size_t const typesCount, EHeaderTypeMask const headerGeo
if (params.layer != 0)
header |= HEADER_HAS_LAYER;
header |= headerGeomType;
header |= static_cast<uint8_t>(headerGeomType);
// Geometry type for additional info is only one.
switch (headerGeomType)
{
case HEADER_GEOM_POINT:
case HeaderGeomType::Point:
if (params.rank != 0)
header |= HEADER_HAS_ADDINFO;
break;
case HEADER_GEOM_LINE:
case HeaderGeomType::Line:
if (!params.ref.empty())
header |= HEADER_HAS_ADDINFO;
break;
case HEADER_GEOM_AREA:
case HEADER_GEOM_POINT_EX:
case HeaderGeomType::Area:
case HeaderGeomType::PointEx:
if (!params.house.IsEmpty())
header |= HEADER_HAS_ADDINFO;
break;
@ -385,35 +385,36 @@ void FeatureParams::SetGeomType(feature::EGeomType t)
{
switch (t)
{
case GEOM_POINT: m_geomType = HEADER_GEOM_POINT; break;
case GEOM_LINE: m_geomType = HEADER_GEOM_LINE; break;
case GEOM_AREA: m_geomType = HEADER_GEOM_AREA; break;
case GEOM_POINT: m_geomType = HeaderGeomType::Point; break;
case GEOM_LINE: m_geomType = HeaderGeomType::Line; break;
case GEOM_AREA: m_geomType = HeaderGeomType::Area; break;
default: ASSERT(false, ());
}
}
void FeatureParams::SetGeomTypePointEx()
{
ASSERT(m_geomType == HEADER_GEOM_POINT || m_geomType == HEADER_GEOM_POINT_EX, ());
ASSERT(m_geomType == HeaderGeomType::Point ||
m_geomType == HeaderGeomType::PointEx, ());
ASSERT(!house.IsEmpty(), ());
m_geomType = HEADER_GEOM_POINT_EX;
m_geomType = HeaderGeomType::PointEx;
}
feature::EGeomType FeatureParams::GetGeomType() const
{
CHECK_NOT_EQUAL(m_geomType, 0xFF, ());
CheckValid();
switch (m_geomType)
{
case HEADER_GEOM_LINE: return GEOM_LINE;
case HEADER_GEOM_AREA: return GEOM_AREA;
case HeaderGeomType::Line: return GEOM_LINE;
case HeaderGeomType::Area: return GEOM_AREA;
default: return GEOM_POINT;
}
}
uint8_t FeatureParams::GetTypeMask() const
HeaderGeomType FeatureParams::GetHeaderGeomType() const
{
CHECK_NOT_EQUAL(m_geomType, 0xFF, ());
CheckValid();
return m_geomType;
}
@ -555,14 +556,13 @@ uint32_t FeatureParams::FindType(uint32_t comp, uint8_t level) const
bool FeatureParams::CheckValid() const
{
CHECK(!m_types.empty() && m_types.size() <= kMaxTypesCount, ());
CHECK_NOT_EQUAL(m_geomType, 0xFF, ());
return FeatureParamsBase::CheckValid();
}
uint8_t FeatureParams::GetHeader() const
{
return CalculateHeader(m_types.size(), static_cast<EHeaderTypeMask>(GetTypeMask()), *this);
return CalculateHeader(m_types.size(), GetHeaderGeomType(), *this);
}
uint32_t FeatureParams::GetIndexForType(uint32_t t)

View file

@ -11,6 +11,7 @@
#include <algorithm>
#include <array>
#include <cstdint>
#include <iterator>
#include <string>
#include <utility>
@ -30,13 +31,13 @@ namespace feature
HEADER_HAS_ADDINFO = 1U << 7
};
enum EHeaderTypeMask
enum class HeaderGeomType : uint8_t
{
/// Coding geometry feature type in 2 bits.
HEADER_GEOM_POINT = 0, /// point feature (addinfo = rank)
HEADER_GEOM_LINE = 1U << 5, /// linear feature (addinfo = ref)
HEADER_GEOM_AREA = 1U << 6, /// area feature (addinfo = house)
HEADER_GEOM_POINT_EX = 3U << 5 /// point feature (addinfo = house)
Point = 0, /// point feature (addinfo = rank)
Line = 1U << 5, /// linear feature (addinfo = ref)
Area = 1U << 6, /// area feature (addinfo = house)
PointEx = 3U << 5 /// point feature (addinfo = house)
};
static constexpr int kMaxTypesCount = HEADER_TYPE_MASK + 1;
@ -126,7 +127,7 @@ namespace feature
std::string DebugPrint(TypesHolder const & holder);
uint8_t CalculateHeader(size_t const typesCount, EHeaderTypeMask const headerGeomType,
uint8_t CalculateHeader(size_t const typesCount, HeaderGeomType const headerGeomType,
FeatureParamsBase const & params);
} // namespace feature
@ -164,16 +165,17 @@ struct FeatureParamsBase
if (header & HEADER_HAS_ADDINFO)
{
switch (header & HEADER_GEOTYPE_MASK)
auto const headerGeomType = static_cast<HeaderGeomType>(header & HEADER_GEOTYPE_MASK);
switch (headerGeomType)
{
case HEADER_GEOM_POINT:
case HeaderGeomType::Point:
WriteToSink(sink, rank);
break;
case HEADER_GEOM_LINE:
case HeaderGeomType::Line:
utils::WriteString(sink, ref);
break;
case HEADER_GEOM_AREA:
case HEADER_GEOM_POINT_EX:
case HeaderGeomType::Area:
case HeaderGeomType::PointEx:
house.Write(sink);
break;
}
@ -193,16 +195,17 @@ struct FeatureParamsBase
if (header & HEADER_HAS_ADDINFO)
{
switch (header & HEADER_GEOTYPE_MASK)
auto const headerGeomType = static_cast<HeaderGeomType>(header & HEADER_GEOTYPE_MASK);
switch (headerGeomType)
{
case HEADER_GEOM_POINT:
case HeaderGeomType::Point:
rank = ReadPrimitiveFromSource<uint8_t>(src);
break;
case HEADER_GEOM_LINE:
case HeaderGeomType::Line:
utils::ReadString(src, ref);
break;
case HEADER_GEOM_AREA:
case HEADER_GEOM_POINT_EX:
case HeaderGeomType::Area:
case HeaderGeomType::PointEx:
house.Read(src);
break;
}
@ -214,7 +217,7 @@ class FeatureParams : public FeatureParamsBase
{
using Base = FeatureParamsBase;
uint8_t m_geomType;
feature::HeaderGeomType m_geomType = feature::HeaderGeomType::Point;
feature::Metadata m_metadata;
feature::AddressData m_addrTags;
@ -225,7 +228,7 @@ public:
bool m_reverseGeometry;
FeatureParams() : m_geomType(0xFF), m_reverseGeometry(false) {}
FeatureParams() : m_reverseGeometry(false) {}
void ClearName();
@ -317,7 +320,7 @@ public:
using namespace feature;
uint8_t const header = ReadPrimitiveFromSource<uint8_t>(src);
m_geomType = header & HEADER_GEOTYPE_MASK;
m_geomType = static_cast<feature::HeaderGeomType>(header & HEADER_GEOTYPE_MASK);
size_t const count = (header & HEADER_TYPE_MASK) + 1;
for (size_t i = 0; i < count; ++i)
@ -330,7 +333,7 @@ public:
}
private:
uint8_t GetTypeMask() const;
feature::HeaderGeomType GetHeaderGeomType() const;
static uint32_t GetIndexForType(uint32_t t);
static uint32_t GetTypeForIndex(uint32_t i);