Monado OpenXR Runtime
Loading...
Searching...
No Matches
u_weak_ptr.hpp
Go to the documentation of this file.
1// Copyright 2026, Beyley Cardellio
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief C++ helpers for weak pointers.
6 * @author Beyley Cardellio <ep1cm1n10n123@gmail.com>
7 *
8 * @ingroup aux_util
9 */
10
11#pragma once
12
13#include <memory>
14#include <stdexcept>
15
16
17#define U_ASSERT_WEAK_PTR_RET(ptr, msg, ...) \
18 do { \
19 if (!ptr) { \
20 U_LOG_E("Handle " #ptr " has expired unexpectedly! [%s:%d]: " msg, __func__, __LINE__); \
21 assert(false); \
22 return __VA_ARGS__; \
23 } \
24 } while (0)
25
26#define U_ASSERT_WEAK_PTR_THROW(ptr, msg, ...) \
27 do { \
28 if (!ptr) { \
29 U_LOG_E("Handle " #ptr " has expired unexpectedly! [%s:%d]: " msg, __func__, __LINE__); \
30 throw std::runtime_error("Weak pointer has expired unexpectedly"); \
31 } \
32 } while (0)