X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Fcpp-common%2Fbt2%2Fclock-class.hpp;h=ad033b0e5587b71fa72e8d1f235362f987ae011b;hb=72ff0d991279c51d053d528e1c011b526c9419f6;hp=ce306eef9340c2be414a01fa85ae15f6b4f8f3eb;hpb=b7ffa6f040d6609fce6f2fef81ee0c3792abc048;p=babeltrace.git diff --git a/src/cpp-common/bt2/clock-class.hpp b/src/cpp-common/bt2/clock-class.hpp index ce306eef..ad033b0e 100644 --- a/src/cpp-common/bt2/clock-class.hpp +++ b/src/cpp-common/bt2/clock-class.hpp @@ -8,14 +8,13 @@ #define BABELTRACE_CPP_COMMON_BT2_CLOCK_CLASS_HPP #include -#include #include #include -#include "cpp-common/optional.hpp" -#include "cpp-common/string_view.hpp" -#include "cpp-common/uuid-view.hpp" +#include "cpp-common/bt2c/c-string-view.hpp" +#include "cpp-common/bt2c/uuid.hpp" +#include "cpp-common/bt2s/optional.hpp" #include "borrowed-object.hpp" #include "exc.hpp" @@ -64,17 +63,14 @@ struct CommonClockClassSpec 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} { } - ClockClassOffset(const ClockClassOffset&) noexcept = default; - ClockClassOffset& operator=(const ClockClassOffset&) noexcept = default; - std::int64_t seconds() const noexcept { return _mSeconds; @@ -95,16 +91,13 @@ class CommonClockClass final : public BorrowedObject { private: using typename BorrowedObject::_ThisBorrowedObject; - using typename BorrowedObject::_LibObjPtr; - using _ThisCommonClockClass = CommonClockClass; public: - using Shared = SharedObject<_ThisCommonClockClass, LibObjT, internal::ClockClassRefFuncs>; - - using UserAttributes = - typename std::conditional::value, ConstMapValue, MapValue>::type; + using typename BorrowedObject::LibObjPtr; + using Shared = SharedObject; + using UserAttributes = internal::DepUserAttrs; - explicit CommonClockClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} + explicit CommonClockClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} { } @@ -115,17 +108,23 @@ public: } template - _ThisCommonClockClass& operator=(const CommonClockClass clkClass) noexcept + CommonClockClass& operator=(const CommonClockClass clkClass) noexcept { _ThisBorrowedObject::operator=(clkClass); return *this; } - void frequency(const std::uint64_t frequency) const noexcept + CommonClockClass asConst() const noexcept + { + return CommonClockClass {*this}; + } + + CommonClockClass frequency(const std::uint64_t frequency) const noexcept { - static_assert(!std::is_const::value, "`LibObjT` must NOT be `const`."); + static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); bt_clock_class_set_frequency(this->libObjPtr(), frequency); + return *this; } std::uint64_t frequency() const noexcept @@ -133,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::value, "`LibObjT` must NOT be `const`."); + static_assert(!std::is_const::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::value, "`LibObjT` must NOT be `const`."); + static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); bt_clock_class_set_precision(this->libObjPtr(), precision); + return *this; } std::uint64_t precision() const noexcept @@ -161,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::value, "`LibObjT` must NOT be `const`."); + static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); bt_clock_class_set_origin_is_unix_epoch(this->libObjPtr(), static_cast(originIsUnixEpoch)); + return *this; } bool originIsUnixEpoch() const noexcept @@ -174,82 +177,66 @@ public: return static_cast(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::value, "`LibObjT` must NOT be `const`."); + static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); const auto status = bt_clock_class_set_name(this->libObjPtr(), name); 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; } - nonstd::optional name() const noexcept + bt2c::CStringView 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 + CommonClockClass description(const bt2c::CStringView description) const { - static_assert(!std::is_const::value, "`LibObjT` must NOT be `const`."); + static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); const auto status = bt_clock_class_set_description(this->libObjPtr(), description); 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; } - nonstd::optional description() const noexcept + bt2c::CStringView 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 + CommonClockClass uuid(const bt2c::UuidView uuid) const noexcept { - bt_clock_class_set_uuid(this->libObjPtr(), uuid); + bt_clock_class_set_uuid(this->libObjPtr(), uuid.data()); + return *this; } - nonstd::optional uuid() const noexcept + bt2s::optional 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 - void userAttributes(const CommonMapValue userAttrs) const noexcept + CommonClockClass userAttributes(const CommonMapValue userAttrs) const noexcept { - static_assert(!std::is_const::value, "`LibObjT` must NOT be `const`."); + static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); bt_clock_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); + return *this; } UserAttributes userAttributes() const noexcept