libosmscout  1.1.1
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 #include <osmscout/util/GeoBox.h>
33 #include <osmscout/util/Geometry.h>
34 
36 
37 namespace osmscout {
38 
48  class OSMSCOUT_API Route CLASS_FINAL
49  {
50  public:
51  enum class MemberDirection {
52  forward,
53  backward
54  };
55 
56  struct SegmentMember {
57  MemberDirection direction{MemberDirection::forward};
59  };
60 
61  struct Segment {
62  std::vector<SegmentMember> members;
63  };
64 
65  using MemberCache=std::unordered_map<FileOffset,WayRef> ;
66 
67  std::vector<Segment> segments;
68  GeoBox bbox;
69 
70  private:
71  mutable std::mutex cacheMutex;
72  MemberCache resolvedMembers;
73 
74  FeatureValueBuffer featureValueBuffer;
75 
76  FileOffset fileOffset=0;
77  FileOffset nextFileOffset=0;
78 
79  public:
80  Route() = default;
81 
82  inline FileOffset GetFileOffset() const
83  {
84  return fileOffset;
85  }
86 
88  {
89  return nextFileOffset;
90  }
91 
92  std::vector<FileOffset> GetMemberOffsets() const;
93 
94  bool HasResolvedMembers() const
95  {
96  std::lock_guard<std::mutex> lock(cacheMutex);
97  return !resolvedMembers.empty();
98  }
99 
101  {
102  std::lock_guard<std::mutex> lock(cacheMutex);
103  this->resolvedMembers=map;
104  }
105 
107  {
108  std::lock_guard<std::mutex> lock(cacheMutex);
109  return resolvedMembers;
110  }
111 
112  // inline ObjectFileRef GetObjectFileRef() const
113  // {
114  // return {fileOffset,refRoute};
115  // }
116 
117  inline GeoBox GetBoundingBox() const
118  {
119  return bbox;
120  }
121 
122  inline TypeInfoRef GetType() const
123  {
124  return featureValueBuffer.GetType();
125  }
126 
127  inline size_t GetFeatureCount() const
128  {
129  return featureValueBuffer.GetType()->GetFeatureCount();
130  }
131 
132  inline bool HasFeature(size_t idx) const
133  {
134  return featureValueBuffer.HasFeature(idx);
135  }
136 
137  inline const FeatureInstance& GetFeature(size_t idx) const
138  {
139  return featureValueBuffer.GetType()->GetFeature(idx);
140  }
141 
142  inline FeatureValue* GetFeatureValue(size_t idx) const
143  {
144  return featureValueBuffer.GetValue(idx);
145  }
146 
147  inline void UnsetFeature(size_t idx)
148  {
149  featureValueBuffer.FreeValue(idx);
150  }
151 
152  inline const FeatureValueBuffer& GetFeatureValueBuffer() const
153  {
154  return featureValueBuffer;
155  }
156 
157  inline void SetType(const TypeInfoRef& type)
158  {
159  featureValueBuffer.SetType(type);
160  }
161 
162  inline void SetFeatures(const FeatureValueBuffer& buffer)
163  {
164  featureValueBuffer.Set(buffer);
165  }
166 
167  void Read(const TypeConfig& typeConfig,
168  FileScanner& scanner);
169 
170  void Write(const TypeConfig& typeConfig,
171  FileWriter& writer) const;
172  };
173 
174  using RouteRef = std::shared_ptr<Route>;
175 }
176 
177 #endif
178 
FileOffset GetFileOffset() const
Definition: Route.h:82
const FeatureValueBuffer & GetFeatureValueBuffer() const
Definition: Route.h:152
FileOffset way
Definition: Route.h:58
TypeInfoRef GetType() const
Definition: Route.h:122
std::vector< SegmentMember > members
Definition: Route.h:62
FileOffset GetNextFileOffset() const
Definition: Route.h:87
void SetType(const TypeInfoRef &type)
Definition: Route.h:157
Definition: Route.h:61
bool HasFeature(size_t idx) const
Definition: Route.h:132
MemberDirection
Definition: Route.h:51
Definition: Area.h:38
GeoBox GetBoundingBox() const
Definition: Route.h:117
size_t GetFeatureCount() const
Definition: Route.h:127
Definition: TypeFeature.h:40
FeatureValue * GetFeatureValue(size_t idx) const
Definition: Route.h:142
bool HasResolvedMembers() const
Definition: Route.h:94
#define CLASS_FINAL
Definition: Compiler.h:26
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
void UnsetFeature(size_t idx)
Definition: Route.h:147
std::unordered_map< FileOffset, WayRef > MemberCache
Definition: Route.h:65
std::vector< Segment > segments
Definition: Route.h:67
void SetResolvedMembers(const MemberCache &map)
Definition: Route.h:100
std::shared_ptr< TypeInfo > TypeInfoRef
Definition: TypeConfig.h:58
uint64_t FileOffset
Definition: OSMScoutTypes.h:47
const FeatureInstance & GetFeature(size_t idx) const
Definition: Route.h:137
MemberCache GetResolvedMembers() const
Definition: Route.h:106
std::shared_ptr< Route > RouteRef
Definition: Route.h:174
void SetFeatures(const FeatureValueBuffer &buffer)
Definition: Route.h:162