blob: 0f14909047541a0c8a4869897010322ea5e21715 (
plain)
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
|
#include "countries.hpp"
#include "simple_tree.hpp"
#include "../base/string_utils.hpp"
#include "../geometry/cellid.hpp"
#include "../std/iostream.hpp"
typedef m2::CellId<9> CountryCellId;
namespace mapinfo
{
void CountryTreeNode::AddCellId(string const & cellId)
{
CountryCellId id = CountryCellId::FromString(cellId);
m_ids.push_back(static_cast<uint16_t>(id.ToBitsAndLevel().first));
ASSERT_EQUAL(CountryCellId::FromBitsAndLevel(m_ids.back(), 8).ToString(), cellId, ());
}
bool LoadCountries(SimpleTree<CountryTreeNode> & tree, std::istream & stream)
{
std::string line;
CountryTreeNode * value = &tree.Value();
while (stream.good())
{
std::getline(stream, line);
if (line.empty())
continue;
// calculate spaces - depth inside the tree
int spaces = 0;
for (size_t i = 0; i < line.size(); ++i)
{
if (line[i] == ' ')
++spaces;
else
break;
}
switch (spaces)
{
case 0: // this is value for current node
value->AddCellId(line);;
break;
case 1: // country group
case 2: // country name
case 3: // region
value = &tree.AddAtDepth(spaces - 1, CountryTreeNode(line.substr(spaces)));
break;
default:
return false;
}
}
return true;
}
}
|