X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Fcpp-common%2Fbt2%2Ffield-path.hpp;h=fc087593b881ecbaef878ccdea4642c4c3884de4;hb=bd6e66fd0c3012ad6bcb03cdb3fb687767fb6ccf;hp=4031ee0aab703e09e82ad4e34867ad7046632e56;hpb=801759504c915ece1877feb27f9bac3ab0ffc65c;p=babeltrace.git diff --git a/src/cpp-common/bt2/field-path.hpp b/src/cpp-common/bt2/field-path.hpp index 4031ee0a..fc087593 100644 --- a/src/cpp-common/bt2/field-path.hpp +++ b/src/cpp-common/bt2/field-path.hpp @@ -8,11 +8,14 @@ #define BABELTRACE_CPP_COMMON_BT2_FIELD_PATH_HPP #include + #include #include "common/assert.h" -#include "internal/borrowed-obj.hpp" -#include "internal/shared-obj.hpp" + +#include "borrowed-object-iterator.hpp" +#include "borrowed-object.hpp" +#include "shared-object.hpp" namespace bt2 { @@ -25,23 +28,14 @@ enum class FieldPathItemType CURRENT_OPTION_CONTENT = BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT, }; -class ConstFieldPathItem : public internal::BorrowedObj +class ConstFieldPathItem : public BorrowedObject { public: - explicit ConstFieldPathItem(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr} - { - } - - ConstFieldPathItem(const ConstFieldPathItem& fpItem) noexcept : _ThisBorrowedObj {fpItem} + explicit ConstFieldPathItem(const LibObjPtr libObjPtr) noexcept : + _ThisBorrowedObject {libObjPtr} { } - ConstFieldPathItem& operator=(const ConstFieldPathItem& fpItem) noexcept - { - _ThisBorrowedObj::operator=(fpItem); - return *this; - } - FieldPathItemType type() const noexcept { return static_cast(this->_libType()); @@ -67,52 +61,40 @@ public: private: bt_field_path_item_type _libType() const noexcept { - return bt_field_path_item_get_type(this->_libObjPtr()); + return bt_field_path_item_get_type(this->libObjPtr()); } }; class ConstIndexFieldPathItem final : public ConstFieldPathItem { public: - explicit ConstIndexFieldPathItem(const _LibObjPtr libObjPtr) noexcept : + explicit ConstIndexFieldPathItem(const LibObjPtr libObjPtr) noexcept : ConstFieldPathItem {libObjPtr} { BT_ASSERT_DBG(this->isIndex()); } - ConstIndexFieldPathItem(const ConstIndexFieldPathItem& fpItem) noexcept : - ConstFieldPathItem {fpItem} - { - } - - ConstIndexFieldPathItem& operator=(const ConstIndexFieldPathItem& fpItem) noexcept - { - ConstFieldPathItem::operator=(fpItem); - return *this; - } - std::uint64_t index() const noexcept { - return bt_field_path_item_index_get_index(this->_libObjPtr()); + return bt_field_path_item_index_get_index(this->libObjPtr()); } }; inline ConstIndexFieldPathItem ConstFieldPathItem::asIndex() const noexcept { - BT_ASSERT_DBG(this->isIndex()); - return ConstIndexFieldPathItem {this->_libObjPtr()}; + return ConstIndexFieldPathItem {this->libObjPtr()}; } namespace internal { struct FieldPathRefFuncs final { - static void get(const bt_field_path * const libObjPtr) + static void get(const bt_field_path * const libObjPtr) noexcept { bt_field_path_get_ref(libObjPtr); } - static void put(const bt_field_path * const libObjPtr) + static void put(const bt_field_path * const libObjPtr) noexcept { bt_field_path_put_ref(libObjPtr); } @@ -120,11 +102,11 @@ struct FieldPathRefFuncs final } /* namespace internal */ -class ConstFieldPath final : public internal::BorrowedObj +class ConstFieldPath final : public BorrowedObject { public: - using Shared = - internal::SharedObj; + using Shared = SharedObject; + using Iterator = BorrowedObjectIterator; enum class Scope { @@ -134,39 +116,39 @@ public: EVENT_PAYLOAD = BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD, }; - explicit ConstFieldPath(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr} + explicit ConstFieldPath(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} { } - ConstFieldPath(const ConstFieldPath& fieldPath) noexcept : _ThisBorrowedObj {fieldPath} + Scope rootScope() const noexcept { + return static_cast(bt_field_path_get_root_scope(this->libObjPtr())); } - ConstFieldPath& operator=(const ConstFieldPath& fieldPath) noexcept + std::uint64_t length() const noexcept { - _ThisBorrowedObj::operator=(fieldPath); - return *this; + return bt_field_path_get_item_count(this->libObjPtr()); } - Scope rootScope() const noexcept + ConstFieldPathItem operator[](const std::uint64_t index) const noexcept { - return static_cast(bt_field_path_get_root_scope(this->_libObjPtr())); + return ConstFieldPathItem { + bt_field_path_borrow_item_by_index_const(this->libObjPtr(), index)}; } - std::uint64_t size() const noexcept + Iterator begin() const noexcept { - return bt_field_path_get_item_count(this->_libObjPtr()); + return Iterator {*this, 0}; } - ConstFieldPathItem operator[](const std::uint64_t index) const noexcept + Iterator end() const noexcept { - return ConstFieldPathItem { - bt_field_path_borrow_item_by_index_const(this->_libObjPtr(), index)}; + return Iterator {*this, this->length()}; } Shared shared() const noexcept { - return Shared {*this}; + return Shared::createWithRef(*this); } };