libosmscout 1.1.1
Loading...
Searching...
No Matches
RouteNodeDataFile.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_ROUTENODEDATAFILE_H
2#define OSMSCOUT_ROUTENODEDATAFILE_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2018 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 <map>
24#include <vector>
25
26#include <osmscout/Pixel.h>
27
29
31
33
34namespace osmscout {
38 class OSMSCOUT_API RouteNodeDataFile CLASS_FINAL
39 {
40 private:
41 struct IndexEntry
42 {
43 FileOffset fileOffset;
44 uint32_t count;
45 };
46
47 struct IndexPage
48 {
49 FileOffset fileOffset;
50 uint32_t remaining;
51 std::unordered_map<Id,RouteNodeRef> nodeMap;
52
53 RouteNodeRef find(FileScanner& scanner,
54 Id id);
55 };
56
57 private:
58 using ValueCache = Cache<Id, IndexPage>;
59
60 private:
61 std::string datafile;
62 std::string datafilename;
63
64 TypeConfigRef typeConfig;
65
66 std::map<Pixel,IndexEntry> index;
67
68 mutable FileScanner scanner;
69 mutable ValueCache cache;
70 mutable std::mutex accessMutex;
71 mutable Magnification magnification;
72
73 private:
74 bool LoadIndexPage(const osmscout::Pixel& tile,
75 ValueCache::CacheRef& cacheRef) const;
76 bool GetIndexPage(const osmscout::Pixel& tile,
77 ValueCache::CacheRef& cacheRef) const;
78
79 public:
80 explicit RouteNodeDataFile(const std::string& datafile,
81 size_t cacheSize);
82
83 bool Open(const TypeConfigRef& typeConfig,
84 const std::string& path,
85 bool memoryMapedData);
86 bool IsOpen() const;
87 bool Close();
88
89 Pixel GetTile(const GeoCoord& coord) const;
90 bool IsCovered(const Pixel& tile) const;
91
92 bool IsCovered(const GeoCoord& coord) const;
93
94 bool Get(Id id,
95 RouteNodeRef& node) const;
96
97 template<typename IteratorIn>
98 bool Get(IteratorIn begin, IteratorIn end, size_t size,
99 std::vector<RouteNodeRef>& data) const
100 {
101 data.reserve(size);
102
103 for (IteratorIn idIter=begin; idIter!=end; ++idIter) {
104 Id id=*idIter;
105 ValueCache::CacheRef cacheRef;
106
107 GeoCoord coord=Point::GetCoordFromId(id);
108 osmscout::Pixel tile=TileId::GetTile(magnification,coord).AsPixel();
109
110 //std::cout << "Tile " << tile.GetDisplayText() << " " << tile.GetId() << "..." << std::endl;
111
112 if (!GetIndexPage(tile,
113 cacheRef)) {
114 return false;
115 }
116
117 auto node=cacheRef->value.find(scanner,
118 id);
119
120 if (node==nullptr) {
121 return false;
122 }
123
124 data.push_back(node);
125 }
126
127 return true;
128 }
129
130 template<typename IteratorIn>
131 bool Get(IteratorIn begin, IteratorIn end, size_t /*size*/,
132 std::unordered_map<Id,RouteNodeRef>& dataMap) const
133 {
134 for (IteratorIn idIter=begin; idIter!=end; ++idIter) {
135 Id id=*idIter;
136 ValueCache::CacheRef cacheRef;
137
138 GeoCoord coord=Point::GetCoordFromId(id);
139 osmscout::Pixel tile=TileId::GetTile(magnification,coord).AsPixel();
140
141 //std::cout << "Tile " << tile.GetDisplayText() << " " << tile.GetId() << "..." << std::endl;
142
143 if (!GetIndexPage(tile,
144 cacheRef)) {
145 return false;
146 }
147
148 auto node=cacheRef->value.find(scanner,
149 id);
150
151 if (node==nullptr) {
152 return false;
153 }
154
155 dataMap[id]=node;
156 }
157
158 return true;
159 }
160 };
161
162}
163
164#endif
165
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Area.h:88
const GeoCoord coord
Definition RouteStateAgent.h:49
bool Open(const TypeConfigRef &typeConfig, const std::string &path, bool memoryMapedData)
bool Get(Id id, RouteNodeRef &node) const
bool IsCovered(const Pixel &tile) const
bool Get(IteratorIn begin, IteratorIn end, size_t size, std::vector< RouteNodeRef > &data) const
Definition RouteNodeDataFile.h:98
TypeInfoSetConstIterator begin() const
Definition TypeInfoSet.h:180
OSMId id
We are an area.
Definition ObjectRef.h:49
bool IsCovered(const GeoCoord &coord) const
Pixel GetTile(const GeoCoord &coord) const
RoutableObjectsRef data
Definition DataAgent.h:63
RouteNodeDataFile(const std::string &datafile, size_t cacheSize)
bool Get(IteratorIn begin, IteratorIn end, size_t, std::unordered_map< Id, RouteNodeRef > &dataMap) const
Definition RouteNodeDataFile.h:131
typename OrderList::iterator CacheRef
Definition Cache.h:98
static TileId GetTile(const Magnification &magnification, const GeoCoord &coord)
uint64_t Id
Definition OSMScoutTypes.h:40
uint64_t FileOffset
Definition OSMScoutTypes.h:46
std::shared_ptr< TypeConfig > TypeConfigRef
Definition TypeConfig.h:1396
Definition Area.h:39
std::shared_ptr< RouteNode > RouteNodeRef
Definition RouteNode.h:177