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
|
#pragma once
#include "storage/storage_defines.hpp"
#include "storage/simple_tree.hpp"
#include "storage/country_decl.hpp"
#include "defines.hpp"
#include "geometry/rect2d.hpp"
#include "base/buffer_vector.hpp"
#include "std/string.hpp"
#include "std/vector.hpp"
namespace update { class SizeUpdater; }
namespace storage
{
/// Information about each file for a country
class CountryFile
{
string m_fileName; /// Same as id of country\region.
uint32_t m_mapSize, m_routingSize;
public:
CountryFile() : m_mapSize(0), m_routingSize(0) {}
CountryFile(string const & fName, uint32_t mapSize, uint32_t routingSize)
: m_fileName(fName), m_mapSize(mapSize), m_routingSize(routingSize)
{
}
void AssignSizes(uint32_t mapSize, uint32_t routingSize)
{
m_mapSize = mapSize;
m_routingSize = routingSize;
}
string GetFileWithExt(TMapOptions opt) const;
string const & GetFileWithoutExt() const { return m_fileName; }
uint32_t GetFileSize(TMapOptions opt) const;
uint32_t GetRemoteSize(TMapOptions opt) const;
};
typedef buffer_vector<CountryFile, 1> FilesContainerT;
/// Serves as a proxy between GUI and downloaded files
class Country
{
friend class update::SizeUpdater;
/// Name in the country node tree
string m_name;
/// Flag to display
string m_flag;
/// stores squares with world pieces which are part of the country
FilesContainerT m_files;
public:
Country() {}
Country(string const & name, string const & flag = "")
: m_name(name), m_flag(flag) {}
bool operator<(Country const & other) const { return Name() < other.Name(); }
void AddFile(CountryFile const & file);
size_t GetFilesCount() const { return m_files.size(); }
/*
template <class ToDo> void ForEachFile(ToDo toDo) const
{
for (FilesContainerT::const_iterator i = m_files.begin(); i != m_files.end(); ++i)
toDo(i->GetFileWithExt());
}
*/
/// This function valid for current logic - one file for one country (region).
/// If the logic will be changed, replace GetFile with ForEachFile.
CountryFile const & GetFile() const
{
ASSERT_EQUAL ( m_files.size(), 1, (m_name) );
return m_files.front();
}
string const & Name() const { return m_name; }
string const & Flag() const { return m_flag; }
/// @return bounds for downloaded parts of the country or empty rect
//m2::RectD Bounds() const;
LocalAndRemoteSizeT Size(TMapOptions opt) const;
};
typedef SimpleTree<Country> CountriesContainerT;
/// @return version of country file or -1 if error was encountered
int64_t LoadCountries(string const & jsonBuffer, CountriesContainerT & countries);
void LoadCountryFile2CountryInfo(string const & jsonBuffer, map<string, CountryInfo> & id2info);
void LoadCountryCode2File(string const & jsonBuffer, multimap<string, string> & code2file);
bool SaveCountries(int64_t version, CountriesContainerT const & countries, string & jsonBuffer);
}
|