-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathregioncontrol.cpp
More file actions
119 lines (79 loc) · 1.75 KB
/
regioncontrol.cpp
File metadata and controls
119 lines (79 loc) · 1.75 KB
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
#include "regioncontrol.h"
#include "ext/ZFile.h"
bool RegionControl::OpenFile(const GString &name)
{
ZFile zfo;
if (!zfo.Open(name,EZFOpenMode::BinaryRead))
return false;
zfo >> Countries;
zfo.Close();
if (!Countries.size())
return false;
// Fill out regions
for (Country& cn : Countries){
Regions.reserve(Regions.size() + cn.Regions.size());
for (Region& rgc : cn.Regions){
Reg ar;
ar.id = rgc.id;ar.name = rgc.name;
ar.ownerid = cn.id;
Regions.push_back(ar);
}
}
return true;
}
bool RegionControl::SaveFile(const GString &outname)
{
ZFile zfs;
if (!zfs.Open(outname,EZFOpenMode::BinaryWrite))
return false;
zfs << Countries;
zfs.Close();
return true;
}
void RegionControl::SetCountries(std::vector<Country> &cts)
{
Countries = cts;
}
GString RegionControl::GetOwnerName(Reg &ro)
{
return GetCountryName(ro.id);
}
GString RegionControl::GetCountryName(int cid)
{
for (Country& ctr : Countries){
if (ctr.id == cid)
return ctr.name;
}
return L"";
}
RegionControl::RegionControl()
{
}
ZFile &operator<<(ZFile &right, const Region ®)
{
right << reg.id;
right << reg.name;
return right;
}
ZFile &operator<<(ZFile &right, const Country &cnt)
{
right << cnt.id;
right << cnt.name;
right << cnt.Regions;
right << cnt.code;
return right;
}
ZFile &operator>>(ZFile &right, Country &cr)
{
right >> cr.id;
right >> cr.name;
right >> cr.Regions;
right >> cr.code;
return right;
}
ZFile &operator>>(ZFile &right, Region ®)
{
right >> reg.id;
right >> reg.name;
return right;
}