libosmscout 1.1.1
Loading...
Searching...
No Matches
DBFileOffset.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_DBFILEOFFSET_H
2#define OSMSCOUT_DBFILEOFFSET_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2017 Lukas 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 <string>
24#include <ostream>
25#include <tuple>
27
28namespace osmscout{
29
30 using DatabaseId = uint32_t;
31
38 struct DBId
39 {
40 DatabaseId database=0; // NOLINT
41 Id id=0; // NOLINT
42
43 DBId() = default;
44 DBId(const DBId &) = default;
45 DBId(DBId &&) = default;
46
47 DBId &operator=(const DBId &) = default;
48 DBId &operator=(DBId &&) = default;
49
51 Id id)
53 id(id)
54 {
55 }
56
57 ~DBId() = default;
58
59 bool IsValid() const
60 {
61 return id!=0;
62 }
63
64 bool operator==(const DBId& other) const
65 {
66 return database==other.database && id==other.id;
67 }
68
69 bool operator!=(const DBId& other) const
70 {
71 return database!=other.database || id!=other.id;
72 }
73
74 bool operator<(const DBId& other) const
75 {
76 return std::tie(database, id) < std::tie(other.database, other.id);
77 }
78 };
79
80 inline std::ostream& operator<<(std::ostream &stream,const DBId &o)
81 {
82 stream << "DBId(" << o.database << "," << o.id << ")";
83 return stream;
84 }
85
93 {
94 DatabaseId database=0; // NOLINT
95 FileOffset offset=0; // NOLINT
96
97 DBFileOffset() = default;
98 DBFileOffset(const DBFileOffset &o) = default;
99
106
107 bool IsValid() const
108 {
109 return offset!=0;
110 }
111
112 bool operator==(const DBFileOffset& other) const
113 {
114 return database==other.database && offset==other.offset;
115 }
116
117 bool operator!=(const DBFileOffset& other) const
118 {
119 return database!=other.database || offset!=other.offset;
120 }
121
122 bool operator<(const DBFileOffset& other) const
123 {
124 return std::tie(database, offset) < std::tie(other.database, other.offset);
125 }
126
127 DBFileOffset& operator=(const DBFileOffset& other) = default;
128 };
129
130 inline std::ostream& operator<<(std::ostream &stream,const DBFileOffset &o)
131 {
132 stream << "DBFileOffset(" << o.database << "," << o.offset << ")";
133 return stream;
134 }
135}
136
137namespace std {
138 template <>
139 struct hash<osmscout::DBId>
140 {
141 size_t operator()(const osmscout::DBId& id) const
142 {
143 return hash<uint32_t>{}(id.database) ^ hash<osmscout::Id>{}(id.id);
144 }
145 };
146
147 template <>
148 struct hash<osmscout::DBFileOffset>
149 {
150 size_t operator()(const osmscout::DBFileOffset& id) const
151 {
152 return hash<uint32_t>{}(id.database) ^ hash<osmscout::FileOffset>{}(id.offset);
153 }
154 };
155}
156
157#endif /* OSMSCOUT_DBFILEOFFSET_H */
uint64_t Id
Definition OSMScoutTypes.h:40
uint64_t FileOffset
Definition OSMScoutTypes.h:46
Definition Area.h:39
std::ostream & operator<<(std::ostream &stream, const DBId &o)
Definition DBFileOffset.h:80
uint32_t DatabaseId
Definition DBFileOffset.h:30
STL namespace.
Definition DBFileOffset.h:93
bool operator==(const DBFileOffset &other) const
Definition DBFileOffset.h:112
FileOffset offset
Definition DBFileOffset.h:95
bool operator!=(const DBFileOffset &other) const
Definition DBFileOffset.h:117
DBFileOffset(DatabaseId database, FileOffset offset)
Definition DBFileOffset.h:100
bool operator<(const DBFileOffset &other) const
Definition DBFileOffset.h:122
DBFileOffset(const DBFileOffset &o)=default
bool IsValid() const
Definition DBFileOffset.h:107
DBFileOffset & operator=(const DBFileOffset &other)=default
DatabaseId database
Definition DBFileOffset.h:94
Definition DBFileOffset.h:39
bool operator!=(const DBId &other) const
Definition DBFileOffset.h:69
DBId & operator=(DBId &&)=default
bool operator==(const DBId &other) const
Definition DBFileOffset.h:64
bool operator<(const DBId &other) const
Definition DBFileOffset.h:74
DBId(DBId &&)=default
bool IsValid() const
Definition DBFileOffset.h:59
DatabaseId database
Definition DBFileOffset.h:40
DBId(DatabaseId database, Id id)
Definition DBFileOffset.h:50
DBId & operator=(const DBId &)=default
DBId(const DBId &)=default
DBId()=default
~DBId()=default
Id id
Definition DBFileOffset.h:41
size_t operator()(const osmscout::DBFileOffset &id) const
Definition DBFileOffset.h:150
size_t operator()(const osmscout::DBId &id) const
Definition DBFileOffset.h:141