libosmscout 1.1.1
Loading...
Searching...
No Matches
LocationIndex.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_LOCATIONINDEX_H
2#define OSMSCOUT_LOCATIONINDEX_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2009 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
23#include <list>
24#include <map>
25#include <memory>
26#include <set>
27#include <unordered_set>
28
30#include <osmscout/TypeConfig.h>
31
33
35
36namespace osmscout {
37
49 {
50 public:
51 static const char* const FILENAME_LOCATION_IDX;
52
57 std::shared_ptr<LocationIndex> index;
58 public:
59 explicit ScopeCacheCleaner(std::shared_ptr<LocationIndex> index):
60 index(std::move(index))
61 {}
62
67
69 if (index) {
70 index->FlushCache();
71 }
72 }
73 };
74
75 private:
76
89 class FileScannerPool: public ObjectPool<FileScanner>
90 {
91 public:
92 std::string path;
93 bool memoryMappedData=false;
94 public:
95 FileScannerPool():
96 ObjectPool<FileScanner>(4) // 4 should be enough for recursive visitors
97 {}
98
99 ~FileScannerPool() override {
100 Clear(); // we have Close method override...
101 }
102
103 Ptr Borrow() override;
104
105 FileScanner* MakeNew() noexcept override;
106
107 void Destroy(FileScanner*) noexcept override;
108
109 bool IsValid(FileScanner* o) noexcept override;
110 };
111
112 using FileScannerPtr = FileScannerPool::Ptr;
113
114 private:
115 mutable FileScannerPool fileScannerPool;
116 uint8_t bytesForNodeFileOffset;
117 uint8_t bytesForAreaFileOffset;
118 uint8_t bytesForWayFileOffset;
119 std::vector<std::string> regionIgnoreTokens;
120 std::unordered_set<std::string> regionIgnoreTokenSet;
121 std::vector<std::string> poiIgnoreTokens;
122 std::unordered_set<std::string> poiIgnoreTokenSet;
123 std::vector<std::string> locationIgnoreTokens;
124 std::unordered_set<std::string> locationIgnoreTokenSet;
125 uint32_t minRegionChars;
126 uint32_t maxRegionChars;
127 uint32_t minRegionWords;
128 uint32_t maxRegionWords;
129 uint32_t maxPOIWords;
130 uint32_t minLocationChars;
131 uint32_t maxLocationChars;
132 uint32_t minLocationWords;
133 uint32_t maxLocationWords;
134 uint32_t maxAddressWords;
135 FileOffset indexOffset;
136
137 private:
138 void Read(FileScanner& scanner,
139 ObjectFileRef& object) const;
140
141 bool LoadAdminRegion(FileScanner& scanner,
142 AdminRegion& region) const;
143
144 AdminRegionVisitor::Action VisitRegionEntries(const AdminRegion& region,
145 FileScanner& scanner,
146 AdminRegionVisitor& visitor) const;
147
148 bool VisitRegionPOIs(const AdminRegion& region,
149 FileScanner& scanner,
150 POIVisitor& visitor,
151 bool recursive,
152 bool& stopped) const;
153
154 bool VisitPostalArea(const AdminRegion& adminRegion,
155 const PostalArea& postalArea,
156 FileScanner& scanner,
157 LocationVisitor& visitor,
158 bool recursive,
159 bool& stopped) const;
160
161 bool VisitLocations(const AdminRegion& adminRegion,
162 FileScanner& scanner,
163 LocationVisitor& visitor,
164 bool recursive,
165 bool& stopped) const;
166
167 bool VisitPostalAreaLocations(const AdminRegion& adminRegion,
168 const PostalArea& postalArea,
169 FileScanner& scanner,
170 LocationVisitor& visitor,
171 bool& stopped) const;
172
173 bool VisitLocation(FileScanner& scanner,
174 const AdminRegion& region,
175 const PostalArea& postalArea,
176 const Location& location,
177 AddressVisitor& visitor,
178 bool& stopped) const;
179
180 public:
181 LocationIndex() = default;
182 virtual ~LocationIndex() = default;
183
184 bool Load(const std::string& path, bool memoryMappedData);
185
186 const std::vector<std::string>& GetRegionIgnoreTokens() const
187 {
188 return regionIgnoreTokens;
189 }
190
191 const std::vector<std::string>& GetPOIIgnoreTokens() const
192 {
193 return poiIgnoreTokens;
194 }
195
196 const std::vector<std::string>& GetLocationIgnoreTokens() const
197 {
198 return locationIgnoreTokens;
199 }
200
201 bool IsRegionIgnoreToken(const std::string& token) const;
202 bool IsLocationIgnoreToken(const std::string& token) const;
203
204 uint32_t GetRegionMaxWords() const
205 {
206 return maxRegionWords;
207 }
208
209 uint32_t GetPOIMaxWords() const
210 {
211 return maxPOIWords;
212 }
213
214 uint32_t GetLocationMaxWords() const
215 {
216 return maxLocationWords;
217 }
218
219 uint32_t GetAddressMaxWords() const
220 {
221 return maxAddressWords;
222 }
223
228
232 bool VisitAdminRegions(const AdminRegion& adminRegion,
233 AdminRegionVisitor& visitor) const;
234
238 bool VisitPOIs(const AdminRegion& region,
239 POIVisitor& visitor,
240 bool recursive=true) const;
241
245 bool VisitLocations(const AdminRegion& adminRegion,
246 LocationVisitor& visitor,
247 bool recursive=true) const;
248
252 bool VisitLocations(const AdminRegion& adminRegion,
253 const PostalArea& postalArea,
254 LocationVisitor& visitor,
255 bool recursive=true) const;
256
260 bool VisitAddresses(const AdminRegion& region,
261 const PostalArea& postalArea,
262 const Location& location,
263 AddressVisitor& visitor) const;
264
266 std::map<FileOffset,AdminRegionRef>& refs) const;
267
268 void DumpStatistics() const;
269
270 void FlushCache() const;
271 };
272
273 using LocationIndexRef = std::shared_ptr<LocationIndex>;
274}
275
276#endif
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Location.h:199
Definition Location.h:59
Definition Location.h:91
Definition Location.h:147
Definition LocationIndex.h:56
ScopeCacheCleaner(std::shared_ptr< LocationIndex > index)
Definition LocationIndex.h:59
ScopeCacheCleaner & operator=(ScopeCacheCleaner &&)=delete
ScopeCacheCleaner(const ScopeCacheCleaner &)=delete
ScopeCacheCleaner(ScopeCacheCleaner &&)=delete
~ScopeCacheCleaner()
Definition LocationIndex.h:68
ScopeCacheCleaner & operator=(const ScopeCacheCleaner &)=delete
static const char *const FILENAME_LOCATION_IDX
Definition LocationIndex.h:51
uint32_t GetAddressMaxWords() const
Definition LocationIndex.h:219
bool VisitAddresses(const AdminRegion &region, const PostalArea &postalArea, const Location &location, AddressVisitor &visitor) const
void DumpStatistics() const
bool ResolveAdminRegionHierachie(const AdminRegionRef &region, std::map< FileOffset, AdminRegionRef > &refs) const
bool VisitLocations(const AdminRegion &adminRegion, const PostalArea &postalArea, LocationVisitor &visitor, bool recursive=true) const
bool Load(const std::string &path, bool memoryMappedData)
bool VisitPOIs(const AdminRegion &region, POIVisitor &visitor, bool recursive=true) const
const std::vector< std::string > & GetRegionIgnoreTokens() const
Definition LocationIndex.h:186
bool VisitAdminRegions(AdminRegionVisitor &visitor) const
uint32_t GetRegionMaxWords() const
Definition LocationIndex.h:204
uint32_t GetPOIMaxWords() const
Definition LocationIndex.h:209
bool VisitAdminRegions(const AdminRegion &adminRegion, AdminRegionVisitor &visitor) const
bool IsRegionIgnoreToken(const std::string &token) const
uint32_t GetLocationMaxWords() const
Definition LocationIndex.h:214
const std::vector< std::string > & GetPOIIgnoreTokens() const
Definition LocationIndex.h:191
const std::vector< std::string > & GetLocationIgnoreTokens() const
Definition LocationIndex.h:196
bool IsLocationIgnoreToken(const std::string &token) const
bool VisitLocations(const AdminRegion &adminRegion, LocationVisitor &visitor, bool recursive=true) const
Definition Location.h:164
Definition ObjectPool.h:33
Definition Location.h:131
Definition Location.h:39
Definition Area.h:39
std::shared_ptr< AdminRegion > AdminRegionRef
Definition Location.h:83
std::shared_ptr< LocationIndex > LocationIndexRef
Definition LocationIndex.h:273
STL namespace.