aboutsummaryrefslogtreecommitdiff
path: root/include/utility/pointer.h
diff options
context:
space:
mode:
authorGravatar Sadie Powell2026-03-28 21:32:23 +0000
committerGravatar Sadie Powell2026-03-29 00:42:15 +0000
commitcbc5431d62e3fe9166f18395dce3ddf2af0906d3 (patch)
tree48a87fc27dc4826ce0caf4071e2060a9ff9e24c5 /include/utility/pointer.h
parentMove service code from base to its own header. (diff)
Switch modules from reference<> to shared_ptr<> and weak_ptr<>.
Diffstat (limited to 'include/utility/pointer.h')
-rw-r--r--include/utility/pointer.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/include/utility/pointer.h b/include/utility/pointer.h
new file mode 100644
index 000000000..2e356ae2b
--- /dev/null
+++ b/include/utility/pointer.h
@@ -0,0 +1,42 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ * Copyright (C) 2026 Sadie Powell <sadie@witchery.services>
+ *
+ * This file is part of InspIRCd. InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+namespace insp
+{
+ /** Determines if the pointer in \p ptr1 is empty.
+ * @param ptr Either a shared_ptr<> or a weak_ptr<>.
+ */
+ template <typename Ptr>
+ bool empty_ptr(const Ptr& ptr)
+ {
+ return same_ptr(ptr, {});
+ }
+
+ /** Determines if the pointer in \p ptr1 points to the same value as the pointer in \p ptr2.
+ * @param ptr1 Either a shared_ptr<> or a weak_ptr<>.
+ * @param ptr2 Either a shared_ptr<> or a weak_ptr<>.
+ */
+ template <typename Ptr1, typename Ptr2 = Ptr1>
+ bool same_ptr(const Ptr1& ptr1, const Ptr2& ptr2)
+ {
+ return !ptr1.owner_before(ptr2) && !ptr2.owner_before(ptr1);
+ }
+}