libosmscout  1.1.1
AreaNodeIndex.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_AREANODEINDEX_H
2 #define OSMSCOUT_AREANODEINDEX_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2011 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 <memory>
25 #include <mutex>
26 #include <vector>
27 
28 #include <osmscout/TypeConfig.h>
29 #include <osmscout/TypeInfoSet.h>
30 
32 #include <osmscout/util/TileId.h>
33 
34 namespace osmscout {
35 
45  {
46  public:
47  static const char* const AREA_NODE_IDX;
48 
49  private:
50  struct ListTile
51  {
52  FileOffset fileOffset;
53  uint16_t entryCount;
54  bool storeGeoCoord;
55  };
56 
57  struct BitmapTile
58  {
59  FileOffset fileOffset;
60  uint8_t dataOffsetBytes;
61  MagnificationLevel magnification;
62  };
63 
64  struct TypeData
65  {
66  bool isComplex;
67  GeoBox boundingBox;
68  FileOffset indexOffset=0;
69  uint16_t entryCount=0;
70 
71  std::map<TileId,ListTile> listTiles;
72  std::map<TileId,BitmapTile> bitmapTiles;
73  };
74 
75  private:
76  mutable FileScanner scanner;
77 
79  MagnificationLevel gridMag;
80  std::vector<TypeData> nodeTypeData;
81 
82  mutable std::mutex lookupMutex;
83 
84  private:
85  bool GetOffsetsList(const TypeData& typeData,
86  const GeoBox& boundingBox,
87  std::vector<FileOffset>& offsets) const;
88 
89  bool GetOffsetsTileList(const TypeData& typeData,
90  const GeoBox& boundingBox,
91  std::vector<FileOffset>& offsets) const;
92 
93  bool GetOffsetsBitmap(const TypeData& typeData,
94  const GeoBox& boundingBox,
95  std::vector<FileOffset>& offsets) const;
96 
97  public:
98  AreaNodeIndex() = default;
99 
100  void Close();
101  bool Open(const std::string& path,
102  bool memoryMappedData);
103 
104  inline bool IsOpen() const
105  {
106  return scanner.IsOpen();
107  }
108 
109  inline std::string GetFilename() const
110  {
111  return scanner.GetFilename();
112  }
113 
114  bool GetOffsets(const GeoBox& boundingBox,
115  const TypeInfoSet& requestedTypes,
116  std::vector<FileOffset>& offsets,
117  TypeInfoSet& loadedTypes) const;
118  };
119 
120  using AreaNodeIndexRef = std::shared_ptr<AreaNodeIndex>;
121 }
122 
123 #endif
Definition: AreaNodeIndex.h:44
std::string GetFilename() const
Definition: AreaNodeIndex.h:109
Definition: Area.h:38
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
static const char *const AREA_NODE_IDX
Definition: AreaNodeIndex.h:47
uint64_t FileOffset
Definition: OSMScoutTypes.h:47
std::shared_ptr< AreaNodeIndex > AreaNodeIndexRef
Definition: AreaNodeIndex.h:120
bool IsOpen() const
Definition: AreaNodeIndex.h:104