libosmscout  1.1.1
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 
33 namespace 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  inline explicit MagnificationLevel(uint32_t level) noexcept
44  : level(level)
45  {
46  }
47 
48  MagnificationLevel(const MagnificationLevel& level) = default;
49 
50  inline uint32_t Get() const
51  {
52  return level;
53  }
54 
55  MagnificationLevel& operator=(const MagnificationLevel& other) = default;
56 
57  inline MagnificationLevel& operator++()
58  {
59  ++level;
60 
61  return *this;
62  }
63 
64  inline MagnificationLevel operator++(int)
65  {
66  ++level;
67 
68  return *this;
69  }
70 
71  inline MagnificationLevel& operator+=(uint32_t increment)
72  {
73  level+=increment;
74 
75  return *this;
76  }
77 
78  inline bool operator==(const MagnificationLevel& other) const
79  {
80  return level==other.level;
81  }
82 
83  inline bool operator!=(const MagnificationLevel& other) const
84  {
85  return level!=other.level;
86  }
87 
88  inline bool operator<(const MagnificationLevel& other) const
89  {
90  return level<other.level;
91  }
92 
93  inline bool operator<=(const MagnificationLevel& other) const
94  {
95  return level<=other.level;
96  }
97 
98  inline bool operator>=(const MagnificationLevel& other) const
99  {
100  return level>=other.level;
101  }
102 
103  inline 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 
130 namespace 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 
141 namespace osmscout {
142  class OSMSCOUT_API Magnification CLASS_FINAL
143  {
144  public:
145  static MagnificationLevel magWorld; // 0
146  static MagnificationLevel magContinent; // 4
147  static MagnificationLevel magState; // 5
148  static MagnificationLevel magStateOver; // 6
149  static MagnificationLevel magCounty; // 7
150  static MagnificationLevel magRegion; // 8
151  static MagnificationLevel magProximity; // 9
152  static MagnificationLevel magCityOver; // 10
153  static MagnificationLevel magCity; // 11
154  static MagnificationLevel magSuburb; // 12
155  static MagnificationLevel magDetail; // 13
156  static MagnificationLevel magClose; // 14
157  static MagnificationLevel magCloser; // 15
158  static MagnificationLevel magVeryClose; // 16
159  static MagnificationLevel magBlock; // 18
160  static MagnificationLevel magStreet; // 19
161  static MagnificationLevel magHouse; // 20
162 
163  private:
164  double magnification=1;
165  uint32_t level=0;
166 
167  public:
168  Magnification() = default;
169  ~Magnification() = default;
170 
171  Magnification(const Magnification& other) = default;
172 
177  inline explicit Magnification(double magnification) noexcept
178  {
179  SetMagnification(magnification);
180  }
181 
182  inline explicit Magnification(const MagnificationLevel& level) noexcept
183  {
184  SetLevel(level);
185  }
186 
191  void SetMagnification(double magnification);
192 
193  void SetLevel(const MagnificationLevel& level);
194 
195  inline double GetMagnification() const
196  {
197  return magnification;
198  }
199 
200  inline uint32_t GetLevel() const
201  {
202  return level;
203  }
204 
205  inline Magnification& operator=(const Magnification& other)
206  {
207  if (this!=&other) {
208  this->magnification=other.magnification;
209  this->level=other.level;
210  }
211 
212  return *this;
213  }
214 
215  inline bool operator==(const Magnification& other) const
216  {
217  return magnification==other.magnification;
218  }
219 
220  inline bool operator!=(const Magnification& other) const
221  {
222  return magnification!=other.magnification;
223  }
224 
225  inline bool operator<(const Magnification& other) const
226  {
227  return magnification<other.magnification;
228  }
229 
230  inline bool operator<=(const Magnification& other) const
231  {
232  return magnification<=other.magnification;
233  }
234 
235  inline bool operator>=(const Magnification& other) const
236  {
237  return magnification>=other.magnification;
238  }
239 
240  inline bool operator>(const Magnification& other) const
241  {
242  return magnification>other.magnification;
243  }
244 
245  inline Magnification& operator++()
246  {
247  magnification*=2.0;
248  level+=1;
249 
250  return *this;
251  }
252 
253  inline Magnification operator++(int)
254  {
255  magnification*=2.0;
256  level+=1;
257 
258  return *this;
259  }
260  };
261 
263  {
264  private:
265  std::unordered_map<std::string,MagnificationLevel> stringToMagMap;
266  std::unordered_map<MagnificationLevel,std::string> levelToStringMap;
267 
268  public:
270 
271  bool Convert(const std::string& name,
272  Magnification& magnification);
273 
274  bool Convert(const MagnificationLevel& level,
275  std::string& name);
276  };
277 }
278 
279 #endif
static MagnificationLevel magCloser
Definition: Magnification.h:157
static MagnificationLevel magCity
Definition: Magnification.h:153
static MagnificationLevel magClose
Definition: Magnification.h:156
Magnification operator++(int)
Definition: Magnification.h:253
static MagnificationLevel magHouse
Definition: Magnification.h:161
size_t operator()(const osmscout::MagnificationLevel &level) const
Definition: Magnification.h:134
uint32_t GetLevel() const
Definition: Magnification.h:200
static MagnificationLevel magCityOver
Definition: Magnification.h:152
Magnification & operator++()
Definition: Magnification.h:245
static MagnificationLevel magState
Definition: Magnification.h:147
STL namespace.
std::ostream & operator<<(std::ostream &stream, const DBId &o)
Definition: DBFileOffset.h:80
bool operator!=(const Magnification &other) const
Definition: Magnification.h:220
bool operator>(const MagnificationLevel &other) const
Definition: Magnification.h:103
bool operator<=(const MagnificationLevel &other) const
Definition: Magnification.h:93
bool operator<(const MagnificationLevel &other) const
Definition: Magnification.h:88
static MagnificationLevel magCounty
Definition: Magnification.h:149
static MagnificationLevel magStateOver
Definition: Magnification.h:148
static MagnificationLevel magRegion
Definition: Magnification.h:150
MagnificationLevel(uint32_t level) noexcept
Definition: Magnification.h:43
Definition: Area.h:38
#define CLASS_FINAL
Definition: Compiler.h:26
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
bool operator<=(const Magnification &other) const
Definition: Magnification.h:230
bool operator>(const Magnification &other) const
Definition: Magnification.h:240
bool operator>=(const MagnificationLevel &other) const
Definition: Magnification.h:98
static MagnificationLevel magContinent
Definition: Magnification.h:146
MagnificationLevel operator++(int)
Definition: Magnification.h:64
bool operator>=(const Magnification &other) const
Definition: Magnification.h:235
double GetMagnification() const
Definition: Magnification.h:195
static MagnificationLevel magWorld
Definition: Magnification.h:145
static MagnificationLevel magVeryClose
Definition: Magnification.h:158
static MagnificationLevel magStreet
Definition: Magnification.h:160
static MagnificationLevel magBlock
Definition: Magnification.h:159
Magnification(double magnification) noexcept
Definition: Magnification.h:177
std::string operator+(const char *text, const MagnificationLevel &level)
Definition: Magnification.h:117
bool operator==(const Magnification &other) const
Definition: Magnification.h:215
bool operator!=(const MagnificationLevel &other) const
Definition: Magnification.h:83
Definition: Magnification.h:262
uint32_t Get() const
Definition: Magnification.h:50
MagnificationLevel & operator++()
Definition: Magnification.h:57
Magnification(const MagnificationLevel &level) noexcept
Definition: Magnification.h:182
Magnification & operator=(const Magnification &other)
Definition: Magnification.h:205
bool operator<(const Magnification &other) const
Definition: Magnification.h:225
static MagnificationLevel magProximity
Definition: Magnification.h:151
MagnificationLevel & operator+=(uint32_t increment)
Definition: Magnification.h:71
static MagnificationLevel magDetail
Definition: Magnification.h:155
static MagnificationLevel magSuburb
Definition: Magnification.h:154
bool operator==(const MagnificationLevel &other) const
Definition: Magnification.h:78