X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcpp-common%2Fbt2%2Ffield-path.hpp;h=0a68927cf9dfc2e56fa82b1557b0907777a3cacf;hb=c802cacb9f0879a42e01575595a75bbefe7d3db9;hp=b91d91135ba95aed791ba64853a6d241abf327a5;hpb=40ed8b0148b4b1d02dc1fd4f8fa4f615f40a4f59;p=babeltrace.git diff --git a/src/cpp-common/bt2/field-path.hpp b/src/cpp-common/bt2/field-path.hpp index b91d9113..0a68927c 100644 --- a/src/cpp-common/bt2/field-path.hpp +++ b/src/cpp-common/bt2/field-path.hpp @@ -8,10 +8,14 @@ #define BABELTRACE_CPP_COMMON_BT2_FIELD_PATH_HPP #include + #include #include "common/assert.h" + +#include "common-iter.hpp" #include "internal/borrowed-obj.hpp" +#include "internal/shared-obj.hpp" namespace bt2 { @@ -66,7 +70,7 @@ 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()); } }; @@ -92,14 +96,14 @@ public: 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 { @@ -117,7 +121,7 @@ struct FieldPathRefFuncs final } }; -} // namespace internal +} /* namespace internal */ class ConstFieldPath final : public internal::BorrowedObj { @@ -125,6 +129,8 @@ public: using Shared = internal::SharedObj; + using Iterator = CommonIterator; + enum class Scope { PACKET_CONTEXT = BT_FIELD_PATH_SCOPE_PACKET_CONTEXT, @@ -137,38 +143,48 @@ public: { } - ConstFieldPath(const ConstFieldPath& clkSnapshot) noexcept : _ThisBorrowedObj {clkSnapshot} + ConstFieldPath(const ConstFieldPath& fieldPath) noexcept : _ThisBorrowedObj {fieldPath} { } - ConstFieldPath& operator=(const ConstFieldPath& clkSnapshot) noexcept + ConstFieldPath& operator=(const ConstFieldPath& fieldPath) noexcept { - _ThisBorrowedObj::operator=(clkSnapshot); + _ThisBorrowedObj::operator=(fieldPath); return *this; } Scope rootScope() const noexcept { - return static_cast(bt_field_path_get_root_scope(this->_libObjPtr())); + return static_cast(bt_field_path_get_root_scope(this->libObjPtr())); } std::uint64_t size() const noexcept { - return bt_field_path_get_item_count(this->_libObjPtr()); + return bt_field_path_get_item_count(this->libObjPtr()); } ConstFieldPathItem operator[](const std::uint64_t index) const noexcept { return ConstFieldPathItem { - bt_field_path_borrow_item_by_index_const(this->_libObjPtr(), index)}; + bt_field_path_borrow_item_by_index_const(this->libObjPtr(), index)}; + } + + Iterator begin() const noexcept + { + return Iterator {*this, 0}; + } + + Iterator end() const noexcept + { + return Iterator {*this, this->size()}; } Shared shared() const noexcept { - return Shared {*this}; + return Shared::createWithRef(*this); } }; -} // namespace bt2 +} /* namespace bt2 */ -#endif // BABELTRACE_CPP_COMMON_BT2_FIELD_PATH_HPP +#endif /* BABELTRACE_CPP_COMMON_BT2_FIELD_PATH_HPP */