libosmscout  1.1.1
AreaIndex.h
Go to the documentation of this file.
1 #ifndef LIBOSMSCOUT_AREAYINDEX_H
2 #define LIBOSMSCOUT_AREAYINDEX_H
3 /*
4  This source is part of the libosmscout library
5  Copyright (C) 2011 Tim Teulings
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 
22 #include <memory>
23 #include <mutex>
24 #include <unordered_set>
25 #include <vector>
26 
27 #include <osmscout/TypeConfig.h>
28 #include <osmscout/TypeInfoSet.h>
29 
31 #include <osmscout/util/TileId.h>
32 
33 namespace osmscout {
34 
40  {
41  protected:
42  struct TypeData
43  {
45  MagnificationLevel indexLevel;
46 
47  uint8_t dataOffsetBytes;
49 
50  TileIdBox tileBox;
51 
52  GeoBox boundingBox;
53 
54  TypeData();
55 
56  FileOffset GetDataOffset() const;
57  FileOffset GetCellOffset(size_t x, size_t y) const;
58  };
59 
60  std::string indexFileName;
61  std::string fullIndexFileName;
62  mutable FileScanner scanner;
63 
64  std::vector<TypeData> typeData;
65 
66  mutable std::mutex lookupMutex;
67 
68  protected:
69  void GetOffsets(const TypeData& typeData,
70  const GeoBox& boundingBox,
71  std::unordered_set<FileOffset>& offsets) const;
72 
73  AreaIndex(const std::string &indexFileName);
74 
75  virtual void ReadTypeData(const TypeConfigRef& typeConfig,
76  TypeData &data) = 0;
77 
78  public:
79  AreaIndex() = default;
80 
81  // disable copy and move
82  AreaIndex(const AreaIndex&) = delete;
83  AreaIndex(AreaIndex&&) = delete;
84  AreaIndex& operator=(const AreaIndex&) = delete;
85  AreaIndex& operator=(AreaIndex&&) = delete;
86 
87  virtual ~AreaIndex();
88 
89  void Close();
90  bool Open(const TypeConfigRef& typeConfig,
91  const std::string& path,
92  bool memoryMappedData);
93 
94  inline bool IsOpen() const
95  {
96  return scanner.IsOpen();
97  }
98 
99  inline std::string GetFilename() const
100  {
101  return fullIndexFileName;
102  }
103 
104  bool GetOffsets(const GeoBox& boundingBox,
105  const TypeInfoSet& types,
106  std::vector<FileOffset>& offsets,
107  TypeInfoSet& loadedTypes) const;
108  };
109 }
110 
111 #endif //LIBOSMSCOUT_AREAYINDEX_H
std::string fullIndexFileName
Full path and name of the data file.
Definition: AreaIndex.h:61
uint8_t dataOffsetBytes
Definition: AreaIndex.h:47
std::vector< TypeData > typeData
Definition: AreaIndex.h:64
bool IsOpen() const
Definition: AreaIndex.h:94
FileScanner scanner
Scanner instance for reading this file.
Definition: AreaIndex.h:62
Definition: Area.h:38
std::string indexFileName
Definition: AreaIndex.h:60
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
std::mutex lookupMutex
Definition: AreaIndex.h:66
TileIdBox tileBox
Definition: AreaIndex.h:50
std::shared_ptr< TypeInfo > TypeInfoRef
Definition: TypeConfig.h:58
uint64_t FileOffset
Definition: OSMScoutTypes.h:47
TypeInfoRef type
Definition: AreaIndex.h:44
GeoBox boundingBox
Definition: AreaIndex.h:52
std::shared_ptr< TypeConfig > TypeConfigRef
Definition: TypeConfig.h:1227
MagnificationLevel indexLevel
Definition: AreaIndex.h:45
std::string GetFilename() const
Definition: AreaIndex.h:99
Definition: AreaIndex.h:39
FileOffset bitmapOffset
Definition: AreaIndex.h:48
Definition: AreaIndex.h:42