doc/api/libbabeltrace2/DoxygenLayout.xml: use `topics` tab
[babeltrace.git] / src / cpp-common / bt2 / clock-class.hpp
index 2c58770b6af48ce639c618a55a4d9725fdde45cb..5b80890d2e7deaf936bf64872afa35f54e04cbf8 100644 (file)
@@ -8,11 +8,11 @@
 #define BABELTRACE_CPP_COMMON_BT2_CLOCK_CLASS_HPP
 
 #include <cstdint>
-#include <string>
 #include <type_traits>
 
 #include <babeltrace2/babeltrace.h>
 
+#include "cpp-common/bt2c/c-string-view.hpp"
 #include "cpp-common/bt2c/uuid.hpp"
 #include "cpp-common/bt2s/optional.hpp"
 
@@ -63,10 +63,10 @@ struct CommonClockClassSpec<const bt_clock_class> final
 
 } /* namespace internal */
 
-class ClockClassOffset final
+class ClockOffset final
 {
 public:
-    explicit ClockClassOffset(const std::int64_t seconds, const std::uint64_t cycles) :
+    explicit ClockOffset(const std::int64_t seconds, const std::uint64_t cycles) :
         _mSeconds {seconds}, _mCycles {cycles}
     {
     }
@@ -91,13 +91,13 @@ class CommonClockClass final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
 
 public:
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
     using Shared = SharedObject<CommonClockClass, LibObjT, internal::ClockClassRefFuncs>;
     using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
-    explicit CommonClockClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonClockClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -119,11 +119,12 @@ public:
         return CommonClockClass<const bt_clock_class> {*this};
     }
 
-    void frequency(const std::uint64_t frequency) const noexcept
+    CommonClockClass frequency(const std::uint64_t frequency) const noexcept
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstClockClass`.");
 
         bt_clock_class_set_frequency(this->libObjPtr(), frequency);
+        return *this;
     }
 
     std::uint64_t frequency() const noexcept
@@ -131,27 +132,30 @@ public:
         return bt_clock_class_get_frequency(this->libObjPtr());
     }
 
-    void offset(const ClockClassOffset& offset) const noexcept
+    CommonClockClass offsetFromOrigin(const ClockOffset& offsetFromOrigin) const noexcept
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstClockClass`.");
 
-        bt_clock_class_set_offset(this->libObjPtr(), offset.seconds(), offset.cycles());
+        bt_clock_class_set_offset(this->libObjPtr(), offsetFromOrigin.seconds(),
+                                  offsetFromOrigin.cycles());
+        return *this;
     }
 
-    ClockClassOffset offset() const noexcept
+    ClockOffset offsetFromOrigin() const noexcept
     {
         std::int64_t seconds;
         std::uint64_t cycles;
 
         bt_clock_class_get_offset(this->libObjPtr(), &seconds, &cycles);
-        return ClockClassOffset {seconds, cycles};
+        return ClockOffset {seconds, cycles};
     }
 
-    void precision(const std::uint64_t precision) const noexcept
+    CommonClockClass precision(const std::uint64_t precision) const noexcept
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstClockClass`.");
 
         bt_clock_class_set_precision(this->libObjPtr(), precision);
+        return *this;
     }
 
     std::uint64_t precision() const noexcept
@@ -159,12 +163,13 @@ public:
         return bt_clock_class_get_precision(this->libObjPtr());
     }
 
-    void originIsUnixEpoch(const bool originIsUnixEpoch) const noexcept
+    CommonClockClass originIsUnixEpoch(const bool originIsUnixEpoch) const noexcept
     {
         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));
+        return *this;
     }
 
     bool originIsUnixEpoch() const noexcept
@@ -172,7 +177,7 @@ public:
         return static_cast<bool>(bt_clock_class_origin_is_unix_epoch(this->libObjPtr()));
     }
 
-    void name(const char * const name) const
+    CommonClockClass name(const bt2c::CStringView name) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstClockClass`.");
 
@@ -181,19 +186,16 @@ public:
         if (status == BT_CLOCK_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
             throw MemoryError {};
         }
-    }
 
-    void name(const std::string& name) const
-    {
-        this->name(name.data());
+        return *this;
     }
 
-    const char *name() const noexcept
+    bt2c::CStringView name() const noexcept
     {
         return bt_clock_class_get_name(this->libObjPtr());
     }
 
-    void description(const char * const description) const
+    CommonClockClass description(const bt2c::CStringView description) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstClockClass`.");
 
@@ -202,21 +204,21 @@ public:
         if (status == BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_MEMORY_ERROR) {
             throw MemoryError {};
         }
-    }
 
-    void description(const std::string& description) const
-    {
-        this->description(description.data());
+        return *this;
     }
 
-    const char *description() const noexcept
+    bt2c::CStringView description() const noexcept
     {
         return bt_clock_class_get_description(this->libObjPtr());
     }
 
-    void uuid(const std::uint8_t * const uuid) const noexcept
+    CommonClockClass uuid(const bt2c::UuidView uuid) const noexcept
     {
-        bt_clock_class_set_uuid(this->libObjPtr(), uuid);
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstClockClass`.");
+
+        bt_clock_class_set_uuid(this->libObjPtr(), uuid.data());
+        return *this;
     }
 
     bt2s::optional<bt2c::UuidView> uuid() const noexcept
@@ -231,11 +233,12 @@ public:
     }
 
     template <typename LibValT>
-    void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
+    CommonClockClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstClockClass`.");
 
         bt_clock_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
+        return *this;
     }
 
     UserAttributes userAttributes() const noexcept
This page took 0.026341 seconds and 4 git commands to generate.