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"
15 #include "internal/shared-obj.hpp"
19 class ConstIndexFieldPathItem;
21 enum class FieldPathItemType
23 INDEX = BT_FIELD_PATH_ITEM_TYPE_INDEX,
24 CURRENT_ARRAY_ELEMENT = BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT,
25 CURRENT_OPTION_CONTENT = BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT,
28 class ConstFieldPathItem : public internal::BorrowedObj<const bt_field_path_item>
31 explicit ConstFieldPathItem(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
35 ConstFieldPathItem(const ConstFieldPathItem& fpItem) noexcept : _ThisBorrowedObj {fpItem}
39 ConstFieldPathItem& operator=(const ConstFieldPathItem& fpItem) noexcept
41 _ThisBorrowedObj::operator=(fpItem);
45 FieldPathItemType type() const noexcept
47 return static_cast<FieldPathItemType>(this->_libType());
50 bool isIndex() const noexcept
52 return this->_libType() == BT_FIELD_PATH_ITEM_TYPE_INDEX;
55 bool isCurrentArrayElement() const noexcept
57 return this->_libType() == BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT;
60 bool isCurrentOptionContent() const noexcept
62 return this->_libType() == BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT;
65 ConstIndexFieldPathItem asIndex() const noexcept;
68 bt_field_path_item_type _libType() const noexcept
70 return bt_field_path_item_get_type(this->_libObjPtr());
74 class ConstIndexFieldPathItem final : public ConstFieldPathItem
77 explicit ConstIndexFieldPathItem(const _LibObjPtr libObjPtr) noexcept :
78 ConstFieldPathItem {libObjPtr}
80 BT_ASSERT_DBG(this->isIndex());
83 ConstIndexFieldPathItem(const ConstIndexFieldPathItem& fpItem) noexcept :
84 ConstFieldPathItem {fpItem}
88 ConstIndexFieldPathItem& operator=(const ConstIndexFieldPathItem& fpItem) noexcept
90 ConstFieldPathItem::operator=(fpItem);
94 std::uint64_t index() const noexcept
96 return bt_field_path_item_index_get_index(this->_libObjPtr());
100 inline ConstIndexFieldPathItem ConstFieldPathItem::asIndex() const noexcept
102 BT_ASSERT_DBG(this->isIndex());
103 return ConstIndexFieldPathItem {this->_libObjPtr()};
108 struct FieldPathRefFuncs final
110 static void get(const bt_field_path * const libObjPtr)
112 bt_field_path_get_ref(libObjPtr);
115 static void put(const bt_field_path * const libObjPtr)
117 bt_field_path_put_ref(libObjPtr);
121 } /* namespace internal */
123 class ConstFieldPath final : public internal::BorrowedObj<const bt_field_path>
127 internal::SharedObj<ConstFieldPath, const bt_field_path, internal::FieldPathRefFuncs>;
131 PACKET_CONTEXT = BT_FIELD_PATH_SCOPE_PACKET_CONTEXT,
132 EVENT_COMMON_CONTEXT = BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT,
133 EVENT_SPECIFIC_CONTEXT = BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT,
134 EVENT_PAYLOAD = BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD,
137 explicit ConstFieldPath(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
141 ConstFieldPath(const ConstFieldPath& fieldPath) noexcept : _ThisBorrowedObj {fieldPath}
145 ConstFieldPath& operator=(const ConstFieldPath& fieldPath) noexcept
147 _ThisBorrowedObj::operator=(fieldPath);
151 Scope rootScope() const noexcept
153 return static_cast<Scope>(bt_field_path_get_root_scope(this->_libObjPtr()));
156 std::uint64_t size() const noexcept
158 return bt_field_path_get_item_count(this->_libObjPtr());
161 ConstFieldPathItem operator[](const std::uint64_t index) const noexcept
163 return ConstFieldPathItem {
164 bt_field_path_borrow_item_by_index_const(this->_libObjPtr(), index)};
167 Shared shared() const noexcept
169 return Shared {*this};
173 } /* namespace bt2 */
175 #endif /* BABELTRACE_CPP_COMMON_BT2_FIELD_PATH_HPP */