cpp-common: add `bt2s::optional`, alias of `nonstd::optional`
[babeltrace.git] / src / cpp-common / bt2 / clock-class.hpp
index b101ee66f4c9e985170ed2e548f37fe9cccddbc3..6d99ed1f1fc0a8cdba7883d5d7f9ce0b195e0239 100644 (file)
@@ -13,9 +13,8 @@
 
 #include <babeltrace2/babeltrace.h>
 
-#include "cpp-common/optional.hpp"
-#include "cpp-common/string_view.hpp"
-#include "cpp-common/uuid-view.hpp"
+#include "cpp-common/bt2c/uuid-view.hpp"
+#include "cpp-common/bt2s/optional.hpp"
 
 #include "borrowed-object.hpp"
 #include "exc.hpp"
@@ -72,9 +71,6 @@ public:
     {
     }
 
-    ClockClassOffset(const ClockClassOffset&) noexcept = default;
-    ClockClassOffset& operator=(const ClockClassOffset&) noexcept = default;
-
     std::int64_t seconds() const noexcept
     {
         return _mSeconds;
@@ -96,13 +92,10 @@ class CommonClockClass final : public BorrowedObject<LibObjT>
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
     using typename BorrowedObject<LibObjT>::_LibObjPtr;
-    using _ThisCommonClockClass = CommonClockClass<LibObjT>;
 
 public:
-    using Shared = SharedObject<_ThisCommonClockClass, LibObjT, internal::ClockClassRefFuncs>;
-
-    using UserAttributes =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
+    using Shared = SharedObject<CommonClockClass, LibObjT, internal::ClockClassRefFuncs>;
+    using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
     explicit CommonClockClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
@@ -115,7 +108,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonClockClass& operator=(const CommonClockClass<OtherLibObjT> clkClass) noexcept
+    CommonClockClass& operator=(const CommonClockClass<OtherLibObjT> clkClass) noexcept
     {
         _ThisBorrowedObject::operator=(clkClass);
         return *this;
@@ -128,7 +121,7 @@ public:
 
     void frequency(const std::uint64_t frequency) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstClockClass`.");
 
         bt_clock_class_set_frequency(this->libObjPtr(), frequency);
     }
@@ -140,7 +133,7 @@ public:
 
     void offset(const ClockClassOffset& offset) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstClockClass`.");
 
         bt_clock_class_set_offset(this->libObjPtr(), offset.seconds(), offset.cycles());
     }
@@ -156,7 +149,7 @@ public:
 
     void precision(const std::uint64_t precision) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstClockClass`.");
 
         bt_clock_class_set_precision(this->libObjPtr(), precision);
     }
@@ -168,7 +161,7 @@ public:
 
     void originIsUnixEpoch(const bool originIsUnixEpoch) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstClockClass`.");
 
         bt_clock_class_set_origin_is_unix_epoch(this->libObjPtr(),
                                                 static_cast<bt_bool>(originIsUnixEpoch));
@@ -181,7 +174,7 @@ public:
 
     void name(const char * const name) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstClockClass`.");
 
         const auto status = bt_clock_class_set_name(this->libObjPtr(), name);
 
@@ -195,20 +188,14 @@ public:
         this->name(name.data());
     }
 
-    nonstd::optional<bpstd::string_view> name() const noexcept
+    const char *name() const noexcept
     {
-        const auto name = bt_clock_class_get_name(this->libObjPtr());
-
-        if (name) {
-            return name;
-        }
-
-        return nonstd::nullopt;
+        return bt_clock_class_get_name(this->libObjPtr());
     }
 
     void description(const char * const description) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstClockClass`.");
 
         const auto status = bt_clock_class_set_description(this->libObjPtr(), description);
 
@@ -222,15 +209,9 @@ public:
         this->description(description.data());
     }
 
-    nonstd::optional<bpstd::string_view> description() const noexcept
+    const char *description() const noexcept
     {
-        const auto description = bt_clock_class_get_description(this->libObjPtr());
-
-        if (description) {
-            return description;
-        }
-
-        return nonstd::nullopt;
+        return bt_clock_class_get_description(this->libObjPtr());
     }
 
     void uuid(const std::uint8_t * const uuid) const noexcept
@@ -238,21 +219,21 @@ public:
         bt_clock_class_set_uuid(this->libObjPtr(), uuid);
     }
 
-    nonstd::optional<bt2_common::UuidView> uuid() const noexcept
+    bt2s::optional<bt2c::UuidView> uuid() const noexcept
     {
         const auto uuid = bt_clock_class_get_uuid(this->libObjPtr());
 
         if (uuid) {
-            return bt2_common::UuidView {uuid};
+            return bt2c::UuidView {uuid};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
     template <typename LibValT>
     void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstClockClass`.");
 
         bt_clock_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
     }
This page took 0.025892 seconds and 4 git commands to generate.