KOSMIndoorMap

internal.h
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
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
12namespace OSM {
13
14namespace Internal {
15/** Pointer with the lower bits used for compact flag storage. */
16template <typename T> class TaggedPointer
17{
18public:
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 [[nodiscard]] 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 [[nodiscard]] 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 [[nodiscard]] constexpr inline operator bool() const { return (m_data & ~TagMask); }
29 [[nodiscard]] constexpr inline bool operator==(TaggedPointer<T> other) const { return m_data == other.m_data; }
30 [[nodiscard]] constexpr inline bool operator!=(TaggedPointer<T> other) const { return m_data != other.m_data; }
31 [[nodiscard]] constexpr inline bool operator<(TaggedPointer<T> other) const { return m_data < other.m_data; }
32
33private:
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:17
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-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:55:21 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.