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
--- /dev/null
+/*
+ * 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