libosmscout 1.1.1
Loading...
Searching...
No Matches
Route.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_ROUTE_OBJ_H
2#define OSMSCOUT_ROUTE_OBJ_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2020 Lukáš Karas
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 <memory>
24#include <unordered_map>
25#include <mutex>
26
27#include <osmscout/TypeConfig.h>
28#include <osmscout/Way.h>
29
32
35
37
38namespace osmscout {
39
49 class OSMSCOUT_API Route CLASS_FINAL
50 {
51 public:
52 enum class MemberDirection {
53 forward,
54 backward
55 };
56
61
62 struct Segment {
63 std::vector<SegmentMember> members;
64 };
65
66 using MemberCache=std::unordered_map<FileOffset,WayRef> ;
67
68 std::vector<Segment> segments;
70
71 private:
72 mutable std::mutex cacheMutex;
73 MemberCache resolvedMembers;
74
75 FeatureValueBuffer featureValueBuffer;
76
77 FileOffset fileOffset=0;
78 FileOffset nextFileOffset=0;
79
80 public:
81 Route() = default;
82
84 {
85 return fileOffset;
86 }
87
89 {
90 return nextFileOffset;
91 }
92
93 std::vector<FileOffset> GetMemberOffsets() const;
94
95 bool HasResolvedMembers() const
96 {
97 std::lock_guard<std::mutex> lock(cacheMutex);
98 return !resolvedMembers.empty();
99 }
100
102 {
103 std::lock_guard<std::mutex> lock(cacheMutex);
104 this->resolvedMembers=map;
105 }
106
108 {
109 std::lock_guard<std::mutex> lock(cacheMutex);
110 return resolvedMembers;
111 }
112
113 // ObjectFileRef GetObjectFileRef() const
114 // {
115 // return {fileOffset,refRoute};
116 // }
117
119 {
120 return bbox;
121 }
122
124 {
125 return featureValueBuffer.GetType();
126 }
127
128 size_t GetFeatureCount() const
129 {
130 return featureValueBuffer.GetType()->GetFeatureCount();
131 }
132
133 bool HasFeature(size_t idx) const
134 {
135 return featureValueBuffer.HasFeature(idx);
136 }
137
138 const FeatureInstance& GetFeature(size_t idx) const
139 {
140 return featureValueBuffer.GetType()->GetFeature(idx);
141 }
142
143 FeatureValue* GetFeatureValue(size_t idx) const
144 {
145 return featureValueBuffer.GetValue(idx);
146 }
147
148 void UnsetFeature(size_t idx)
149 {
150 featureValueBuffer.FreeValue(idx);
151 }
152
154 {
155 return featureValueBuffer;
156 }
157
159 {
160 featureValueBuffer.SetType(type);
161 }
162
164 {
165 featureValueBuffer.Set(buffer);
166 }
167
168 void Read(const TypeConfig& typeConfig,
169 FileScanner& scanner);
170
171 void Write(const TypeConfig& typeConfig,
172 FileWriter& writer) const;
173 };
174
175 using RouteRef = std::shared_ptr<Route>;
176}
177
178#endif
179
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Area.h:88
void UnsetFeature(size_t idx)
Definition Route.h:148
TypeInfoRef GetType() const
Definition Route.h:123
std::unordered_map< FileOffset, WayRef > MemberCache
Definition Route.h:66
void Write(const TypeConfig &typeConfig, FileWriter &writer) const
GeoBox GetBoundingBox() const
Definition Route.h:118
FileOffset GetFileOffset() const
Definition Route.h:83
bool HasFeature(size_t idx) const
Definition Route.h:133
FeatureValue * GetFeatureValue(size_t idx) const
Definition Route.h:143
FileOffset GetNextFileOffset() const
Definition Route.h:88
MemberDirection
Definition Route.h:52
void SetResolvedMembers(const MemberCache &map)
Definition Route.h:101
void SetFeatures(const FeatureValueBuffer &buffer)
Definition Route.h:163
bool HasResolvedMembers() const
Definition Route.h:95
std::vector< Segment > segments
Definition Route.h:68
std::vector< FileOffset > GetMemberOffsets() const
const FeatureValueBuffer & GetFeatureValueBuffer() const
Definition Route.h:153
MemberCache GetResolvedMembers() const
Definition Route.h:107
Type type
The type of the cell.
Definition GroundTile.h:92
void SetType(const TypeInfoRef &type)
Definition Route.h:158
Vertex2D * buffer
Definition Transformation.h:343
FeatureValueBuffer()=default
GeoBox bbox
Precomputed (cache) bounding box.
Definition DataAgent.h:53
const FeatureInstance & GetFeature(size_t idx) const
Definition Route.h:138
void Read(const TypeConfig &typeConfig, FileScanner &scanner)
size_t GetFeatureCount() const
Definition Route.h:128
Definition TypeFeature.h:41
uint64_t FileOffset
Definition OSMScoutTypes.h:46
Definition Area.h:39
std::shared_ptr< Route > RouteRef
Definition Route.h:175
std::shared_ptr< TypeInfo > TypeInfoRef
Definition TypeConfig.h:61
Definition Route.h:62
std::vector< SegmentMember > members
Definition Route.h:63
FileOffset way
Definition Route.h:59
MemberDirection direction
Definition Route.h:58