cpp-common/bt2/field-class.hpp \
cpp-common/bt2/field-path.hpp \
cpp-common/bt2/field.hpp \
+ cpp-common/bt2/field-location.hpp \
cpp-common/bt2/integer-range-set.hpp \
cpp-common/bt2/integer-range.hpp \
cpp-common/bt2/internal/comp-cls-bridge.hpp \
--- /dev/null
+/*
+ * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2_FIELD_LOCATION_HPP
+#define BABELTRACE_CPP_COMMON_BT2_FIELD_LOCATION_HPP
+
+#include <cstdint>
+
+#include <babeltrace2/babeltrace.h>
+
+#include "common/assert.h"
+#include "cpp-common/bt2c/c-string-view.hpp"
+
+#include "borrowed-object.hpp"
+#include "shared-object.hpp"
+
+namespace bt2 {
+namespace internal {
+
+struct FieldLocationRefFuncs final
+{
+ static void get(const bt_field_location * const libObjPtr)
+ {
+ bt_field_location_get_ref(libObjPtr);
+ }
+
+ static void put(const bt_field_location * const libObjPtr)
+ {
+ bt_field_location_put_ref(libObjPtr);
+ }
+};
+
+} /* namespace internal */
+
+class ConstFieldLocation : public BorrowedObject<const bt_field_location>
+{
+public:
+ using Shared =
+ SharedObject<ConstFieldLocation, const bt_field_location, internal::FieldLocationRefFuncs>;
+
+ enum class Scope
+ {
+ PacketContext = BT_FIELD_LOCATION_SCOPE_PACKET_CONTEXT,
+ CommonEventContext = BT_FIELD_LOCATION_SCOPE_EVENT_COMMON_CONTEXT,
+ SpecificEventContext = BT_FIELD_LOCATION_SCOPE_EVENT_SPECIFIC_CONTEXT,
+ EventPayload = BT_FIELD_LOCATION_SCOPE_EVENT_PAYLOAD,
+ };
+
+ explicit ConstFieldLocation(const LibObjPtr libObjPtr) noexcept :
+ _ThisBorrowedObject {libObjPtr}
+ {
+ }
+
+ Scope rootScope() const noexcept
+ {
+ return static_cast<Scope>(bt_field_location_get_root_scope(this->libObjPtr()));
+ }
+
+ std::uint64_t size() const noexcept
+ {
+ return bt_field_location_get_item_count(this->libObjPtr());
+ }
+
+ bt2c::CStringView operator[](const std::uint64_t index) const noexcept
+ {
+ return bt_field_location_get_item_by_index(this->libObjPtr(), index);
+ }
+
+ Shared shared() const noexcept
+ {
+ return Shared::createWithRef(*this);
+ }
+};
+
+} /* namespace bt2 */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2_FIELD_LOCATION_HPP */
#include <cstdint>
#include <type_traits>
+#include <vector>
#include <babeltrace2/babeltrace.h>
#include "common/macros.h"
#include "cpp-common/bt2c/c-string-view.hpp"
+#include "cpp-common/bt2c/call.hpp"
#include "cpp-common/bt2s/optional.hpp"
+#include "cpp-common/bt2s/span.hpp"
#include "borrowed-object.hpp"
#include "clock-class.hpp"
#include "field-class.hpp"
+#include "field-location.hpp"
#include "field.hpp"
#include "internal/utils.hpp"
#include "optional-borrowed-object.hpp"
return Trace::Shared::createWithoutRef(libObjPtr);
}
+ ConstFieldLocation::Shared createFieldLocation(const ConstFieldLocation::Scope scope,
+ const bt2s::span<const char * const> items) const
+ {
+ static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
+
+ const auto libObjPtr =
+ bt_field_location_create(this->libObjPtr(), static_cast<bt_field_location_scope>(scope),
+ items.data(), items.size());
+
+ internal::validateCreatedObjPtr(libObjPtr);
+ return ConstFieldLocation::Shared::createWithoutRef(libObjPtr);
+ }
+
+ ConstFieldLocation::Shared createFieldLocation(const ConstFieldLocation::Scope scope,
+ const bt2s::span<const std::string> items) const
+ {
+ static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
+
+ const auto ptrItems = bt2c::call([items] {
+ std::vector<const char *> v;
+
+ for (auto& item : items) {
+ v.push_back(item.data());
+ }
+
+ return v;
+ });
+
+ return this->createFieldLocation(scope, ptrItems);
+ }
+
StreamClass::Shared createStreamClass() const
{
static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
#include "component-port.hpp"
#include "error.hpp"
#include "field-class.hpp"
+#include "field-location.hpp"
#include "field.hpp"
#include "graph.hpp"
#include "integer-range-set.hpp"
return ConstFieldPathItem {libObjPtr};
}
+inline ConstFieldLocation wrap(const bt_field_location * const libObjPtr) noexcept
+{
+ return ConstFieldLocation {libObjPtr};
+}
+
inline ConstFieldPath wrap(const bt_field_path * const libObjPtr) noexcept
{
return ConstFieldPath {libObjPtr};