libosmscout  1.1.1
AreaAreaIndex.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_AREAAREAINDEX_H
2 #define OSMSCOUT_AREAAREAINDEX_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2010 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 <array>
24 #include <memory>
25 #include <mutex>
26 #include <vector>
27 
28 #include <osmscout/DataFile.h>
29 
30 #include <osmscout/TypeInfoSet.h>
31 
32 #include <osmscout/util/Cache.h>
33 #include <osmscout/util/Geometry.h>
35 
36 namespace osmscout {
37 
53  {
54  public:
55  static const char* const AREA_AREA_IDX;
56 
57  private:
61  struct IndexCell
62  {
63  std::array<FileOffset, 4> children;
64  FileOffset data;
65  };
66 
67  using IndexCache = Cache<FileOffset, IndexCell>;
68 
69  struct IndexCacheValueSizer : public IndexCache::ValueSizer
70  {
71  size_t GetSize(const IndexCell& value) const override
72  {
73  size_t memory=0;
74 
75  memory+=sizeof(value);
76 
77  return memory;
78  }
79  };
80 
81  struct CellRef
82  {
83  FileOffset offset;
84  size_t x;
85  size_t y;
86 
87  CellRef(FileOffset offset,
88  size_t x,
89  size_t y)
90  : offset(offset),
91  x(x),
92  y(y)
93  {
94  // no code
95  }
96  };
97 
98  private:
99  std::string datafilename;
100  mutable FileScanner scanner;
101 
102  uint32_t maxLevel;
103  FileOffset topLevelOffset;
104 
105  mutable IndexCache indexCache;
106 
107  mutable std::mutex lookupMutex;
108 
109  private:
110  bool GetIndexCell(uint32_t level,
111  FileOffset offset,
112  IndexCell& indexCell,
113  FileOffset& dataOffset) const;
114 
115  bool ReadCellData(const TypeConfig& typeConfig,
116  const TypeInfoSet& types,
117  FileOffset dataOffset,
118  std::vector<DataBlockSpan>& spans) const;
119 
120  void PushCellsForNextLevel(double minlon,
121  double minlat,
122  double maxlon,
123  double maxlat,
124  const IndexCell & cellIndexData,
125  const CellDimension& cellDimension,
126  size_t cx,
127  size_t cy,
128  std::vector<CellRef>& nextCellRefs) const;
129 
130  public:
131  explicit AreaAreaIndex(size_t cacheSize);
132  virtual ~AreaAreaIndex();
133 
134  void Close();
135  bool Open(const std::string& path, bool memoryMappedData);
136 
137  inline bool IsOpen() const
138  {
139  return scanner.IsOpen();
140  }
141 
142  inline std::string GetFilename() const
143  {
144  return datafilename;
145  }
146 
147  bool GetAreasInArea(const TypeConfig& typeConfig,
148  const GeoBox& boundingBox,
149  size_t maxLevel,
150  const TypeInfoSet& types,
151  std::vector<DataBlockSpan>& spans,
152  TypeInfoSet& loadedTypes) const;
153 
154  void DumpStatistics();
155 
156  void FlushCache();
157  };
158 
159  using AreaAreaIndexRef = std::shared_ptr<AreaAreaIndex>;
160 }
161 
162 #endif
std::shared_ptr< AreaAreaIndex > AreaAreaIndexRef
Definition: AreaAreaIndex.h:159
Prints details for debugging, if debug flag (performance, data) is set in renderer parameter...
Definition: MapPainter.h:58
OSMSCOUT_API const std::array< CellDimension, CELL_DIMENSION_COUNT > cellDimension
Definition: Area.h:38
bool IsOpen() const
Definition: AreaAreaIndex.h:137
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
std::string GetFilename() const
Definition: AreaAreaIndex.h:142
Definition: AreaAreaIndex.h:52
uint64_t FileOffset
Definition: OSMScoutTypes.h:47
static const char *const AREA_AREA_IDX
Definition: AreaAreaIndex.h:55