libosmscout  1.1.1
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>
26 #include <osmscout/OSMScoutTypes.h>
27 
28 namespace 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)
52  : database(database),
53  id(id)
54  {
55  }
56 
57  ~DBId() = default;
58 
59  inline bool IsValid() const
60  {
61  return id!=0;
62  }
63 
64  inline bool operator==(const DBId& other) const
65  {
66  return database==other.database && id==other.id;
67  }
68 
69  inline bool operator!=(const DBId& other) const
70  {
71  return database!=other.database || id!=other.id;
72  }
73 
74  inline 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 
92  struct DBFileOffset
93  {
94  DatabaseId database=0; // NOLINT
95  FileOffset offset=0; // NOLINT
96 
97  DBFileOffset() = default;
98  DBFileOffset(const DBFileOffset &o) = default;
99 
102  : database(database),
103  offset(offset)
104  {
105  }
106 
107  inline bool IsValid() const
108  {
109  return offset!=0;
110  }
111 
112  inline bool operator==(const DBFileOffset& other) const
113  {
114  return database==other.database && offset==other.offset;
115  }
116 
117  inline bool operator!=(const DBFileOffset& other) const
118  {
119  return database!=other.database || offset!=other.offset;
120  }
121 
122  inline 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 
137 namespace 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 */
size_t operator()(const osmscout::DBId &id) const
Definition: DBFileOffset.h:141
bool operator!=(const DBFileOffset &other) const
Definition: DBFileOffset.h:117
bool IsValid() const
Definition: DBFileOffset.h:59
uint64_t Id
Definition: OSMScoutTypes.h:41
DBFileOffset(DatabaseId database, FileOffset offset)
Definition: DBFileOffset.h:100
STL namespace.
std::ostream & operator<<(std::ostream &stream, const DBId &o)
Definition: DBFileOffset.h:80
bool operator<(const DBId &other) const
Definition: DBFileOffset.h:74
bool operator==(const DBId &other) const
Definition: DBFileOffset.h:64
bool IsValid() const
Definition: DBFileOffset.h:107
DBId & operator=(const DBId &)=default
Definition: Area.h:38
DatabaseId database
Definition: DBFileOffset.h:40
~DBId()=default
bool operator!=(const DBId &other) const
Definition: DBFileOffset.h:69
DBId(DatabaseId database, Id id)
Definition: DBFileOffset.h:50
DBFileOffset & operator=(const DBFileOffset &other)=default
DatabaseId database
Definition: DBFileOffset.h:94
Id id
Definition: DBFileOffset.h:41
size_t operator()(const osmscout::DBFileOffset &id) const
Definition: DBFileOffset.h:150
uint64_t FileOffset
Definition: OSMScoutTypes.h:47
Definition: DBFileOffset.h:38
DBId()=default
FileOffset offset
Definition: DBFileOffset.h:95
Definition: DBFileOffset.h:92
bool operator==(const DBFileOffset &other) const
Definition: DBFileOffset.h:112
bool operator<(const DBFileOffset &other) const
Definition: DBFileOffset.h:122
uint32_t DatabaseId
Definition: DBFileOffset.h:30