From: Philippe Proulx Date: Fri, 11 Dec 2020 00:27:18 +0000 (-0500) Subject: Add `src/cpp-common/bt2/internal/utils.hpp` (validateCreatedObjPtr()) X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=dcfc2f5c7a9372d8301435fa67b5dec09369d9b9 Add `src/cpp-common/bt2/internal/utils.hpp` (validateCreatedObjPtr()) 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 Change-Id: Iba8428da517bbeb0714cd554cb69758a3f7c62c7 Reviewed-on: https://review.lttng.org/c/babeltrace/+/4536 --- diff --git a/src/cpp-common/bt2/internal/utils.hpp b/src/cpp-common/bt2/internal/utils.hpp new file mode 100644 index 00000000..d429f3bc --- /dev/null +++ b/src/cpp-common/bt2/internal/utils.hpp @@ -0,0 +1,28 @@ +/* + * Copyright 2019-2020 (c) Philippe Proulx + * + * SPDX-License-Identifier: MIT + */ + +#ifndef BABELTRACE_CPP_COMMON_BT2_INTERNAL_UTILS_HPP +#define BABELTRACE_CPP_COMMON_BT2_INTERNAL_UTILS_HPP + +#include + +#include "../lib-error.hpp" + +namespace bt2 { +namespace internal { + +template +void validateCreatedObjPtr(const LibObjPtrT libOjbPtr) +{ + if (!libOjbPtr) { + throw LibMemoryError {}; + } +} + +} // namespace internal +} // namespace bt2 + +#endif // BABELTRACE_CPP_COMMON_BT2_INTERNAL_UTILS_HPP