libosmscout  1.1.1
ObjectRef.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_OBJECTREF_H
2 #define OSMSCOUT_OBJECTREF_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2009 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 
24 
25 #include <string>
26 #include <tuple>
27 
28 #include <osmscout/OSMScoutTypes.h>
29 
31 
32 namespace osmscout {
33 
35  {
38  osmRefWay = 2,
40  };
41 
46  class OSMSCOUT_API ObjectOSMRef CLASS_FINAL
47  {
48  public:
49  OSMId id=0; //NOLINT
50  OSMRefType type=osmRefNone; // NOLINT
51 
52  public:
53  ObjectOSMRef() = default;
54  ObjectOSMRef(const ObjectOSMRef& ref) = default;
55 
57  OSMRefType type)
58  : id(id),
59  type(type)
60  {
61  // no code
62  }
63 
64  void Set(const OSMId& id,
65  const OSMRefType& type)
66  {
67  this->id=id;
68  this->type=type;
69  }
70 
71  void Invalidate()
72  {
73  this->id=0;
74  this->type=osmRefNone;
75  }
76 
77  const OSMId& GetId() const
78  {
79  return id;
80  }
81 
82  const OSMRefType& GetType() const
83  {
84  return type;
85  }
86 
87  std::string GetName() const;
88 
89  bool Valid() const
90  {
91  return type!=osmRefNone;
92  }
93 
94  bool Invalid() const
95  {
96  return type==osmRefNone;
97  }
98 
99  bool IsNode() const
100  {
101  return type==osmRefNode;
102  }
103 
104  bool IsWay() const
105  {
106  return type==osmRefWay;
107  }
108 
109  bool IsRelation() const
110  {
111  return type==osmRefRelation;
112  }
113  bool operator<(const ObjectOSMRef& reference) const
114  {
115  return std::tie(type, id) < std::tie(reference.type, reference.id);
116  }
117 
118  bool operator==(const ObjectOSMRef& reference) const
119  {
120  return type==reference.type && id==reference.id;
121  }
122 
123  bool operator!=(const ObjectOSMRef& reference) const
124  {
125  return type!=reference.type || id!=reference.id;
126  }
127 
128  const char* GetTypeName() const;
129  };
130 
131  enum RefType
132  {
133  refNone = 0,
134  refNode = 1,
135  refArea = 2,
136  refWay = 3
137  };
138 
143  class OSMSCOUT_API ObjectFileRef CLASS_FINAL
144  {
145  public:
146  FileOffset offset=0; // NOLINT
147  RefType type=refNone; // NOLINT
148 
149  public:
150  ObjectFileRef() = default;
151  ObjectFileRef(const ObjectFileRef& ref) = default;
152 
154  RefType type)
155  : offset(offset),
156  type(type)
157  {
158  // no code
159  }
160 
161  void Set(const FileOffset& offset,
162  const RefType& type)
163  {
164  this->offset=offset;
165  this->type=type;
166  }
167 
168  void Invalidate()
169  {
170  this->offset=0;
171  this->type=refNone;
172  }
173 
174  const FileOffset& GetFileOffset() const
175  {
176  return offset;
177  }
178 
179  const RefType& GetType() const
180  {
181  return type;
182  }
183 
184  std::string GetName() const;
185 
186  bool Valid() const
187  {
188  return type!=refNone;
189  }
190 
191  bool Invalid() const
192  {
193  return type==refNone;
194  }
195 
196  bool IsNode() const
197  {
198  return type==refNode;
199  }
200 
201  bool IsWay() const
202  {
203  return type==refWay;
204  }
205 
206  bool IsArea() const
207  {
208  return type==refArea;
209  }
210 
211  bool operator<(const ObjectFileRef& reference) const
212  {
213  return std::tie(type, offset) < std::tie(reference.type, reference.offset);
214  }
215 
216  bool operator==(const ObjectFileRef& reference) const
217  {
218  return type==reference.type && offset==reference.offset;
219  }
220 
221  bool operator!=(const ObjectFileRef& reference) const
222  {
223  return type!=reference.type || offset!=reference.offset;
224  }
225 
226  const char* GetTypeName() const;
227  };
228 
229 
233  class OSMSCOUT_API ObjectFileRefByFileOffsetComparator CLASS_FINAL
234  {
235  public:
236  bool operator()(const ObjectFileRef& a,
237  const ObjectFileRef& b) const
238  {
239  return a.GetFileOffset()<b.GetFileOffset();
240  }
241  };
242 }
243 
244 #endif
bool operator!=(const ObjectFileRef &reference) const
Definition: ObjectRef.h:221
int64_t OSMId
Definition: OSMScoutTypes.h:34
bool operator==(const ObjectFileRef &reference) const
Definition: ObjectRef.h:216
OSMRefType
Definition: ObjectRef.h:34
Definition: ObjectRef.h:39
bool operator==(const ObjectOSMRef &reference) const
Definition: ObjectRef.h:118
Definition: ObjectRef.h:135
bool IsWay() const
Definition: ObjectRef.h:104
const RefType & GetType() const
Definition: ObjectRef.h:179
Definition: ObjectRef.h:37
Definition: ObjectRef.h:133
RefType
Definition: ObjectRef.h:131
ObjectFileRef(FileOffset offset, RefType type)
Definition: ObjectRef.h:153
bool IsNode() const
Definition: ObjectRef.h:99
Definition: Area.h:38
Definition: ObjectRef.h:38
const TypeInfoRef & reference
Definition: TypeInfoSet.h:37
void Set(const FileOffset &offset, const RefType &type)
Definition: ObjectRef.h:161
bool operator!=(const ObjectOSMRef &reference) const
Definition: ObjectRef.h:123
#define CLASS_FINAL
Definition: Compiler.h:26
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
Definition: ObjectRef.h:134
bool operator()(const ObjectFileRef &a, const ObjectFileRef &b) const
Definition: ObjectRef.h:236
const OSMId & GetId() const
Definition: ObjectRef.h:77
const OSMRefType & GetType() const
Definition: ObjectRef.h:82
bool Valid() const
Definition: ObjectRef.h:89
bool operator<(const ObjectFileRef &reference) const
Definition: ObjectRef.h:211
void Set(const OSMId &id, const OSMRefType &type)
Definition: ObjectRef.h:64
uint64_t FileOffset
Definition: OSMScoutTypes.h:47
Definition: ObjectRef.h:36
bool IsRelation() const
Definition: ObjectRef.h:109
void Invalidate()
Definition: ObjectRef.h:71
Definition: ObjectRef.h:136
bool Invalid() const
Definition: ObjectRef.h:94
bool IsArea() const
Definition: ObjectRef.h:206
const FileOffset & GetFileOffset() const
Definition: ObjectRef.h:174
bool operator<(const ObjectOSMRef &reference) const
Definition: ObjectRef.h:113
ObjectOSMRef(OSMId id, OSMRefType type)
Definition: ObjectRef.h:56