2 * Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
4 * SPDX-License-Identifier: MIT
7 #ifndef BABELTRACE_CPP_COMMON_BT2_FIELD_PATH_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_FIELD_PATH_HPP
11 #include <babeltrace2/babeltrace.h>
13 #include "common/assert.h"
14 #include "internal/borrowed-obj.hpp"
18 class ConstIndexFieldPathItem;
20 enum class FieldPathItemType
22 INDEX = BT_FIELD_PATH_ITEM_TYPE_INDEX,
23 CURRENT_ARRAY_ELEMENT = BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT,
24 CURRENT_OPTION_CONTENT = BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT,
27 class ConstFieldPathItem : public internal::BorrowedObj<const bt_field_path_item>
30 explicit ConstFieldPathItem(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
34 ConstFieldPathItem(const ConstFieldPathItem& fpItem) noexcept : _ThisBorrowedObj {fpItem}
38 ConstFieldPathItem& operator=(const ConstFieldPathItem& fpItem) noexcept
40 _ThisBorrowedObj::operator=(fpItem);
44 FieldPathItemType type() const noexcept
46 return static_cast<FieldPathItemType>(this->_libType());
49 bool isIndex() const noexcept
51 return this->_libType() == BT_FIELD_PATH_ITEM_TYPE_INDEX;
54 bool isCurrentArrayElement() const noexcept
56 return this->_libType() == BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT;
59 bool isCurrentOptionContent() const noexcept
61 return this->_libType() == BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT;
64 ConstIndexFieldPathItem asIndex() const noexcept;
67 bt_field_path_item_type _libType() const noexcept
69 return bt_field_path_item_get_type(this->_libObjPtr());
73 class ConstIndexFieldPathItem final : public ConstFieldPathItem
76 explicit ConstIndexFieldPathItem(const _LibObjPtr libObjPtr) noexcept :
77 ConstFieldPathItem {libObjPtr}
79 BT_ASSERT_DBG(this->isIndex());
82 ConstIndexFieldPathItem(const ConstIndexFieldPathItem& fpItem) noexcept :
83 ConstFieldPathItem {fpItem}
87 ConstIndexFieldPathItem& operator=(const ConstIndexFieldPathItem& fpItem) noexcept
89 ConstFieldPathItem::operator=(fpItem);
93 std::uint64_t index() const noexcept
95 return bt_field_path_item_index_get_index(this->_libObjPtr());
99 inline ConstIndexFieldPathItem ConstFieldPathItem::asIndex() const noexcept
101 BT_ASSERT_DBG(this->isIndex());
102 return ConstIndexFieldPathItem {this->_libObjPtr()};
107 struct FieldPathRefFuncs final
109 static void get(const bt_field_path * const libObjPtr)
111 bt_field_path_get_ref(libObjPtr);
114 static void put(const bt_field_path * const libObjPtr)
116 bt_field_path_put_ref(libObjPtr);
120 } // namespace internal
122 class ConstFieldPath final : public internal::BorrowedObj<const bt_field_path>
126 internal::SharedObj<ConstFieldPath, const bt_field_path, internal::FieldPathRefFuncs>;
130 PACKET_CONTEXT = BT_FIELD_PATH_SCOPE_PACKET_CONTEXT,
131 EVENT_COMMON_CONTEXT = BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT,
132 EVENT_SPECIFIC_CONTEXT = BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT,
133 EVENT_PAYLOAD = BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD,
136 explicit ConstFieldPath(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
140 ConstFieldPath(const ConstFieldPath& clkSnapshot) noexcept : _ThisBorrowedObj {clkSnapshot}
144 ConstFieldPath& operator=(const ConstFieldPath& clkSnapshot) noexcept
146 _ThisBorrowedObj::operator=(clkSnapshot);
150 Scope rootScope() const noexcept
152 return static_cast<Scope>(bt_field_path_get_root_scope(this->_libObjPtr()));
155 std::uint64_t size() const noexcept
157 return bt_field_path_get_item_count(this->_libObjPtr());
160 ConstFieldPathItem operator[](const std::uint64_t index) const noexcept
162 return ConstFieldPathItem {
163 bt_field_path_borrow_item_by_index_const(this->_libObjPtr(), index)};
166 Shared shared() const noexcept
168 return Shared {*this};
174 #endif // BABELTRACE_CPP_COMMON_BT2_FIELD_PATH_HPP