projects
/
babeltrace.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
cpp-common/bt2: add static_assert in `CommonClockClass::uuid(const std::uint8_t *)`
[babeltrace.git]
/
src
/
cpp-common
/
bt2
/
clock-class.hpp
diff --git
a/src/cpp-common/bt2/clock-class.hpp
b/src/cpp-common/bt2/clock-class.hpp
index b236764510e437808965aab6b8f9b4cee1f989cb..5b80890d2e7deaf936bf64872afa35f54e04cbf8 100644
(file)
--- a/
src/cpp-common/bt2/clock-class.hpp
+++ b/
src/cpp-common/bt2/clock-class.hpp
@@
-8,33
+8,31
@@
#define BABELTRACE_CPP_COMMON_BT2_CLOCK_CLASS_HPP
#include <cstdint>
#define BABELTRACE_CPP_COMMON_BT2_CLOCK_CLASS_HPP
#include <cstdint>
-#include <string>
#include <type_traits>
#include <babeltrace2/babeltrace.h>
#include <type_traits>
#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/c-string-view
.hpp"
+#include "cpp-common/
bt2c/uuid
.hpp"
+#include "cpp-common/
bt2s/optional
.hpp"
+#include "borrowed-object.hpp"
#include "exc.hpp"
#include "exc.hpp"
-#include "internal/borrowed-obj.hpp"
-#include "internal/shared-obj.hpp"
#include "internal/utils.hpp"
#include "internal/utils.hpp"
+#include "shared-object.hpp"
#include "value.hpp"
namespace bt2 {
#include "value.hpp"
namespace bt2 {
-
namespace internal {
struct ClockClassRefFuncs final
{
namespace internal {
struct ClockClassRefFuncs final
{
- static void get(const bt_clock_class * const libObjPtr)
+ static void get(const bt_clock_class * const libObjPtr)
noexcept
{
bt_clock_class_get_ref(libObjPtr);
}
{
bt_clock_class_get_ref(libObjPtr);
}
- static void put(const bt_clock_class * const libObjPtr)
+ static void put(const bt_clock_class * const libObjPtr)
noexcept
{
bt_clock_class_put_ref(libObjPtr);
}
{
bt_clock_class_put_ref(libObjPtr);
}
@@
-65,17
+63,14
@@
struct CommonClockClassSpec<const bt_clock_class> final
} /* namespace internal */
} /* namespace internal */
-class Clock
Class
Offset final
+class ClockOffset final
{
public:
{
public:
- explicit Clock
Class
Offset(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}
{
}
_mSeconds {seconds}, _mCycles {cycles}
{
}
- ClockClassOffset(const ClockClassOffset&) noexcept = default;
- ClockClassOffset& operator=(const ClockClassOffset&) noexcept = default;
-
std::int64_t seconds() const noexcept
{
return _mSeconds;
std::int64_t seconds() const noexcept
{
return _mSeconds;
@@
-92,42
+87,44
@@
private:
};
template <typename LibObjT>
};
template <typename LibObjT>
-class CommonClockClass final : public
internal::BorrowedObj
<LibObjT>
+class CommonClockClass final : public
BorrowedObject
<LibObjT>
{
private:
{
private:
- using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
- using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
- using _ThisCommonClockClass = CommonClockClass<LibObjT>;
+ using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
public:
public:
- using Shared =
- internal::SharedObj<_ThisCommonClockClass, LibObjT, internal::ClockClassRefFuncs>;
+ using typename BorrowedObject<LibObjT>::LibObjPtr;
+ using Shared = SharedObject<CommonClockClass, LibObjT, internal::ClockClassRefFuncs>;
+ using UserAttributes = internal::DepUserAttrs<LibObjT>;
- using UserAttributes =
- typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
-
- explicit CommonClockClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
+ explicit CommonClockClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
{
}
template <typename OtherLibObjT>
CommonClockClass(const CommonClockClass<OtherLibObjT> clkClass) noexcept :
{
}
template <typename OtherLibObjT>
CommonClockClass(const CommonClockClass<OtherLibObjT> clkClass) noexcept :
- _ThisBorrowedObj {clkClass}
+ _ThisBorrowedObj
ect
{clkClass}
{
}
template <typename OtherLibObjT>
{
}
template <typename OtherLibObjT>
-
_This
CommonClockClass& operator=(const CommonClockClass<OtherLibObjT> clkClass) noexcept
+ CommonClockClass& operator=(const CommonClockClass<OtherLibObjT> clkClass) noexcept
{
{
- _ThisBorrowedObj::operator=(clkClass);
+ _ThisBorrowedObj
ect
::operator=(clkClass);
return *this;
}
return *this;
}
-
void frequency(const std::uint64_t frequency)
noexcept
+
CommonClockClass<const bt_clock_class> asConst() const
noexcept
{
{
- static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+ return CommonClockClass<const bt_clock_class> {*this};
+ }
+
+ 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);
bt_clock_class_set_frequency(this->libObjPtr(), frequency);
+ return *this;
}
std::uint64_t frequency() const noexcept
}
std::uint64_t frequency() const noexcept
@@
-135,27
+132,30
@@
public:
return bt_clock_class_get_frequency(this->libObjPtr());
}
return bt_clock_class_get_frequency(this->libObjPtr());
}
-
void offset(const ClockClassOffset& offset)
noexcept
+
CommonClockClass offsetFromOrigin(const ClockOffset& offsetFromOrigin) 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());
+ bt_clock_class_set_offset(this->libObjPtr(), offsetFromOrigin.seconds(),
+ offsetFromOrigin.cycles());
+ return *this;
}
}
- Clock
ClassOffset offset
() const noexcept
+ Clock
Offset offsetFromOrigin
() const noexcept
{
std::int64_t seconds;
std::uint64_t cycles;
bt_clock_class_get_offset(this->libObjPtr(), &seconds, &cycles);
{
std::int64_t seconds;
std::uint64_t cycles;
bt_clock_class_get_offset(this->libObjPtr(), &seconds, &cycles);
- return Clock
Class
Offset {seconds, cycles};
+ return ClockOffset {seconds, cycles};
}
}
-
void precision(const std::uint64_t precision)
noexcept
+
CommonClockClass 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);
bt_clock_class_set_precision(this->libObjPtr(), precision);
+ return *this;
}
std::uint64_t precision() const noexcept
}
std::uint64_t precision() const noexcept
@@
-163,12
+163,13
@@
public:
return bt_clock_class_get_precision(this->libObjPtr());
}
return bt_clock_class_get_precision(this->libObjPtr());
}
-
void originIsUnixEpoch(const bool originIsUnixEpoch)
noexcept
+
CommonClockClass 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));
bt_clock_class_set_origin_is_unix_epoch(this->libObjPtr(),
static_cast<bt_bool>(originIsUnixEpoch));
+ return *this;
}
bool originIsUnixEpoch() const noexcept
}
bool originIsUnixEpoch() const noexcept
@@
-176,91
+177,71
@@
public:
return static_cast<bool>(bt_clock_class_origin_is_unix_epoch(this->libObjPtr()));
}
return static_cast<bool>(bt_clock_class_origin_is_unix_epoch(this->libObjPtr()));
}
- void name(const char * const name)
+ CommonClockClass name(const bt2c::CStringView 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);
if (status == BT_CLOCK_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
throw MemoryError {};
}
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)
- {
- this->name(name.data());
+ return *this;
}
}
-
nonstd::optional<bpstd::string_view>
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)
+ CommonClockClass description(const bt2c::CStringView 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);
if (status == BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_MEMORY_ERROR) {
throw MemoryError {};
}
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)
- {
- this->description(description.data());
+ return *this;
}
}
-
nonstd::optional<bpstd::string_view>
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)
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;
}
}
-
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) {
{
const auto uuid = bt_clock_class_get_uuid(this->libObjPtr());
if (uuid) {
- return bt2
_common
::UuidView {uuid};
+ return bt2
c
::UuidView {uuid};
}
}
- return
nonstd
::nullopt;
+ return
bt2s
::nullopt;
}
template <typename LibValT>
}
template <typename LibValT>
- void userAttributes(const CommonMapValue<LibValT> userAttrs)
+ CommonClockClass 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());
bt_clock_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
+ return *this;
}
}
- ConstMapValue userAttributes() const noexcept
- {
- return ConstMapValue {internal::CommonClockClassSpec<const bt_clock_class>::userAttributes(
- this->libObjPtr())};
- }
-
- UserAttributes userAttributes() noexcept
+ UserAttributes userAttributes() const noexcept
{
return UserAttributes {
internal::CommonClockClassSpec<LibObjT>::userAttributes(this->libObjPtr())};
{
return UserAttributes {
internal::CommonClockClassSpec<LibObjT>::userAttributes(this->libObjPtr())};
This page took
0.028399 seconds
and
4
git commands to generate.