cpp-common/bt2: remove redundant assertions
[babeltrace.git] / src / cpp-common / bt2 / message.hpp
index ff0240d2774420a6483a9317356c44e1eb323494..3f9d74183e53f7e1d66e399d4f4d3e9c279c49ae 100644 (file)
 #include "common/assert.h"
 #include "cpp-common/bt2/clock-snapshot.hpp"
 #include "cpp-common/bt2/trace-ir.hpp"
-#include "cpp-common/optional.hpp"
+#include "cpp-common/bt2s/optional.hpp"
 
 #include "borrowed-object.hpp"
 #include "internal/utils.hpp"
+#include "optional-borrowed-object.hpp"
 #include "shared-object.hpp"
+#include "trace-ir.hpp"
 
 namespace bt2 {
 namespace internal {
@@ -85,13 +87,13 @@ private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
 
 protected:
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _ThisCommonMessage = CommonMessage<LibObjT>;
 
 public:
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
     using Shared = SharedMessage<CommonMessage<LibObjT>, LibObjT>;
 
-    explicit CommonMessage(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonMessage(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -228,14 +230,14 @@ template <typename LibObjT>
 class CommonStreamBeginningMessage final : public CommonMessage<LibObjT>
 {
 private:
-    using typename CommonMessage<LibObjT>::_LibObjPtr;
     using typename CommonMessage<LibObjT>::_ThisCommonMessage;
     using _Stream = internal::DepStream<LibObjT>;
 
 public:
+    using typename CommonMessage<LibObjT>::LibObjPtr;
     using Shared = SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
 
-    explicit CommonStreamBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonStreamBeginningMessage(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonMessage {libObjPtr}
     {
         BT_ASSERT_DBG(this->isStreamBeginning());
@@ -274,17 +276,17 @@ public:
         bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
     }
 
-    nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
+    OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
     {
         const bt_clock_snapshot *libObjPtr;
         const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
             this->libObjPtr(), &libObjPtr);
 
         if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
-            return ConstClockSnapshot {libObjPtr};
+            return libObjPtr;
         }
 
-        return nonstd::nullopt;
+        return {};
     }
 
     Shared shared() const noexcept
@@ -343,14 +345,14 @@ template <typename LibObjT>
 class CommonStreamEndMessage final : public CommonMessage<LibObjT>
 {
 private:
-    using typename CommonMessage<LibObjT>::_LibObjPtr;
     using typename CommonMessage<LibObjT>::_ThisCommonMessage;
     using _Stream = internal::DepStream<LibObjT>;
 
 public:
+    using typename CommonMessage<LibObjT>::LibObjPtr;
     using Shared = SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
 
-    explicit CommonStreamEndMessage(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonStreamEndMessage(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonMessage {libObjPtr}
     {
         BT_ASSERT_DBG(this->isStreamEnd());
@@ -388,17 +390,17 @@ public:
         bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
     }
 
-    nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
+    OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
     {
         const bt_clock_snapshot *libObjPtr;
         const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
             this->libObjPtr(), &libObjPtr);
 
         if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
-            return ConstClockSnapshot {libObjPtr};
+            return libObjPtr;
         }
 
-        return nonstd::nullopt;
+        return {};
     }
 
     Shared shared() const noexcept
@@ -457,14 +459,14 @@ template <typename LibObjT>
 class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
 {
 private:
-    using typename CommonMessage<LibObjT>::_LibObjPtr;
     using typename CommonMessage<LibObjT>::_ThisCommonMessage;
     using _Packet = internal::DepPacket<LibObjT>;
 
 public:
+    using typename CommonMessage<LibObjT>::LibObjPtr;
     using Shared = SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
 
-    explicit CommonPacketBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonPacketBeginningMessage(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonMessage {libObjPtr}
     {
         BT_ASSERT_DBG(this->isPacketBeginning());
@@ -567,14 +569,14 @@ template <typename LibObjT>
 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
 {
 private:
-    using typename CommonMessage<LibObjT>::_LibObjPtr;
     using typename CommonMessage<LibObjT>::_ThisCommonMessage;
     using _Packet = internal::DepPacket<LibObjT>;
 
 public:
+    using typename CommonMessage<LibObjT>::LibObjPtr;
     using Shared = SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
 
-    explicit CommonPacketEndMessage(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonPacketEndMessage(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonMessage {libObjPtr}
     {
         BT_ASSERT_DBG(this->isPacketEnd());
@@ -676,15 +678,14 @@ template <typename LibObjT>
 class CommonEventMessage final : public CommonMessage<LibObjT>
 {
 private:
-    using typename CommonMessage<LibObjT>::_LibObjPtr;
     using typename CommonMessage<LibObjT>::_ThisCommonMessage;
     using _Event = internal::DepType<LibObjT, CommonEvent<bt_event>, CommonEvent<const bt_event>>;
 
 public:
+    using typename CommonMessage<LibObjT>::LibObjPtr;
     using Shared = SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
 
-    explicit CommonEventMessage(const _LibObjPtr libObjPtr) noexcept :
-        _ThisCommonMessage {libObjPtr}
+    explicit CommonEventMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr}
     {
         BT_ASSERT_DBG(this->isEvent());
     }
@@ -712,6 +713,11 @@ public:
         return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
     }
 
+    OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
+    {
+        return bt_message_event_borrow_stream_class_default_clock_class_const(this->libObjPtr());
+    }
+
     ConstClockSnapshot defaultClockSnapshot() const noexcept
     {
         const auto libObjPtr =
@@ -776,14 +782,14 @@ template <typename LibObjT>
 class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
 {
 private:
-    using typename CommonMessage<LibObjT>::_LibObjPtr;
     using typename CommonMessage<LibObjT>::_ThisCommonMessage;
     using _Stream = internal::DepStream<LibObjT>;
 
 public:
+    using typename CommonMessage<LibObjT>::LibObjPtr;
     using Shared = SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
 
-    explicit CommonDiscardedEventsMessage(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonDiscardedEventsMessage(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonMessage {libObjPtr}
     {
         BT_ASSERT_DBG(this->isDiscardedEvents());
@@ -839,16 +845,15 @@ public:
         bt_message_discarded_events_set_count(this->libObjPtr(), count);
     }
 
-    nonstd::optional<std::uint64_t> count() const noexcept
+    bt2s::optional<std::uint64_t> count() const noexcept
     {
         std::uint64_t count;
-        const auto avail = bt_message_discarded_events_get_count(this->libObjPtr(), &count);
 
-        if (avail) {
+        if (bt_message_discarded_events_get_count(this->libObjPtr(), &count)) {
             return count;
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
     Shared shared() const noexcept
@@ -907,14 +912,14 @@ template <typename LibObjT>
 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
 {
 private:
-    using typename CommonMessage<LibObjT>::_LibObjPtr;
     using typename CommonMessage<LibObjT>::_ThisCommonMessage;
     using _Stream = internal::DepStream<LibObjT>;
 
 public:
+    using typename CommonMessage<LibObjT>::LibObjPtr;
     using Shared = SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
 
-    explicit CommonDiscardedPacketsMessage(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonDiscardedPacketsMessage(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonMessage {libObjPtr}
     {
         BT_ASSERT_DBG(this->isDiscardedPackets());
@@ -970,16 +975,15 @@ public:
         bt_message_discarded_packets_set_count(this->libObjPtr(), count);
     }
 
-    nonstd::optional<std::uint64_t> count() const noexcept
+    bt2s::optional<std::uint64_t> count() const noexcept
     {
         std::uint64_t count;
-        const auto avail = bt_message_discarded_packets_get_count(this->libObjPtr(), &count);
 
-        if (avail) {
+        if (bt_message_discarded_packets_get_count(this->libObjPtr(), &count)) {
             return count;
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
     Shared shared() const noexcept
@@ -1015,13 +1019,13 @@ template <typename LibObjT>
 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
 {
 private:
-    using typename CommonMessage<LibObjT>::_LibObjPtr;
     using typename CommonMessage<LibObjT>::_ThisCommonMessage;
 
 public:
+    using typename CommonMessage<LibObjT>::LibObjPtr;
     using Shared = SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
 
-    explicit CommonMessageIteratorInactivityMessage(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonMessageIteratorInactivityMessage(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonMessage {libObjPtr}
     {
         BT_ASSERT_DBG(this->isMessageIteratorInactivity());
@@ -1090,49 +1094,42 @@ struct TypeDescr<ConstMessageIteratorInactivityMessage> :
 template <typename LibObjT>
 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
 {
-    BT_ASSERT_DBG(this->isStreamBeginning());
     return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
 {
-    BT_ASSERT_DBG(this->isStreamEnd());
     return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
 {
-    BT_ASSERT_DBG(this->isPacketBeginning());
     return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
 {
-    BT_ASSERT_DBG(this->isPacketEnd());
     return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
 {
-    BT_ASSERT_DBG(this->isEvent());
     return CommonEventMessage<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
 {
-    BT_ASSERT_DBG(this->isDiscardedEvents());
     return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
 {
-    BT_ASSERT_DBG(this->isDiscardedPackets());
     return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
 }
 
@@ -1140,7 +1137,6 @@ template <typename LibObjT>
 CommonMessageIteratorInactivityMessage<LibObjT>
 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
 {
-    BT_ASSERT_DBG(this->isMessageIteratorInactivity());
     return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
 }
 
This page took 0.028289 seconds and 4 git commands to generate.