Add `src/cpp-common/bt2/internal/utils.hpp` (validateCreatedObjPtr())
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 11 Dec 2020 00:27:18 +0000 (19:27 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 28 Jan 2022 16:22:26 +0000 (11:22 -0500)
This patch adds `src/cpp-common/bt2/internal/utils.hpp`, that is,
internal utils for the libbabeltrace2 C++ interface.

Currently, the new file only contains validateCreatedObjPtr() which
throws a memory error if a pointer is `nullptr`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iba8428da517bbeb0714cd554cb69758a3f7c62c7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4536

src/cpp-common/bt2/internal/utils.hpp [new file with mode: 0644]

diff --git a/src/cpp-common/bt2/internal/utils.hpp b/src/cpp-common/bt2/internal/utils.hpp
new file mode 100644 (file)
index 0000000..d429f3b
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2019-2020 (c) Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2_INTERNAL_UTILS_HPP
+#define BABELTRACE_CPP_COMMON_BT2_INTERNAL_UTILS_HPP
+
+#include <type_traits>
+
+#include "../lib-error.hpp"
+
+namespace bt2 {
+namespace internal {
+
+template <typename LibObjPtrT>
+void validateCreatedObjPtr(const LibObjPtrT libOjbPtr)
+{
+    if (!libOjbPtr) {
+        throw LibMemoryError {};
+    }
+}
+
+} // namespace internal
+} // namespace bt2
+
+#endif // BABELTRACE_CPP_COMMON_BT2_INTERNAL_UTILS_HPP
This page took 0.024482 seconds and 4 git commands to generate.