libosmscout 1.1.1
Loading...
Searching...
No Matches
Magnification.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_UTIL_MAGNIFICATION_H
2#define OSMSCOUT_UTIL_MAGNIFICATION_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2012 Tim Teulings
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
24
25#include <functional>
26#include <ostream>
27#include <string>
28#include <unordered_map>
29
32
33namespace osmscout {
34
35 class OSMSCOUT_API MagnificationLevel CLASS_FINAL
36 {
37 private:
38 uint32_t level = 0;
39
40 public:
41 MagnificationLevel() = default;
42
43 explicit MagnificationLevel(uint32_t level) noexcept
44 : level(level)
45 {
46 }
47
48 MagnificationLevel(const MagnificationLevel& level) = default;
49
50 uint32_t Get() const
51 {
52 return level;
53 }
54
56
58 {
59 ++level;
60
61 return *this;
62 }
63
65 {
66 ++level;
67
68 return *this;
69 }
70
71 MagnificationLevel& operator+=(uint32_t increment)
72 {
73 level+=increment;
74
75 return *this;
76 }
77
78 bool operator==(const MagnificationLevel& other) const
79 {
80 return level==other.level;
81 }
82
83 bool operator!=(const MagnificationLevel& other) const
84 {
85 return level!=other.level;
86 }
87
88 bool operator<(const MagnificationLevel& other) const
89 {
90 return level<other.level;
91 }
92
93 bool operator<=(const MagnificationLevel& other) const
94 {
95 return level<=other.level;
96 }
97
98 bool operator>=(const MagnificationLevel& other) const
99 {
100 return level>=other.level;
101 }
102
103 bool operator>(const MagnificationLevel& other) const
104 {
105 return level>other.level;
106 }
107 };
108
109 inline std::ostream& operator<<(std::ostream& os,
110 const MagnificationLevel& level)
111 {
112 os << level.Get();
113
114 return os;
115 }
116
117 inline std::string operator+(const char* text,
118 const MagnificationLevel& level)
119 {
120 return std::string(text)+std::to_string(level.Get());
121 }
122
123 inline std::string operator+(const std::string& text,
124 const MagnificationLevel& level)
125 {
126 return text+std::to_string(level.Get());
127 }
128}
129
130namespace std {
131 template <>
132 struct hash<osmscout::MagnificationLevel>
133 {
134 size_t operator()(const osmscout::MagnificationLevel& level) const
135 {
136 return hash<uint32_t>{}(level.Get());
137 }
138 };
139}
140
141namespace osmscout {
142 class OSMSCOUT_API Magnification CLASS_FINAL
143 {
144 public:
162
163 private:
164 double magnification=1;
165 uint32_t level=0;
166
167 public:
168 Magnification() = default;
169
174 explicit Magnification(double magnification) noexcept
175 {
176 SetMagnification(magnification);
177 }
178
179 explicit Magnification(const MagnificationLevel& level) noexcept
180 {
181 SetLevel(level);
182 }
183
188 void SetMagnification(double magnification);
189
190 void SetLevel(const MagnificationLevel& level);
191
192 double GetMagnification() const
193 {
194 return magnification;
195 }
196
197 uint32_t GetLevel() const
198 {
199 return level;
200 }
201
202 bool operator==(const Magnification& other) const
203 {
204 return magnification==other.magnification;
205 }
206
207 bool operator!=(const Magnification& other) const
208 {
209 return magnification!=other.magnification;
210 }
211
212 bool operator<(const Magnification& other) const
213 {
214 return magnification<other.magnification;
215 }
216
217 bool operator<=(const Magnification& other) const
218 {
219 return magnification<=other.magnification;
220 }
221
222 bool operator>=(const Magnification& other) const
223 {
224 return magnification>=other.magnification;
225 }
226
227 bool operator>(const Magnification& other) const
228 {
229 return magnification>other.magnification;
230 }
231
233 {
234 magnification*=2.0;
235 level+=1;
236
237 return *this;
238 }
239
241 {
242 magnification*=2.0;
243 level+=1;
244
245 return *this;
246 }
247 };
248
250 {
251 private:
252 std::unordered_map<std::string,MagnificationLevel> stringToMagMap;
253 std::unordered_map<MagnificationLevel,std::string> levelToStringMap;
254
255 public:
257
258 bool Convert(const std::string& name,
259 Magnification& magnification);
260
261 bool Convert(const MagnificationLevel& level,
262 std::string& name);
263 };
264}
265
266#endif
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Area.h:88
static MagnificationLevel magCloser
Definition Magnification.h:157
static MagnificationLevel magContinent
Definition Magnification.h:146
bool operator<(const Magnification &other) const
Definition Magnification.h:212
MagnificationLevel & operator=(const MagnificationLevel &other)=default
bool operator>(const Magnification &other) const
Definition Magnification.h:227
static MagnificationLevel magSuburb
Definition Magnification.h:154
static MagnificationLevel magState
Definition Magnification.h:147
static MagnificationLevel magCity
Definition Magnification.h:153
bool operator>=(const Magnification &other) const
Definition Magnification.h:222
uint32_t Get() const
Definition Magnification.h:50
bool operator>=(const MagnificationLevel &other) const
Definition Magnification.h:98
static MagnificationLevel magVeryClose
Definition Magnification.h:158
bool operator<=(const MagnificationLevel &other) const
Definition Magnification.h:93
bool operator!=(const MagnificationLevel &other) const
Definition Magnification.h:83
Magnification(double magnification) noexcept
Definition Magnification.h:174
void SetLevel(const MagnificationLevel &level)
static MagnificationLevel magDetail
Definition Magnification.h:155
bool operator>(const MagnificationLevel &other) const
Definition Magnification.h:103
static MagnificationLevel magBlock
Definition Magnification.h:159
bool operator<(const MagnificationLevel &other) const
Definition Magnification.h:88
static MagnificationLevel magClose
Definition Magnification.h:156
MagnificationLevel & operator++()
Definition Magnification.h:57
uint32_t GetLevel() const
Definition Magnification.h:197
MagnificationLevel & operator+=(uint32_t increment)
Definition Magnification.h:71
static MagnificationLevel magHouse
Definition Magnification.h:161
bool operator==(const MagnificationLevel &other) const
Definition Magnification.h:78
double GetMagnification() const
Definition Magnification.h:192
static MagnificationLevel magRegion
Definition Magnification.h:150
bool operator==(const Magnification &other) const
Definition Magnification.h:202
bool operator!=(const Magnification &other) const
Definition Magnification.h:207
static MagnificationLevel magProximity
Definition Magnification.h:151
Magnification(const MagnificationLevel &level) noexcept
Definition Magnification.h:179
static MagnificationLevel magWorld
Definition Magnification.h:145
void SetMagnification(double magnification)
static MagnificationLevel magCounty
Definition Magnification.h:149
MagnificationLevel()=default
Magnification operator++(int)
Definition Magnification.h:240
static MagnificationLevel magStateOver
Definition Magnification.h:148
Magnification & operator++()
Definition Magnification.h:232
bool operator<=(const Magnification &other) const
Definition Magnification.h:217
static MagnificationLevel magStreet
Definition Magnification.h:160
MagnificationLevel(uint32_t level) noexcept
Definition Magnification.h:43
static MagnificationLevel magCityOver
Definition Magnification.h:152
MagnificationLevel(const MagnificationLevel &level)=default
MagnificationLevel operator++(int)
Definition Magnification.h:64
bool Convert(const std::string &name, Magnification &magnification)
bool Convert(const MagnificationLevel &level, std::string &name)
Definition Area.h:39
std::ostream & operator<<(std::ostream &stream, const DBId &o)
Definition DBFileOffset.h:80
OSMSCOUT_API Vertex2D operator+(const Vertex2D &a, const Vertex2D &b)
STL namespace.
size_t operator()(const osmscout::MagnificationLevel &level) const
Definition Magnification.h:134