cpp-common: add `bt2s::optional`, alias of `nonstd::optional`
[babeltrace.git] / src / cpp-common / bt2 / trace-ir.hpp
index 245a9d4fcaace4fbfe3564b6092ae1b6371d88d3..51e53732af752d98040c178ad83f38e8d99e4e2a 100644 (file)
@@ -12,8 +12,7 @@
 
 #include <babeltrace2/babeltrace.h>
 
-#include "cpp-common/optional.hpp"
-#include "cpp-common/string_view.hpp"
+#include "cpp-common/bt2s/optional.hpp"
 
 #include "borrowed-object.hpp"
 #include "clock-class.hpp"
@@ -151,7 +150,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonEvent<LibObjT>& operator=(const CommonEvent<OtherLibObjT> event) noexcept
+    CommonEvent<LibObjT> operator=(const CommonEvent<OtherLibObjT> event) noexcept
     {
         _ThisBorrowedObject::operator=(event);
         return *this;
@@ -164,9 +163,9 @@ public:
 
     Class cls() const noexcept;
     _Stream stream() const noexcept;
-    nonstd::optional<_Packet> packet() const noexcept;
+    bt2s::optional<_Packet> packet() const noexcept;
 
-    nonstd::optional<_StructureField> payloadField() const noexcept
+    bt2s::optional<_StructureField> payloadField() const noexcept
     {
         const auto libObjPtr = _Spec::payloadField(this->libObjPtr());
 
@@ -174,10 +173,10 @@ public:
             return _StructureField {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
-    nonstd::optional<_StructureField> specificContextField() const noexcept
+    bt2s::optional<_StructureField> specificContextField() const noexcept
     {
         const auto libObjPtr = _Spec::specificContextField(this->libObjPtr());
 
@@ -185,10 +184,10 @@ public:
             return _StructureField {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
-    nonstd::optional<_StructureField> commonContextField() const noexcept
+    bt2s::optional<_StructureField> commonContextField() const noexcept
     {
         const auto libObjPtr = _Spec::commonContextField(this->libObjPtr());
 
@@ -196,7 +195,7 @@ public:
             return _StructureField {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 };
 
@@ -276,12 +275,11 @@ private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
     using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonPacketSpec<LibObjT>;
-    using _ThisCommonPacket = CommonPacket<LibObjT>;
     using _Stream = internal::DepStream<LibObjT>;
     using _StructureField = internal::DepStructField<LibObjT>;
 
 public:
-    using Shared = SharedObject<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>;
+    using Shared = SharedObject<CommonPacket, LibObjT, internal::PacketRefFuncs>;
 
     explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
@@ -293,7 +291,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonPacket& operator=(const CommonPacket<OtherLibObjT> packet) noexcept
+    CommonPacket operator=(const CommonPacket<OtherLibObjT> packet) noexcept
     {
         _ThisBorrowedObject::operator=(packet);
         return *this;
@@ -306,7 +304,7 @@ public:
 
     _Stream stream() const noexcept;
 
-    nonstd::optional<_StructureField> contextField() const noexcept
+    bt2s::optional<_StructureField> contextField() const noexcept
     {
         const auto libObjPtr = _Spec::contextField(this->libObjPtr());
 
@@ -314,7 +312,7 @@ public:
             return _StructureField {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
     Shared shared() const noexcept
@@ -347,8 +345,7 @@ struct TypeDescr<ConstPacket> : public PacketTypeDescr
 } /* namespace internal */
 
 template <typename LibObjT>
-nonstd::optional<typename CommonEvent<LibObjT>::_Packet>
-CommonEvent<LibObjT>::packet() const noexcept
+bt2s::optional<typename CommonEvent<LibObjT>::_Packet> CommonEvent<LibObjT>::packet() const noexcept
 {
     const auto libObjPtr = _Spec::packet(this->libObjPtr());
 
@@ -356,7 +353,7 @@ CommonEvent<LibObjT>::packet() const noexcept
         return _Packet {libObjPtr};
     }
 
-    return nonstd::nullopt;
+    return bt2s::nullopt;
 }
 
 namespace internal {
@@ -426,11 +423,10 @@ private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
     using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonStreamSpec<LibObjT>;
-    using _ThisCommonStream = CommonStream<LibObjT>;
     using _Trace = internal::DepType<LibObjT, CommonTrace<bt_trace>, CommonTrace<const bt_trace>>;
 
 public:
-    using Shared = SharedObject<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>;
+    using Shared = SharedObject<CommonStream, LibObjT, internal::StreamRefFuncs>;
     using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
     using Class = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
@@ -446,7 +442,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonStream& operator=(const CommonStream<OtherLibObjT> stream) noexcept
+    CommonStream operator=(const CommonStream<OtherLibObjT> stream) noexcept
     {
         _ThisBorrowedObject::operator=(stream);
         return *this;
@@ -491,15 +487,9 @@ public:
         this->name(name.data());
     }
 
-    nonstd::optional<bpstd::string_view> name() const noexcept
+    const char *name() const noexcept
     {
-        const auto name = bt_stream_get_name(this->libObjPtr());
-
-        if (name) {
-            return name;
-        }
-
-        return nonstd::nullopt;
+        return bt_stream_get_name(this->libObjPtr());
     }
 
     template <typename LibValT>
@@ -635,11 +625,10 @@ private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
     using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonTraceSpec<LibObjT>;
-    using _ThisCommonTrace = CommonTrace<LibObjT>;
     using _Stream = internal::DepStream<LibObjT>;
 
 public:
-    using Shared = SharedObject<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>;
+    using Shared = SharedObject<CommonTrace, LibObjT, internal::TraceRefFuncs>;
     using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
     using Class = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
@@ -647,7 +636,7 @@ public:
 
     struct ConstEnvironmentEntry
     {
-        bpstd::string_view name;
+        const char *name;
         ConstValue value;
     };
 
@@ -661,7 +650,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonTrace& operator=(const CommonTrace<OtherLibObjT> trace) noexcept
+    CommonTrace operator=(const CommonTrace<OtherLibObjT> trace) noexcept
     {
         _ThisBorrowedObject::operator=(trace);
         return *this;
@@ -690,31 +679,25 @@ public:
         this->name(name.data());
     }
 
-    nonstd::optional<bpstd::string_view> name() const noexcept
+    const char *name() const noexcept
     {
-        const auto name = bt_trace_get_name(this->libObjPtr());
-
-        if (name) {
-            return name;
-        }
-
-        return nonstd::nullopt;
+        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
@@ -727,7 +710,7 @@ public:
         return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
     }
 
-    nonstd::optional<_Stream> streamById(const std::uint64_t id) const noexcept
+    bt2s::optional<_Stream> streamById(const std::uint64_t id) const noexcept
     {
         const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id);
 
@@ -735,7 +718,7 @@ public:
             return _Stream {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
     void environmentEntry(const char * const name, const std::int64_t val) const
@@ -795,7 +778,7 @@ public:
         return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
     }
 
-    nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept
+    bt2s::optional<ConstValue> environmentEntry(const char * const name) const noexcept
     {
         const auto libObjPtr =
             bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
@@ -804,10 +787,10 @@ public:
             return ConstValue {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
-    nonstd::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
+    bt2s::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
     {
         return this->environmentEntry(name.data());
     }
@@ -941,15 +924,13 @@ private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
     using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonEventClassSpec<LibObjT>;
-    using _ThisCommonEventClass = CommonEventClass<LibObjT>;
     using _StructureFieldClass = internal::DepStructFc<LibObjT>;
 
     using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
                                            CommonStreamClass<const bt_stream_class>>;
 
 public:
-    using Shared = SharedObject<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>;
-
+    using Shared = SharedObject<CommonEventClass, LibObjT, internal::EventClassRefFuncs>;
     using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
     enum class LogLevel
@@ -982,7 +963,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonEventClass& operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
+    CommonEventClass operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
     {
         _ThisBorrowedObject::operator=(eventClass);
         return *this;
@@ -1016,15 +997,9 @@ public:
         this->name(name.data());
     }
 
-    nonstd::optional<bpstd::string_view> name() const noexcept
+    const char *name() const noexcept
     {
-        const auto name = bt_event_class_get_name(this->libObjPtr());
-
-        if (name) {
-            return name;
-        }
-
-        return nonstd::nullopt;
+        return bt_event_class_get_name(this->libObjPtr());
     }
 
     void logLevel(const LogLevel logLevel) const noexcept
@@ -1035,7 +1010,7 @@ 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);
@@ -1044,7 +1019,7 @@ public:
             return static_cast<LogLevel>(libLogLevel);
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
     void emfUri(const char * const emfUri) const
@@ -1063,15 +1038,9 @@ public:
         this->emfUri(emfUri.data());
     }
 
-    nonstd::optional<bpstd::string_view> emfUri() const noexcept
+    const char *emfUri() const noexcept
     {
-        const auto emfUri = bt_event_class_get_emf_uri(this->libObjPtr());
-
-        if (emfUri) {
-            return emfUri;
-        }
-
-        return nonstd::nullopt;
+        return bt_event_class_get_emf_uri(this->libObjPtr());
     }
 
     void payloadFieldClass(const StructureFieldClass fc) const
@@ -1086,7 +1055,7 @@ public:
         }
     }
 
-    nonstd::optional<_StructureFieldClass> payloadFieldClass() const noexcept
+    bt2s::optional<_StructureFieldClass> payloadFieldClass() const noexcept
     {
         const auto libObjPtr = _Spec::payloadFieldClass(this->libObjPtr());
 
@@ -1094,7 +1063,7 @@ public:
             return _StructureFieldClass {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
     void specificContextFieldClass(const StructureFieldClass fc) const
@@ -1109,7 +1078,7 @@ public:
         }
     }
 
-    nonstd::optional<_StructureFieldClass> specificContextFieldClass() const noexcept
+    bt2s::optional<_StructureFieldClass> specificContextFieldClass() const noexcept
     {
         const auto libObjPtr = _Spec::specificContextFieldClass(this->libObjPtr());
 
@@ -1117,7 +1086,7 @@ public:
             return _StructureFieldClass {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
     template <typename LibValT>
@@ -1281,7 +1250,6 @@ private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
     using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonStreamClassSpec<LibObjT>;
-    using _ThisCommonStreamClass = CommonStreamClass<LibObjT>;
     using _StructureFieldClass = internal::DepStructFc<LibObjT>;
 
     using _TraceClass = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
@@ -1293,8 +1261,7 @@ private:
     using _ClockClass = internal::DepType<LibObjT, ClockClass, ConstClockClass>;
 
 public:
-    using Shared = SharedObject<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
-
+    using Shared = SharedObject<CommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
     using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
     explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept :
@@ -1309,7 +1276,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
+    CommonStreamClass operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
     {
         _ThisBorrowedObject::operator=(streamClass);
         return *this;
@@ -1388,15 +1355,9 @@ public:
         this->name(name.data());
     }
 
-    nonstd::optional<bpstd::string_view> name() const noexcept
+    const char *name() const noexcept
     {
-        const auto name = bt_stream_class_get_name(this->libObjPtr());
-
-        if (name) {
-            return name;
-        }
-
-        return nonstd::nullopt;
+        return bt_stream_class_get_name(this->libObjPtr());
     }
 
     void assignsAutomaticEventClassId(const bool val) const noexcept
@@ -1512,7 +1473,7 @@ public:
         BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
     }
 
-    nonstd::optional<_ClockClass> defaultClockClass() const noexcept
+    bt2s::optional<_ClockClass> defaultClockClass() const noexcept
     {
         const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr());
 
@@ -1520,7 +1481,7 @@ public:
             return _ClockClass {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
     std::uint64_t length() const noexcept
@@ -1533,7 +1494,7 @@ public:
         return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
     }
 
-    nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) const noexcept
+    bt2s::optional<_EventClass> eventClassById(const std::uint64_t id) const noexcept
     {
         const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id);
 
@@ -1541,7 +1502,7 @@ public:
             return _EventClass {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
     void packetContextFieldClass(const StructureFieldClass fc) const
@@ -1557,7 +1518,7 @@ public:
         }
     }
 
-    nonstd::optional<_StructureFieldClass> packetContextFieldClass() const noexcept
+    bt2s::optional<_StructureFieldClass> packetContextFieldClass() const noexcept
     {
         const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr());
 
@@ -1565,7 +1526,7 @@ public:
             return _StructureFieldClass {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
     void eventCommonContextFieldClass(const StructureFieldClass fc) const
@@ -1581,7 +1542,7 @@ public:
         }
     }
 
-    nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
+    bt2s::optional<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
     {
         const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr());
 
@@ -1589,7 +1550,7 @@ public:
             return _StructureFieldClass {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
     template <typename LibValT>
@@ -1719,14 +1680,12 @@ private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
     using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonTraceClassSpec<LibObjT>;
-    using _ThisCommonTraceClass = CommonTraceClass<LibObjT>;
 
     using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
                                            CommonStreamClass<const bt_stream_class>>;
 
 public:
-    using Shared = SharedObject<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
-
+    using Shared = SharedObject<CommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
     using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
     explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
@@ -1740,7 +1699,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
+    CommonTraceClass operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
     {
         _ThisBorrowedObject::operator=(traceClass);
         return *this;
@@ -2021,7 +1980,7 @@ public:
         return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
     }
 
-    nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
+    bt2s::optional<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
     {
         const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id);
 
@@ -2029,7 +1988,7 @@ public:
             return _StreamClass {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
     template <typename LibValT>
This page took 0.044106 seconds and 4 git commands to generate.