1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
#include "feature_data.hpp"
#include "classificator.hpp"
#include "feature.hpp"
#include "../std/algorithm.hpp"
using namespace feature;
TypesHolder::TypesHolder(FeatureBase const & f)
: m_size(0), m_geoType(f.GetFeatureType())
{
f.ForEachTypeRef(*this);
}
string TypesHolder::DebugPrint() const
{
Classificator const & c = classif();
string s;
for (size_t i = 0; i < Size(); ++i)
s += c.GetFullObjectName(m_types[i]) + " ";
return s;
}
void TypesHolder::Remove(uint32_t t)
{
if (m_size > 0)
{
uint32_t * e = m_types + m_size;
if (std::remove(m_types, e, t) != e)
--m_size;
}
}
void FeatureParamsBase::MakeZero()
{
layer = 0;
rank = 0;
ref.clear();
house.Clear();
name.Clear();
}
bool FeatureParamsBase::operator == (FeatureParamsBase const & rhs) const
{
return (name == rhs.name && house == rhs.house && ref == rhs.ref &&
layer == rhs.layer && rank == rhs.rank);
}
bool FeatureParamsBase::CheckValid() const
{
CHECK(layer > LAYER_LOW && layer < LAYER_HIGH, ());
return true;
}
string FeatureParamsBase::DebugString() const
{
string utf8name;
name.GetString(0, utf8name);
return ("'" + utf8name + "' Layer:" + DebugPrint(layer) +
(rank != 0 ? " Rank:" + DebugPrint(rank) : "") +
(!house.IsEmpty() ? " House:" + house.Get() : "") +
(!ref.empty() ? " Ref:" + ref : "") + " ");
}
void FeatureParamsBase::AddHouseName(string const & s)
{
house.Set(house.IsEmpty() ? s : house.Get() + " \"" + s + "\"");
}
void FeatureParamsBase::AddHouseNumber(string const & s)
{
house.Set(house.IsEmpty() ? s : s + " \"" + house.Get() + "\"");
}
feature::EGeomType FeatureParams::GetGeomType() const
{
// Geometry types can be combined.
// We define exact type for priority : starting from GEOM_AREA.
if (m_geomTypes[GEOM_AREA]) return GEOM_AREA;
if (m_geomTypes[GEOM_LINE]) return GEOM_LINE;
if (m_geomTypes[GEOM_POINT]) return GEOM_POINT;
return GEOM_UNDEFINED;
}
uint8_t FeatureParams::GetTypeMask() const
{
uint8_t h = 0;
if (m_geomTypes[GEOM_POINT]) h |= HEADER_GEOM_POINT;
if (m_geomTypes[GEOM_LINE]) h |= HEADER_GEOM_LINE;
if (m_geomTypes[GEOM_AREA]) h |= HEADER_GEOM_AREA;
return h;
}
void FeatureParams::AddTypes(FeatureParams const & rhs, uint32_t skipType2)
{
if (skipType2 == 0)
{
m_Types.insert(m_Types.end(), rhs.m_Types.begin(), rhs.m_Types.end());
}
else
{
for (size_t i = 0; i < rhs.m_Types.size(); ++i)
{
uint32_t t = rhs.m_Types[i];
ftype::TruncValue(t, 2);
if (t != skipType2)
m_Types.push_back(rhs.m_Types[i]);
}
}
}
void FeatureParams::FinishAddingTypes()
{
sort(m_Types.begin(), m_Types.end());
m_Types.erase(unique(m_Types.begin(), m_Types.end()), m_Types.end());
if (m_Types.size() > max_types_count)
m_Types.resize(max_types_count);
}
void FeatureParams::SetType(uint32_t t)
{
m_Types.clear();
m_Types.push_back(t);
}
bool FeatureParams::PopAnyType(uint32_t & t)
{
t = m_Types.back();
m_Types.pop_back();
return m_Types.empty();
}
bool FeatureParams::PopExactType(uint32_t t)
{
m_Types.erase(remove(m_Types.begin(), m_Types.end(), t), m_Types.end());
return m_Types.empty();
}
bool FeatureParams::IsTypeExist(uint32_t t) const
{
return (find(m_Types.begin(), m_Types.end(), t) != m_Types.end());
}
bool FeatureParams::operator == (FeatureParams const & rhs) const
{
return (FeatureParamsBase::operator ==(rhs) &&
m_Types == rhs.m_Types &&
GetGeomType() == rhs.GetGeomType());
}
bool FeatureParams::CheckValid() const
{
CHECK(!m_Types.empty() && m_Types.size() <= max_types_count, ());
CHECK(GetGeomType() != GEOM_UNDEFINED, ());
return FeatureParamsBase::CheckValid();
}
uint8_t FeatureParams::GetHeader() const
{
uint8_t header = static_cast<uint8_t>(m_Types.size() - 1);
if (!name.IsEmpty())
header |= HEADER_HAS_NAME;
if (layer != 0)
header |= HEADER_HAS_LAYER;
header |= GetTypeMask();
// Geometry type for additional info is only one.
switch (GetGeomType())
{
case GEOM_POINT: if (rank != 0) header |= HEADER_HAS_ADDINFO; break;
case GEOM_LINE: if (!ref.empty()) header |= HEADER_HAS_ADDINFO; break;
case GEOM_AREA: if (!house.IsEmpty()) header |= HEADER_HAS_ADDINFO; break;
default:
ASSERT(false, ("Undefined geometry type"));
}
return header;
}
uint32_t FeatureParams::GetIndexForType(uint32_t t)
{
return classif().GetIndexForType(t);
}
uint32_t FeatureParams::GetTypeForIndex(uint32_t i)
{
return classif().GetTypeForIndex(i);
}
string DebugPrint(FeatureParams const & p)
{
ostringstream out;
out << "Types: ";
for (size_t i = 0; i < p.m_Types.size(); ++i)
out << p.m_Types[i] << "; ";
return out.str();
}
|