#include "field-path.hpp"
#include "integer-range-set.hpp"
#include "internal/utils.hpp"
+#include "optional-borrowed-object.hpp"
#include "shared-object.hpp"
#include "value.hpp"
this->libObjPtr(), index)};
}
- bt2s::optional<Mapping> operator[](const char * const label) const noexcept
+ OptionalBorrowedObject<Mapping> operator[](const char * const label) const noexcept
{
- const auto libObjPtr = internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel(
+ return internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel(
this->libObjPtr(), label);
-
- if (libObjPtr) {
- return Mapping {libObjPtr};
- }
-
- return bt2s::nullopt;
}
- bt2s::optional<Mapping> operator[](const std::string& label) const noexcept
+ OptionalBorrowedObject<Mapping> operator[](const std::string& label) const noexcept
{
return (*this)[label.data()];
}
this->libObjPtr(), index)};
}
- bt2s::optional<Member> operator[](const char * const name) const noexcept
+ OptionalBorrowedObject<Member> operator[](const char * const name) const noexcept
{
- const auto libObjPtr =
- internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(this->libObjPtr(), name);
-
- if (libObjPtr) {
- return Member {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(this->libObjPtr(),
+ name);
}
- bt2s::optional<Member> operator[](const std::string& name) const noexcept
+ OptionalBorrowedObject<Member> operator[](const std::string& name) const noexcept
{
return (*this)[name.data()];
}
this->libObjPtr(), index)};
}
- bt2s::optional<Option> operator[](const char * const name) const noexcept
+ OptionalBorrowedObject<Option> operator[](const char * const name) const noexcept
{
- const auto libObjPtr =
- internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(), name);
-
- if (libObjPtr) {
- return Option {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(),
+ name);
}
- bt2s::optional<Option> operator[](const std::string& name) const noexcept
+ OptionalBorrowedObject<Option> operator[](const std::string& name) const noexcept
{
return (*this)[name.data()];
}
return Option {_Spec::optionByIndex(this->libObjPtr(), index)};
}
- bt2s::optional<Option> operator[](const char * const name) const noexcept
+ OptionalBorrowedObject<Option> operator[](const char * const name) const noexcept
{
- const auto libObjPtr = _Spec::optionByName(this->libObjPtr(), name);
-
- if (libObjPtr) {
- return Option {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::optionByName(this->libObjPtr(), name);
}
- bt2s::optional<Option> operator[](const std::string& name) const noexcept
+ OptionalBorrowedObject<Option> operator[](const std::string& name) const noexcept
{
return (*this)[name.data()];
}
#include <babeltrace2/babeltrace.h>
#include "common/assert.h"
-#include "cpp-common/bt2s/optional.hpp"
#include "borrowed-object.hpp"
#include "field-class.hpp"
#include "internal/utils.hpp"
+#include "optional-borrowed-object.hpp"
#include "raw-value-proxy.hpp"
namespace bt2 {
return CommonField<LibObjT> {_Spec::memberFieldByIndex(this->libObjPtr(), index)};
}
- bt2s::optional<CommonField<LibObjT>> operator[](const char * const name) const noexcept
+ OptionalBorrowedObject<CommonField<LibObjT>> operator[](const char * const name) const noexcept
{
- const auto libObjPtr = _Spec::memberFieldByName(this->libObjPtr(), name);
-
- if (libObjPtr) {
- return CommonField<LibObjT> {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::memberFieldByName(this->libObjPtr(), name);
}
- bt2s::optional<CommonField<LibObjT>> operator[](const std::string& name) const noexcept
+ OptionalBorrowedObject<CommonField<LibObjT>> operator[](const std::string& name) const noexcept
{
return (*this)[name.data()];
}
return this->field().has_value();
}
- bt2s::optional<CommonField<LibObjT>> field() const noexcept
+ OptionalBorrowedObject<CommonField<LibObjT>> field() const noexcept
{
- const auto libObjPtr = _Spec::field(this->libObjPtr());
-
- if (libObjPtr) {
- return CommonField<LibObjT> {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::field(this->libObjPtr());
}
};
#include "borrowed-object.hpp"
#include "internal/utils.hpp"
+#include "optional-borrowed-object.hpp"
#include "shared-object.hpp"
namespace bt2 {
bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
}
- bt2s::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
+ OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
{
const bt_clock_snapshot *libObjPtr;
const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
this->libObjPtr(), &libObjPtr);
if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
- return ConstClockSnapshot {libObjPtr};
+ return libObjPtr;
}
- return bt2s::nullopt;
+ return {};
}
Shared shared() const noexcept
bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
}
- bt2s::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
+ OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
{
const bt_clock_snapshot *libObjPtr;
const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
this->libObjPtr(), &libObjPtr);
if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
- return ConstClockSnapshot {libObjPtr};
+ return libObjPtr;
}
- return bt2s::nullopt;
+ return {};
}
Shared shared() const noexcept
return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
}
- bt2s::optional<ConstClockClass> streamClassDefaultClockClass() const noexcept
+ OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
{
- if (const auto libClkClsPtr =
- bt_message_event_borrow_stream_class_default_clock_class_const(this->libObjPtr())) {
- return ConstClockClass {libClkClsPtr};
- }
-
- return bt2s::nullopt;
+ return bt_message_event_borrow_stream_class_default_clock_class_const(this->libObjPtr());
}
ConstClockSnapshot defaultClockSnapshot() const noexcept
#ifndef BABELTRACE_CPP_COMMON_BT2_SHARED_OBJECT_HPP
#define BABELTRACE_CPP_COMMON_BT2_SHARED_OBJECT_HPP
+#include <utility>
+
#include "common/assert.h"
-#include "cpp-common/bt2s/optional.hpp"
+
+#include "optional-borrowed-object.hpp"
namespace bt2 {
this->_putRef();
}
- ObjT& operator*() noexcept
- {
- BT_ASSERT_DBG(_mObj);
- return *_mObj;
- }
-
- const ObjT& operator*() const noexcept
+ ObjT operator*() const noexcept
{
BT_ASSERT_DBG(_mObj);
return *_mObj;
}
- ObjT *operator->() noexcept
+ BorrowedObjectProxy<ObjT> operator->() const noexcept
{
BT_ASSERT_DBG(_mObj);
- return &*_mObj;
- }
-
- const ObjT *operator->() const noexcept
- {
- BT_ASSERT_DBG(_mObj);
- return &*_mObj;
+ return _mObj.operator->();
}
operator bool() const noexcept
{
- return _mObj.has_value();
+ return _mObj.hasObject();
}
/*
*/
void _getRef() const noexcept
{
- if (_mObj) {
- RefFuncsT::get(_mObj->libObjPtr());
- }
+ RefFuncsT::get(_mObj.libObjPtr());
}
/*
*/
void _putRef() const noexcept
{
- if (_mObj) {
- RefFuncsT::put(_mObj->libObjPtr());
- }
+ RefFuncsT::put(_mObj.libObjPtr());
}
- bt2s::optional<ObjT> _mObj;
+ OptionalBorrowedObject<ObjT> _mObj;
};
} /* namespace bt2 */
#include "field-class.hpp"
#include "field.hpp"
#include "internal/utils.hpp"
+#include "optional-borrowed-object.hpp"
#include "shared-object.hpp"
#include "value.hpp"
Class cls() const noexcept;
_Stream stream() const noexcept;
- bt2s::optional<_Packet> packet() const noexcept;
+ OptionalBorrowedObject<_Packet> packet() const noexcept;
- bt2s::optional<_StructureField> payloadField() const noexcept
+ OptionalBorrowedObject<_StructureField> payloadField() const noexcept
{
- const auto libObjPtr = _Spec::payloadField(this->libObjPtr());
-
- if (libObjPtr) {
- return _StructureField {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::payloadField(this->libObjPtr());
}
- bt2s::optional<_StructureField> specificContextField() const noexcept
+ OptionalBorrowedObject<_StructureField> specificContextField() const noexcept
{
- const auto libObjPtr = _Spec::specificContextField(this->libObjPtr());
-
- if (libObjPtr) {
- return _StructureField {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::specificContextField(this->libObjPtr());
}
- bt2s::optional<_StructureField> commonContextField() const noexcept
+ OptionalBorrowedObject<_StructureField> commonContextField() const noexcept
{
- const auto libObjPtr = _Spec::commonContextField(this->libObjPtr());
-
- if (libObjPtr) {
- return _StructureField {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::commonContextField(this->libObjPtr());
}
};
_Stream stream() const noexcept;
- bt2s::optional<_StructureField> contextField() const noexcept
+ OptionalBorrowedObject<_StructureField> contextField() const noexcept
{
- const auto libObjPtr = _Spec::contextField(this->libObjPtr());
-
- if (libObjPtr) {
- return _StructureField {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::contextField(this->libObjPtr());
}
Shared shared() const noexcept
} /* namespace internal */
template <typename LibObjT>
-bt2s::optional<typename CommonEvent<LibObjT>::_Packet> CommonEvent<LibObjT>::packet() const noexcept
+OptionalBorrowedObject<typename CommonEvent<LibObjT>::_Packet>
+CommonEvent<LibObjT>::packet() const noexcept
{
- const auto libObjPtr = _Spec::packet(this->libObjPtr());
-
- if (libObjPtr) {
- return _Packet {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::packet(this->libObjPtr());
}
namespace internal {
return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
}
- bt2s::optional<_Stream> streamById(const std::uint64_t id) const noexcept
+ OptionalBorrowedObject<_Stream> streamById(const std::uint64_t id) const noexcept
{
- const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id);
-
- if (libObjPtr) {
- return _Stream {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::streamById(this->libObjPtr(), id);
}
void environmentEntry(const char * const name, const std::int64_t val) const
return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
}
- bt2s::optional<ConstValue> environmentEntry(const char * const name) const noexcept
+ OptionalBorrowedObject<ConstValue> environmentEntry(const char * const name) const noexcept
{
- const auto libObjPtr =
- bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
-
- if (libObjPtr) {
- return ConstValue {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
}
- bt2s::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
+ OptionalBorrowedObject<ConstValue> environmentEntry(const std::string& name) const noexcept
{
return this->environmentEntry(name.data());
}
}
}
- bt2s::optional<_StructureFieldClass> payloadFieldClass() const noexcept
+ OptionalBorrowedObject<_StructureFieldClass> payloadFieldClass() const noexcept
{
- const auto libObjPtr = _Spec::payloadFieldClass(this->libObjPtr());
-
- if (libObjPtr) {
- return _StructureFieldClass {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::payloadFieldClass(this->libObjPtr());
}
void specificContextFieldClass(const StructureFieldClass fc) const
}
}
- bt2s::optional<_StructureFieldClass> specificContextFieldClass() const noexcept
+ OptionalBorrowedObject<_StructureFieldClass> specificContextFieldClass() const noexcept
{
- const auto libObjPtr = _Spec::specificContextFieldClass(this->libObjPtr());
-
- if (libObjPtr) {
- return _StructureFieldClass {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::specificContextFieldClass(this->libObjPtr());
}
template <typename LibValT>
BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
}
- bt2s::optional<_ClockClass> defaultClockClass() const noexcept
+ OptionalBorrowedObject<_ClockClass> defaultClockClass() const noexcept
{
- const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr());
-
- if (libObjPtr) {
- return _ClockClass {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::defaultClockClass(this->libObjPtr());
}
std::uint64_t length() const noexcept
return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
}
- bt2s::optional<_EventClass> eventClassById(const std::uint64_t id) const noexcept
+ OptionalBorrowedObject<_EventClass> eventClassById(const std::uint64_t id) const noexcept
{
- const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id);
-
- if (libObjPtr) {
- return _EventClass {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::eventClassById(this->libObjPtr(), id);
}
void packetContextFieldClass(const StructureFieldClass fc) const
}
}
- bt2s::optional<_StructureFieldClass> packetContextFieldClass() const noexcept
+ OptionalBorrowedObject<_StructureFieldClass> packetContextFieldClass() const noexcept
{
- const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr());
-
- if (libObjPtr) {
- return _StructureFieldClass {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::packetContextFieldClass(this->libObjPtr());
}
void eventCommonContextFieldClass(const StructureFieldClass fc) const
}
}
- bt2s::optional<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
+ OptionalBorrowedObject<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
{
- const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr());
-
- if (libObjPtr) {
- return _StructureFieldClass {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::eventCommonContextFieldClass(this->libObjPtr());
}
template <typename LibValT>
return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
}
- bt2s::optional<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
+ OptionalBorrowedObject<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
{
- const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id);
-
- if (libObjPtr) {
- return _StreamClass {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::streamClassById(this->libObjPtr(), id);
}
template <typename LibValT>
#include "common/assert.h"
#include "common/common.h"
-#include "cpp-common/bt2s/optional.hpp"
#include "borrowed-object-iterator.hpp"
#include "borrowed-object.hpp"
#include "exc.hpp"
#include "internal/utils.hpp"
+#include "optional-borrowed-object.hpp"
#include "raw-value-proxy.hpp"
#include "shared-object.hpp"
}
template <typename KeyT>
- bt2s::optional<CommonValue<LibObjT>> operator[](KeyT&& key) const noexcept
+ OptionalBorrowedObject<CommonValue<LibObjT>> operator[](KeyT&& key) const noexcept
{
return this->asMap()[std::forward<KeyT>(key)];
}
return this->length() == 0;
}
- bt2s::optional<CommonValue<LibObjT>> operator[](const char * const key) const noexcept
+ OptionalBorrowedObject<CommonValue<LibObjT>> operator[](const char * const key) const noexcept
{
- const auto libObjPtr =
- internal::CommonMapValueSpec<LibObjT>::entryByKey(this->libObjPtr(), key);
-
- if (!libObjPtr) {
- return bt2s::nullopt;
- }
-
- return CommonValue<LibObjT> {libObjPtr};
+ return internal::CommonMapValueSpec<LibObjT>::entryByKey(this->libObjPtr(), key);
}
- bt2s::optional<CommonValue<LibObjT>> operator[](const std::string& key) const noexcept
+ OptionalBorrowedObject<CommonValue<LibObjT>> operator[](const std::string& key) const noexcept
{
return (*this)[key.data()];
}