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
|
#include "indexer/data_header.hpp"
#include "indexer/point_to_int64.hpp"
#include "indexer/scales.hpp"
#include "defines.hpp"
#include "coding/file_reader.hpp"
#include "coding/file_writer.hpp"
#include "coding/file_container.hpp"
#include "coding/write_to_sink.hpp"
#include "coding/varint.hpp"
namespace feature
{
serial::CodingParams DataHeader::GetCodingParams(int scaleIndex) const
{
return serial::CodingParams(m_codingParams.GetCoordBits() -
(m_scales.back() - m_scales[scaleIndex]) / 2,
m_codingParams.GetBasePointUint64());
}
m2::RectD const DataHeader::GetBounds() const
{
return Int64ToRect(m_bounds, m_codingParams.GetCoordBits());
}
void DataHeader::SetBounds(m2::RectD const & r)
{
m_bounds = RectToInt64(r, m_codingParams.GetCoordBits());
}
pair<int, int> DataHeader::GetScaleRange() const
{
using namespace scales;
int const low = 0;
int const high = GetUpperScale();
int const worldH = GetUpperWorldScale();
MapType const type = GetType();
switch (type)
{
case world: return make_pair(low, worldH);
case worldcoasts: return make_pair(low, high);
default:
ASSERT_EQUAL(type, country, ());
return make_pair(worldH + 1, high);
// Uncomment this to test countries drawing in all scales.
//return make_pair(1, high);
}
}
namespace
{
template <class TSink, class TCont>
void SaveBytes(TSink & sink, TCont const & cont)
{
static_assert(sizeof(typename TCont::value_type) == 1, "");
uint32_t const count = static_cast<uint32_t>(cont.size());
WriteVarUint(sink, count);
if (count > 0)
sink.Write(&cont[0], count);
}
template <class TSource, class TCont>
void LoadBytes(TSource & src, TCont & cont)
{
static_assert(sizeof(typename TCont::value_type) == 1, "");
ASSERT ( cont.empty(), () );
uint32_t const count = ReadVarUint<uint32_t>(src);
if (count > 0)
{
cont.resize(count);
src.Read(&cont[0], count);
}
}
}
void DataHeader::Save(FileWriter & w) const
{
m_codingParams.Save(w);
WriteVarInt(w, m_bounds.first);
WriteVarInt(w, m_bounds.second);
SaveBytes(w, m_scales);
SaveBytes(w, m_langs);
WriteVarInt(w, static_cast<int32_t>(m_type));
}
void DataHeader::Load(ModelReaderPtr const & r, version::Format format /* = version::lastFormat */)
{
ReaderSource<ModelReaderPtr> src(r);
m_codingParams.Load(src);
m_bounds.first = ReadVarInt<int64_t>(src);
m_bounds.second = ReadVarInt<int64_t>(src);
LoadBytes(src, m_scales);
LoadBytes(src, m_langs);
m_type = static_cast<MapType>(ReadVarInt<int32_t>(src));
m_format = format;
if (!IsMWMSuitable())
{
// Actually, old versions of the app should read mwm header correct!
// This condition is also checked in adding mwm to the model.
return;
}
// Place all new serializable staff here.
}
void DataHeader::LoadV1(ModelReaderPtr const & r)
{
ReaderSource<ModelReaderPtr> src(r);
int64_t const base = ReadPrimitiveFromSource<int64_t>(src);
m_codingParams = serial::CodingParams(POINT_COORD_BITS, base);
m_bounds.first = ReadVarInt<int64_t>(src) + base;
m_bounds.second = ReadVarInt<int64_t>(src) + base;
uint32_t const count = 4;
m_scales.resize(count);
src.Read(m_scales.data(), count);
m_type = country;
m_format = version::v1;
}
}
|