cpp-common/bt2: `User*Component`: pass query method data to user `_query` methods
[babeltrace.git] / src / cpp-common / bt2 / trace-ir.hpp
index b6f349be9a6f7545292078460e7f6c2bdd3c94ff..7171138d340ca309ab900c53198dbc954f6a604b 100644 (file)
 
 #include <babeltrace2/babeltrace.h>
 
-#include "cpp-common/optional.hpp"
+#include "cpp-common/bt2c/c-string-view.hpp"
+#include "cpp-common/bt2s/optional.hpp"
 
 #include "borrowed-object.hpp"
 #include "clock-class.hpp"
 #include "field-class.hpp"
 #include "field.hpp"
 #include "internal/utils.hpp"
+#include "optional-borrowed-object.hpp"
 #include "shared-object.hpp"
 #include "value.hpp"
 
@@ -130,17 +132,18 @@ class CommonEvent final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonEventSpec<LibObjT>;
     using _Packet = internal::DepPacket<LibObjT>;
     using _Stream = internal::DepStream<LibObjT>;
     using _StructureField = internal::DepStructField<LibObjT>;
 
 public:
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
+
     using Class = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
                                     CommonEventClass<const bt_event_class>>;
 
-    explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonEvent(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -163,39 +166,21 @@ public:
 
     Class cls() const noexcept;
     _Stream stream() const noexcept;
-    nonstd::optional<_Packet> packet() const noexcept;
+    OptionalBorrowedObject<_Packet> packet() const noexcept;
 
-    nonstd::optional<_StructureField> payloadField() const noexcept
+    OptionalBorrowedObject<_StructureField> payloadField() const noexcept
     {
-        const auto libObjPtr = _Spec::payloadField(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _StructureField {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::payloadField(this->libObjPtr());
     }
 
-    nonstd::optional<_StructureField> specificContextField() const noexcept
+    OptionalBorrowedObject<_StructureField> specificContextField() const noexcept
     {
-        const auto libObjPtr = _Spec::specificContextField(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _StructureField {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::specificContextField(this->libObjPtr());
     }
 
-    nonstd::optional<_StructureField> commonContextField() const noexcept
+    OptionalBorrowedObject<_StructureField> commonContextField() const noexcept
     {
-        const auto libObjPtr = _Spec::commonContextField(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _StructureField {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::commonContextField(this->libObjPtr());
     }
 };
 
@@ -273,15 +258,15 @@ class CommonPacket final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonPacketSpec<LibObjT>;
     using _Stream = internal::DepStream<LibObjT>;
     using _StructureField = internal::DepStructField<LibObjT>;
 
 public:
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
     using Shared = SharedObject<CommonPacket, LibObjT, internal::PacketRefFuncs>;
 
-    explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonPacket(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -304,15 +289,9 @@ public:
 
     _Stream stream() const noexcept;
 
-    nonstd::optional<_StructureField> contextField() const noexcept
+    OptionalBorrowedObject<_StructureField> contextField() const noexcept
     {
-        const auto libObjPtr = _Spec::contextField(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _StructureField {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::contextField(this->libObjPtr());
     }
 
     Shared shared() const noexcept
@@ -345,16 +324,10 @@ struct TypeDescr<ConstPacket> : public PacketTypeDescr
 } /* namespace internal */
 
 template <typename LibObjT>
-nonstd::optional<typename CommonEvent<LibObjT>::_Packet>
+OptionalBorrowedObject<typename CommonEvent<LibObjT>::_Packet>
 CommonEvent<LibObjT>::packet() const noexcept
 {
-    const auto libObjPtr = _Spec::packet(this->libObjPtr());
-
-    if (libObjPtr) {
-        return _Packet {libObjPtr};
-    }
-
-    return nonstd::nullopt;
+    return _Spec::packet(this->libObjPtr());
 }
 
 namespace internal {
@@ -422,18 +395,18 @@ class CommonStream final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonStreamSpec<LibObjT>;
     using _Trace = internal::DepType<LibObjT, CommonTrace<bt_trace>, CommonTrace<const bt_trace>>;
 
 public:
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
     using Shared = SharedObject<CommonStream, LibObjT, internal::StreamRefFuncs>;
     using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
     using Class = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
                                     CommonStreamClass<const bt_stream_class>>;
 
-    explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonStream(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -472,7 +445,7 @@ public:
         return bt_stream_get_id(this->libObjPtr());
     }
 
-    void name(const char * const name) const
+    void name(const bt2c::CStringView name) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
 
@@ -483,12 +456,7 @@ public:
         }
     }
 
-    void name(const std::string& name) const
-    {
-        this->name(name.data());
-    }
-
-    const char *name() const noexcept
+    bt2c::CStringView name() const noexcept
     {
         return bt_stream_get_name(this->libObjPtr());
     }
@@ -624,11 +592,11 @@ class CommonTrace final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonTraceSpec<LibObjT>;
     using _Stream = internal::DepStream<LibObjT>;
 
 public:
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
     using Shared = SharedObject<CommonTrace, LibObjT, internal::TraceRefFuncs>;
     using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
@@ -637,11 +605,11 @@ public:
 
     struct ConstEnvironmentEntry
     {
-        const char *name;
+        bt2c::CStringView name;
         ConstValue value;
     };
 
-    explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonTrace(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -664,7 +632,7 @@ public:
 
     Class cls() const noexcept;
 
-    void name(const char * const name) const
+    void name(const bt2c::CStringView name) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
 
@@ -675,30 +643,25 @@ public:
         }
     }
 
-    void name(const std::string& name) const
-    {
-        this->name(name.data());
-    }
-
-    const char *name() const noexcept
+    bt2c::CStringView name() const noexcept
     {
         return bt_trace_get_name(this->libObjPtr());
     }
 
-    void uuid(const bt2_common::UuidView& uuid) const noexcept
+    void uuid(const bt2c::UuidView& uuid) const noexcept
     {
         bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
     }
 
-    nonstd::optional<bt2_common::UuidView> uuid() const noexcept
+    bt2s::optional<bt2c::UuidView> uuid() const noexcept
     {
         const auto uuid = bt_trace_get_uuid(this->libObjPtr());
 
         if (uuid) {
-            return bt2_common::UuidView {uuid};
+            return bt2c::UuidView {uuid};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
     std::uint64_t length() const noexcept
@@ -711,18 +674,12 @@ public:
         return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
     }
 
-    nonstd::optional<_Stream> streamById(const std::uint64_t id) const noexcept
+    OptionalBorrowedObject<_Stream> streamById(const std::uint64_t id) const noexcept
     {
-        const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id);
-
-        if (libObjPtr) {
-            return _Stream {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::streamById(this->libObjPtr(), id);
     }
 
-    void environmentEntry(const char * const name, const std::int64_t val) const
+    void environmentEntry(const bt2c::CStringView name, const std::int64_t val) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
 
@@ -733,12 +690,7 @@ public:
         }
     }
 
-    void environmentEntry(const std::string& name, const std::int64_t val) const
-    {
-        this->environmentEntry(name.data(), val);
-    }
-
-    void environmentEntry(const char * const name, const char * const val) const
+    void environmentEntry(const bt2c::CStringView name, const bt2c::CStringView val) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
 
@@ -749,21 +701,6 @@ public:
         }
     }
 
-    void environmentEntry(const std::string& name, const char * const val) const
-    {
-        this->environmentEntry(name.data(), val);
-    }
-
-    void environmentEntry(const char * const name, const std::string& val) const
-    {
-        this->environmentEntry(name, val.data());
-    }
-
-    void environmentEntry(const std::string& name, const std::string& val) const
-    {
-        this->environmentEntry(name.data(), val.data());
-    }
-
     std::uint64_t environmentSize() const noexcept
     {
         return bt_trace_get_environment_entry_count(this->libObjPtr());
@@ -779,21 +716,9 @@ public:
         return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
     }
 
-    nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept
+    OptionalBorrowedObject<ConstValue> environmentEntry(const bt2c::CStringView name) const noexcept
     {
-        const auto libObjPtr =
-            bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
-
-        if (libObjPtr) {
-            return ConstValue {libObjPtr};
-        }
-
-        return nonstd::nullopt;
-    }
-
-    nonstd::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
-    {
-        return this->environmentEntry(name.data());
+        return bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
     }
 
     template <typename LibValT>
@@ -923,7 +848,6 @@ class CommonEventClass final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonEventClassSpec<LibObjT>;
     using _StructureFieldClass = internal::DepStructFc<LibObjT>;
 
@@ -931,6 +855,7 @@ private:
                                            CommonStreamClass<const bt_stream_class>>;
 
 public:
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
     using Shared = SharedObject<CommonEventClass, LibObjT, internal::EventClassRefFuncs>;
     using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
@@ -953,7 +878,7 @@ public:
         DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
     };
 
-    explicit CommonEventClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonEventClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -982,7 +907,7 @@ public:
         return bt_event_class_get_id(this->libObjPtr());
     }
 
-    void name(const char * const name) const
+    void name(const bt2c::CStringView name) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
 
@@ -993,12 +918,7 @@ public:
         }
     }
 
-    void name(const std::string& name) const
-    {
-        this->name(name.data());
-    }
-
-    const char *name() const noexcept
+    bt2c::CStringView name() const noexcept
     {
         return bt_event_class_get_name(this->libObjPtr());
     }
@@ -1011,19 +931,18 @@ public:
                                      static_cast<bt_event_class_log_level>(logLevel));
     }
 
-    nonstd::optional<LogLevel> logLevel() const noexcept
+    bt2s::optional<LogLevel> logLevel() const noexcept
     {
         bt_event_class_log_level libLogLevel;
-        const auto avail = bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel);
 
-        if (avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
+        if (bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel)) {
             return static_cast<LogLevel>(libLogLevel);
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
-    void emfUri(const char * const emfUri) const
+    void emfUri(const bt2c::CStringView emfUri) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
 
@@ -1034,12 +953,7 @@ public:
         }
     }
 
-    void emfUri(const std::string& emfUri) const
-    {
-        this->emfUri(emfUri.data());
-    }
-
-    const char *emfUri() const noexcept
+    bt2c::CStringView emfUri() const noexcept
     {
         return bt_event_class_get_emf_uri(this->libObjPtr());
     }
@@ -1056,15 +970,9 @@ public:
         }
     }
 
-    nonstd::optional<_StructureFieldClass> payloadFieldClass() const noexcept
+    OptionalBorrowedObject<_StructureFieldClass> payloadFieldClass() const noexcept
     {
-        const auto libObjPtr = _Spec::payloadFieldClass(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _StructureFieldClass {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::payloadFieldClass(this->libObjPtr());
     }
 
     void specificContextFieldClass(const StructureFieldClass fc) const
@@ -1079,15 +987,9 @@ public:
         }
     }
 
-    nonstd::optional<_StructureFieldClass> specificContextFieldClass() const noexcept
+    OptionalBorrowedObject<_StructureFieldClass> specificContextFieldClass() const noexcept
     {
-        const auto libObjPtr = _Spec::specificContextFieldClass(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _StructureFieldClass {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::specificContextFieldClass(this->libObjPtr());
     }
 
     template <typename LibValT>
@@ -1249,7 +1151,6 @@ class CommonStreamClass final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonStreamClassSpec<LibObjT>;
     using _StructureFieldClass = internal::DepStructFc<LibObjT>;
 
@@ -1262,11 +1163,11 @@ private:
     using _ClockClass = internal::DepType<LibObjT, ClockClass, ConstClockClass>;
 
 public:
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
     using Shared = SharedObject<CommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
     using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
-    explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept :
-        _ThisBorrowedObject {libObjPtr}
+    explicit CommonStreamClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -1339,7 +1240,7 @@ public:
         return bt_stream_class_get_id(this->libObjPtr());
     }
 
-    void name(const char * const name) const
+    void name(const bt2c::CStringView name) const
     {
         static_assert(!std::is_const<LibObjT>::value,
                       "Not available with `bt2::ConstStreamClass`.");
@@ -1351,12 +1252,7 @@ public:
         }
     }
 
-    void name(const std::string& name) const
-    {
-        this->name(name.data());
-    }
-
-    const char *name() const noexcept
+    bt2c::CStringView name() const noexcept
     {
         return bt_stream_class_get_name(this->libObjPtr());
     }
@@ -1474,15 +1370,9 @@ public:
         BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
     }
 
-    nonstd::optional<_ClockClass> defaultClockClass() const noexcept
+    OptionalBorrowedObject<_ClockClass> defaultClockClass() const noexcept
     {
-        const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _ClockClass {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::defaultClockClass(this->libObjPtr());
     }
 
     std::uint64_t length() const noexcept
@@ -1495,15 +1385,9 @@ public:
         return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
     }
 
-    nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) const noexcept
+    OptionalBorrowedObject<_EventClass> eventClassById(const std::uint64_t id) const noexcept
     {
-        const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id);
-
-        if (libObjPtr) {
-            return _EventClass {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::eventClassById(this->libObjPtr(), id);
     }
 
     void packetContextFieldClass(const StructureFieldClass fc) const
@@ -1519,15 +1403,9 @@ public:
         }
     }
 
-    nonstd::optional<_StructureFieldClass> packetContextFieldClass() const noexcept
+    OptionalBorrowedObject<_StructureFieldClass> packetContextFieldClass() const noexcept
     {
-        const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _StructureFieldClass {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::packetContextFieldClass(this->libObjPtr());
     }
 
     void eventCommonContextFieldClass(const StructureFieldClass fc) const
@@ -1543,15 +1421,9 @@ public:
         }
     }
 
-    nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
+    OptionalBorrowedObject<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
     {
-        const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _StructureFieldClass {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::eventCommonContextFieldClass(this->libObjPtr());
     }
 
     template <typename LibValT>
@@ -1679,17 +1551,18 @@ class CommonTraceClass final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
+
     using _Spec = internal::CommonTraceClassSpec<LibObjT>;
 
     using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
                                            CommonStreamClass<const bt_stream_class>>;
 
 public:
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
     using Shared = SharedObject<CommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
     using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
-    explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonTraceClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -1981,15 +1854,9 @@ public:
         return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
     }
 
-    nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
+    OptionalBorrowedObject<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
     {
-        const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id);
-
-        if (libObjPtr) {
-            return _StreamClass {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::streamClassById(this->libObjPtr(), id);
     }
 
     template <typename LibValT>
This page took 0.030679 seconds and 4 git commands to generate.