KOSMIndoorMap

internal.h
1 /*
2  SPDX-FileCopyrightText: 2020 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef OSM_INTERNAL_H
8 #define OSM_INTERNAL_H
9 
10 #include <cstdint>
11 
12 namespace OSM {
13 
14 namespace Internal {
15 /** Pointer with the lower bits used for compact flag storage. */
16 template <typename T> class TaggedPointer
17 {
18 public:
19  explicit inline constexpr TaggedPointer() = default;
20  explicit inline constexpr TaggedPointer(T *ptr, uint8_t tag)
21  : m_data(reinterpret_cast<std::uintptr_t>(ptr) | (tag & TagMask))
22  {}
23 
24  constexpr inline T* get() const { return reinterpret_cast<T*>(m_data & ~TagMask); }
25  constexpr inline void set(T *data) { m_data = (m_data & TagMask) | (reinterpret_cast<std::uintptr_t>(data) & ~TagMask); }
26  constexpr inline uint8_t tag() const { return m_data & TagMask; }
27  constexpr inline void setTag(uint8_t tag) { m_data = (tag & TagMask) | (m_data & ~TagMask); }
28  constexpr inline operator bool() const { return (m_data & ~TagMask); }
29  constexpr inline bool operator==(TaggedPointer<T> other) const { return m_data == other.m_data; }
30  constexpr inline bool operator!=(TaggedPointer<T> other) const { return m_data != other.m_data; }
31  constexpr inline bool operator<(TaggedPointer<T> other) const { return m_data < other.m_data; }
32 
33 private:
34  enum { TagMask = 0x3 };
35  std::uintptr_t m_data = 0;
36 };
37 
38 }
39 }
40 
41 #endif
Pointer with the lower bits used for compact flag storage.
Definition: internal.h:16
Low-level types and functions to work with raw OSM data as efficiently as possible.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 23:04:00 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.