libosmscout  1.1.1
LocationService.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_LOCATIONSERVICE_H
2 #define OSMSCOUT_LOCATIONSERVICE_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 <memory>
25 
26 #include <osmscout/Database.h>
27 #include <osmscout/Location.h>
28 
30 #include <osmscout/util/Breaker.h>
31 
32 namespace osmscout {
33 
39  class OSMSCOUT_API POIFormSearchParameter CLASS_FINAL
40  {
41  private:
42  std::string adminRegionSearchString;
43  std::string poiSearchString;
44 
45  bool adminRegionOnlyMatch;
46  bool poiOnlyMatch;
47 
48  bool partialMatch;
49 
50  StringMatcherFactoryRef stringMatcherFactory;
51 
52  size_t limit;
53 
54  BreakerRef breaker;
55  public:
56  explicit POIFormSearchParameter();
57 
58  std::string GetAdminRegionSearchString() const;
59  std::string GetPOISearchString() const;
60 
61  bool GetAdminRegionOnlyMatch() const;
62  bool GetPOIOnlyMatch() const;
63 
64  bool GetPartialMatch() const;
65 
66  StringMatcherFactoryRef GetStringMatcherFactory() const;
67 
68  size_t GetLimit() const;
69 
70  void SetStringMatcherFactory(const StringMatcherFactoryRef& stringMatcherFactory);
71 
72  void SetAdminRegionSearchString(const std::string& adminRegionSearchString);
73  void SetPOISearchString(const std::string& poiSearchString);
74 
75  void SetAdminRegionOnlyMatch(bool adminRegionOnlyMatch);
76  void SetPOIOnlyMatch(bool poiOnlyMatch);
77 
78  void SetPartialMatch(bool partialMatch);
79 
80  void SetLimit(size_t limit);
81 
82  void SetBreaker(BreakerRef &breaker);
83  BreakerRef GetBreaker() const;
84  bool IsAborted() const;
85  };
86 
92  class OSMSCOUT_API LocationFormSearchParameter CLASS_FINAL
93  {
94  private:
95  std::string adminRegionSearchString;
96  std::string postalAreaSearchString;
97  std::string locationSearchString;
98  std::string addressSearchString;
99 
100  bool adminRegionOnlyMatch;
101  bool postalAreaOnlyMatch;
102  bool locationOnlyMatch;
103  bool addressOnlyMatch;
104 
105  bool partialMatch;
106 
107  StringMatcherFactoryRef stringMatcherFactory;
108  size_t limit;
109 
110  BreakerRef breaker;
111  public:
112  explicit LocationFormSearchParameter();
113 
114  std::string GetAdminRegionSearchString() const;
115  std::string GetPostalAreaSearchString() const;
116  std::string GetLocationSearchString() const;
117  std::string GetAddressSearchString() const;
118 
119  bool GetAdminRegionOnlyMatch() const;
120  bool GetPostalAreaOnlyMatch() const;
121  bool GetLocationOnlyMatch() const;
122  bool GetAddressOnlyMatch() const;
123 
124  bool GetPartialMatch() const;
125 
126  StringMatcherFactoryRef GetStringMatcherFactory() const;
127 
128  size_t GetLimit() const;
129 
130  void SetStringMatcherFactory(const StringMatcherFactoryRef& stringMatcherFactory);
131 
132  void SetAdminRegionSearchString(const std::string& adminRegionSearchString);
133  void SetPostalAreaSearchString(const std::string& postalAreaSearchString);
134  void SetLocationSearchString(const std::string& locationSearchString);
135  void SetAddressSearchString(const std::string& addressSearchString);
136 
137  void SetAdminRegionOnlyMatch(bool adminRegionOnlyMatch);
138  void SetPostalAreaOnlyMatch(bool postalAreaOnlyMatch);
139  void SetLocationOnlyMatch(bool locationOnlyMatch);
140  void SetAddressOnlyMatch(bool addressOnlyMatch);
141 
142  void SetPartialMatch(bool partialMatch);
143 
144  void SetLimit(size_t limit);
145 
146  void SetBreaker(BreakerRef &breaker);
147  BreakerRef GetBreaker() const;
148  bool IsAborted() const;
149  };
150 
156  class OSMSCOUT_API LocationStringSearchParameter CLASS_FINAL
157  {
158  private:
159  AdminRegionRef defaultAdminRegion;
160 
161  bool searchForLocation=true;
162  bool searchForPOI=true;
163 
164  bool adminRegionOnlyMatch=false;
165  bool poiOnlyMatch=false;
166  bool locationOnlyMatch=false;
167  bool addressOnlyMatch=false;
168 
169  bool partialMatch=false;
170 
171  std::string searchString;
172  StringMatcherFactoryRef stringMatcherFactory;
173 
174  size_t limit=100;
175 
176  BreakerRef breaker;
177 
178  public:
179  explicit LocationStringSearchParameter(const std::string& searchString);
180 
181  AdminRegionRef GetDefaultAdminRegion() const;
182 
183  bool GetSearchForLocation() const;
184  bool GetSearchForPOI() const;
185 
186  bool GetAdminRegionOnlyMatch() const;
187  bool GetPOIOnlyMatch() const;
188  bool GetLocationOnlyMatch() const;
189  bool GetAddressOnlyMatch() const;
190 
191  bool GetPartialMatch() const;
192 
193  std::string GetSearchString() const;
194 
195  StringMatcherFactoryRef GetStringMatcherFactory() const;
196 
197  size_t GetLimit() const;
198 
199  void SetDefaultAdminRegion(const AdminRegionRef& adminRegion);
200 
201  void SetSearchForLocation(bool searchForLocation);
202  void SetSearchForPOI(bool searchForPOI);
203 
204  void SetAdminRegionOnlyMatch(bool adminRegionOnlyMatch);
205  void SetPOIOnlyMatch(bool poiOnlyMatch);
206  void SetLocationOnlyMatch(bool locationOnlyMatch);
207  void SetAddressOnlyMatch(bool addressOnlyMatch);
208 
209  void SetPartialMatch(bool partialMatch);
210 
211  void SetStringMatcherFactory(const StringMatcherFactoryRef& stringMatcherFactory);
212 
213  void SetLimit(size_t limit);
214 
215  void SetBreaker(BreakerRef &breaker);
216  BreakerRef GetBreaker() const;
217  bool IsAborted() const;
218  };
219 
226  {
227  public:
228 
230  match = 1,
231  candidate = 2,
232  none = 3
233  };
234 
236  {
237  public:
248 
249  bool operator<(const Entry& other) const;
250  bool operator==(const Entry& other) const;
251  };
252 
253  public:
254  std::list<Entry> results;
256  };
257 
279  {
280  private:
281  DatabaseRef database;
282 
283  public:
284  explicit LocationService(const DatabaseRef& database);
285 
286  bool VisitAdminRegions(AdminRegionVisitor& visitor) const;
287 
288  bool ResolveAdminRegionHierachie(const AdminRegionRef& adminRegion,
289  std::map<FileOffset,AdminRegionRef >& refs) const;
290 
291  bool VisitAdminRegionLocations(const AdminRegion& region,
292  const PostalArea& postalArea,
293  LocationVisitor& visitor) const;
294 
295  bool VisitAdminRegionPOIs(const AdminRegion& region,
296  POIVisitor& visitor) const;
297 
298  bool VisitLocationAddresses(const AdminRegion& region,
299  const PostalArea& postalArea,
300  const Location& location,
301  AddressVisitor& visitor) const;
302 
303  bool SearchForLocationByString(const LocationStringSearchParameter& searchParameter,
304  LocationSearchResult& result) const;
305 
306  bool SearchForLocationByForm(const LocationFormSearchParameter& searchParameter,
307  LocationSearchResult& result) const;
308 
309  bool SearchForPOIByForm(const POIFormSearchParameter& searchParameter,
310  LocationSearchResult& result) const;
311 
312  };
313 
317  using LocationServiceRef = std::shared_ptr<LocationService>;
318 }
319 
320 
321 #endif
PostalAreaRef postalArea
Definition: LocationService.h:240
MatchQuality postalAreaMatchQuality
Definition: LocationService.h:241
Definition: LocationService.h:235
AddressRef address
Definition: LocationService.h:246
std::shared_ptr< Breaker > BreakerRef
Definition: Breaker.h:65
Definition: Location.h:130
Definition: Location.h:146
std::shared_ptr< Database > DatabaseRef
Reference counted reference to an Database instance.
Definition: Database.h:555
Definition: Location.h:58
std::shared_ptr< Address > AddressRef
Definition: Location.h:191
Definition: Area.h:38
std::shared_ptr< PostalArea > PostalAreaRef
Definition: Location.h:45
Definition: Location.h:38
Definition: LocationService.h:278
MatchQuality poiMatchQuality
Definition: LocationService.h:245
#define CLASS_FINAL
Definition: Compiler.h:26
bool limitReached
Definition: LocationService.h:255
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
bool operator<(const TileCacheKey &a, const TileCacheKey &b)
Definition: Location.h:163
std::shared_ptr< StringMatcherFactory > StringMatcherFactoryRef
Definition: StringMatcher.h:67
MatchQuality
Definition: LocationService.h:229
Definition: LocationService.h:225
bool operator==(const MapView &a, const MapView &b)
Definition: InputHandler.h:222
std::shared_ptr< POI > POIRef
Definition: Location.h:123
std::list< Entry > results
Definition: LocationService.h:254
MatchQuality locationMatchQuality
Definition: LocationService.h:243
LocationRef location
Definition: LocationService.h:242
Definition: Location.h:90
POIRef poi
Definition: LocationService.h:244
Definition: Location.h:198
MatchQuality addressMatchQuality
Definition: LocationService.h:247
MatchQuality adminRegionMatchQuality
Definition: LocationService.h:239
std::shared_ptr< LocationService > LocationServiceRef
Definition: LocationService.h:317
std::shared_ptr< AdminRegion > AdminRegionRef
Definition: Location.h:83
std::shared_ptr< Location > LocationRef
Definition: Location.h:156
AdminRegionRef adminRegion
Definition: LocationService.h:238