cpp-common/bt2: add bt2::wrap() overloads
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 4 Nov 2023 19:34:09 +0000 (15:34 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 14 Dec 2023 15:57:04 +0000 (10:57 -0500)
You may now call bt2::wrap() with any libbabeltrace2 object pointer with
which you could build a borrowed object wrapper. Therefore, this
excludes `bt2::MessageArray` which is a special case (ownership is
transferred).

For example:

    void f(bt_value * const val)
    {
        const auto wrappedVal = bt2::wrap(val);

        if (wrappedVal.isUnsignedInteger()) {
            *wrappedVal = 23;
        }

        // ...
    }

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I49cc7121bb3c85dc49b9682c219940d4cb2aab5d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11240
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>

src/Makefile.am
src/cpp-common/bt2/wrap.hpp [new file with mode: 0644]

index a3e07d0bbd9b90b67d253ea620a7f042d3dd3c2f..a2c5d8a8d4c4d8fa00633dca082127c6d945ef61 100644 (file)
@@ -39,6 +39,7 @@ noinst_HEADERS = \
        cpp-common/bt2/trace-ir.hpp \
        cpp-common/bt2/type-traits.hpp \
        cpp-common/bt2/value.hpp \
+       cpp-common/bt2/wrap.hpp \
        cpp-common/align.hpp \
        cpp-common/cfg-error-reporting.hpp \
        cpp-common/cfg-error-reporting-throw.hpp \
diff --git a/src/cpp-common/bt2/wrap.hpp b/src/cpp-common/bt2/wrap.hpp
new file mode 100644 (file)
index 0000000..cd0d710
--- /dev/null
@@ -0,0 +1,300 @@
+/*
+ * Copyright (c) 2023 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2_WRAP_HPP
+#define BABELTRACE_CPP_COMMON_BT2_WRAP_HPP
+
+#include <babeltrace2/babeltrace.h>
+
+#include "clock-class.hpp"
+#include "clock-snapshot.hpp"
+#include "component-port.hpp"
+#include "field-class.hpp"
+#include "field.hpp"
+#include "integer-range-set.hpp"
+#include "integer-range.hpp"
+#include "message-iterator.hpp"
+#include "message.hpp"
+#include "private-query-executor.hpp"
+#include "self-component-class.hpp"
+#include "self-component-port.hpp"
+#include "self-message-iterator-configuration.hpp"
+#include "self-message-iterator.hpp"
+#include "trace-ir.hpp"
+#include "value.hpp"
+
+namespace bt2 {
+
+inline ClockClass wrap(bt_clock_class * const libObjPtr) noexcept
+{
+    return ClockClass {libObjPtr};
+}
+
+inline ConstClockClass wrap(const bt_clock_class * const libObjPtr) noexcept
+{
+    return ConstClockClass {libObjPtr};
+}
+
+inline ConstClockSnapshot wrap(const bt_clock_snapshot * const libObjPtr) noexcept
+{
+    return ConstClockSnapshot {libObjPtr};
+}
+
+inline ConstComponent wrap(const bt_component * const libObjPtr) noexcept
+{
+    return ConstComponent {libObjPtr};
+}
+
+inline ConstSourceComponent wrap(const bt_component_source * const libObjPtr) noexcept
+{
+    return ConstSourceComponent {libObjPtr};
+}
+
+inline ConstFilterComponent wrap(const bt_component_filter * const libObjPtr) noexcept
+{
+    return ConstFilterComponent {libObjPtr};
+}
+
+inline ConstSinkComponent wrap(const bt_component_sink * const libObjPtr) noexcept
+{
+    return ConstSinkComponent {libObjPtr};
+}
+
+inline ConstInputPort wrap(const bt_port_input * const libObjPtr) noexcept
+{
+    return ConstInputPort {libObjPtr};
+}
+
+inline ConstOutputPort wrap(const bt_port_output * const libObjPtr) noexcept
+{
+    return ConstOutputPort {libObjPtr};
+}
+
+inline FieldClass wrap(bt_field_class * const libObjPtr) noexcept
+{
+    return FieldClass {libObjPtr};
+}
+
+inline ConstFieldClass wrap(const bt_field_class * const libObjPtr) noexcept
+{
+    return ConstFieldClass {libObjPtr};
+}
+
+inline ConstFieldPathItem wrap(const bt_field_path_item * const libObjPtr) noexcept
+{
+    return ConstFieldPathItem {libObjPtr};
+}
+
+inline ConstFieldPath wrap(const bt_field_path * const libObjPtr) noexcept
+{
+    return ConstFieldPath {libObjPtr};
+}
+
+inline Field wrap(bt_field * const libObjPtr) noexcept
+{
+    return Field {libObjPtr};
+}
+
+inline ConstField wrap(const bt_field * const libObjPtr) noexcept
+{
+    return ConstField {libObjPtr};
+}
+
+inline UnsignedIntegerRangeSet wrap(bt_integer_range_set_unsigned * const libObjPtr) noexcept
+{
+    return UnsignedIntegerRangeSet {libObjPtr};
+}
+
+inline ConstUnsignedIntegerRangeSet
+wrap(const bt_integer_range_set_unsigned * const libObjPtr) noexcept
+{
+    return ConstUnsignedIntegerRangeSet {libObjPtr};
+}
+
+inline SignedIntegerRangeSet wrap(bt_integer_range_set_signed * const libObjPtr) noexcept
+{
+    return SignedIntegerRangeSet {libObjPtr};
+}
+
+inline ConstSignedIntegerRangeSet wrap(const bt_integer_range_set_signed * const libObjPtr) noexcept
+{
+    return ConstSignedIntegerRangeSet {libObjPtr};
+}
+
+inline ConstUnsignedIntegerRange wrap(const bt_integer_range_unsigned * const libObjPtr) noexcept
+{
+    return ConstUnsignedIntegerRange {libObjPtr};
+}
+
+inline ConstSignedIntegerRange wrap(const bt_integer_range_signed * const libObjPtr) noexcept
+{
+    return ConstSignedIntegerRange {libObjPtr};
+}
+
+inline MessageIterator wrap(bt_message_iterator * const libObjPtr) noexcept
+{
+    return MessageIterator {libObjPtr};
+}
+
+inline Message wrap(bt_message * const libObjPtr) noexcept
+{
+    return Message {libObjPtr};
+}
+
+inline ConstMessage wrap(const bt_message * const libObjPtr) noexcept
+{
+    return ConstMessage {libObjPtr};
+}
+
+inline PrivateQueryExecutor wrap(bt_private_query_executor * const libObjPtr) noexcept
+{
+    return PrivateQueryExecutor {libObjPtr};
+}
+
+inline SelfComponentClass wrap(bt_self_component_class * const libObjPtr) noexcept
+{
+    return SelfComponentClass {libObjPtr};
+}
+
+inline SelfComponentClass wrap(bt_self_component_class_source * const libObjPtr) noexcept
+{
+    return SelfComponentClass {libObjPtr};
+}
+
+inline SelfComponentClass wrap(bt_self_component_class_filter * const libObjPtr) noexcept
+{
+    return SelfComponentClass {libObjPtr};
+}
+
+inline SelfComponentClass wrap(bt_self_component_class_sink * const libObjPtr) noexcept
+{
+    return SelfComponentClass {libObjPtr};
+}
+
+inline SelfComponent wrap(bt_self_component * const libObjPtr) noexcept
+{
+    return SelfComponent {libObjPtr};
+}
+
+inline SelfSourceComponent wrap(bt_self_component_source * const libObjPtr) noexcept
+{
+    return SelfSourceComponent {libObjPtr};
+}
+
+inline SelfFilterComponent wrap(bt_self_component_filter * const libObjPtr) noexcept
+{
+    return SelfFilterComponent {libObjPtr};
+}
+
+inline SelfSinkComponent wrap(bt_self_component_sink * const libObjPtr) noexcept
+{
+    return SelfSinkComponent {libObjPtr};
+}
+
+inline SelfComponentInputPort wrap(bt_self_component_port_input * const libObjPtr) noexcept
+{
+    return SelfComponentInputPort {libObjPtr};
+}
+
+inline SelfComponentOutputPort wrap(bt_self_component_port_output * const libObjPtr) noexcept
+{
+    return SelfComponentOutputPort {libObjPtr};
+}
+
+inline SelfMessageIterator wrap(bt_self_message_iterator * const libObjPtr) noexcept
+{
+    return SelfMessageIterator {libObjPtr};
+}
+
+inline SelfMessageIteratorConfiguration
+wrap(bt_self_message_iterator_configuration * const libObjPtr) noexcept
+{
+    return SelfMessageIteratorConfiguration {libObjPtr};
+}
+
+inline Event wrap(bt_event * const libObjPtr) noexcept
+{
+    return Event {libObjPtr};
+}
+
+inline ConstEvent wrap(const bt_event * const libObjPtr) noexcept
+{
+    return ConstEvent {libObjPtr};
+}
+
+inline Packet wrap(bt_packet * const libObjPtr) noexcept
+{
+    return Packet {libObjPtr};
+}
+
+inline ConstPacket wrap(const bt_packet * const libObjPtr) noexcept
+{
+    return ConstPacket {libObjPtr};
+}
+
+inline Stream wrap(bt_stream * const libObjPtr) noexcept
+{
+    return Stream {libObjPtr};
+}
+
+inline ConstStream wrap(const bt_stream * const libObjPtr) noexcept
+{
+    return ConstStream {libObjPtr};
+}
+
+inline Trace wrap(bt_trace * const libObjPtr) noexcept
+{
+    return Trace {libObjPtr};
+}
+
+inline ConstTrace wrap(const bt_trace * const libObjPtr) noexcept
+{
+    return ConstTrace {libObjPtr};
+}
+
+inline EventClass wrap(bt_event_class * const libObjPtr) noexcept
+{
+    return EventClass {libObjPtr};
+}
+
+inline ConstEventClass wrap(const bt_event_class * const libObjPtr) noexcept
+{
+    return ConstEventClass {libObjPtr};
+}
+
+inline StreamClass wrap(bt_stream_class * const libObjPtr) noexcept
+{
+    return StreamClass {libObjPtr};
+}
+
+inline ConstStreamClass wrap(const bt_stream_class * const libObjPtr) noexcept
+{
+    return ConstStreamClass {libObjPtr};
+}
+
+inline TraceClass wrap(bt_trace_class * const libObjPtr) noexcept
+{
+    return TraceClass {libObjPtr};
+}
+
+inline ConstTraceClass wrap(const bt_trace_class * const libObjPtr) noexcept
+{
+    return ConstTraceClass {libObjPtr};
+}
+
+inline Value wrap(bt_value * const libObjPtr) noexcept
+{
+    return Value {libObjPtr};
+}
+
+inline ConstValue wrap(const bt_value * const libObjPtr) noexcept
+{
+    return ConstValue {libObjPtr};
+}
+
+} /* namespace bt2 */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2_WRAP_HPP */
This page took 0.027612 seconds and 4 git commands to generate.