Using `bpstd::string_view` in those contexts was a mistake: building a
`bpstd::string_view` object from a null-terminated string requires to
get its length (think strlen()), and an optional string view requires to
return `nonstd::optional<bpstd::string_view>` which means checking the
library pointer first.
All this means it's not a zero cost, and zero cost is what those C++
bindings aim to be.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ib51fb9e326c4b4c450a381631b9db69f6cd0530b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11370
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
#include <babeltrace2/babeltrace.h>
#include "cpp-common/optional.hpp"
#include <babeltrace2/babeltrace.h>
#include "cpp-common/optional.hpp"
-#include "cpp-common/string_view.hpp"
#include "cpp-common/uuid-view.hpp"
#include "borrowed-object.hpp"
#include "cpp-common/uuid-view.hpp"
#include "borrowed-object.hpp"
this->name(name.data());
}
this->name(name.data());
}
- nonstd::optional<bpstd::string_view> name() const noexcept
+ const char *name() const noexcept
- const auto name = bt_clock_class_get_name(this->libObjPtr());
-
- if (name) {
- return name;
- }
-
- return nonstd::nullopt;
+ return bt_clock_class_get_name(this->libObjPtr());
}
void description(const char * const description) const
}
void description(const char * const description) const
this->description(description.data());
}
this->description(description.data());
}
- nonstd::optional<bpstd::string_view> description() const noexcept
+ const char *description() const noexcept
- const auto description = bt_clock_class_get_description(this->libObjPtr());
-
- if (description) {
- return description;
- }
-
- return nonstd::nullopt;
+ return bt_clock_class_get_description(this->libObjPtr());
}
void uuid(const std::uint8_t * const uuid) const noexcept
}
void uuid(const std::uint8_t * const uuid) const noexcept
#include "common/assert.h"
#include "cpp-common/optional.hpp"
#include "common/assert.h"
#include "cpp-common/optional.hpp"
-#include "cpp-common/string_view.hpp"
#include "borrowed-object-iterator.hpp"
#include "borrowed-object.hpp"
#include "borrowed-object-iterator.hpp"
#include "borrowed-object.hpp"
internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::ranges(this->libObjPtr())};
}
internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::ranges(this->libObjPtr())};
}
- bpstd::string_view label() const noexcept
+ const char *label() const noexcept
{
return internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::label(this->libObjPtr());
}
{
return internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::label(this->libObjPtr());
}
return CommonStructureFieldClassMember<const bt_field_class_structure_member> {*this};
}
return CommonStructureFieldClassMember<const bt_field_class_structure_member> {*this};
}
- bpstd::string_view name() const noexcept
+ const char *name() const noexcept
{
return bt_field_class_structure_member_get_name(this->libObjPtr());
}
{
return bt_field_class_structure_member_get_name(this->libObjPtr());
}
return CommonVariantFieldClassOption<const bt_field_class_variant_option> {*this};
}
return CommonVariantFieldClassOption<const bt_field_class_variant_option> {*this};
}
- nonstd::optional<bpstd::string_view> name() const noexcept
+ const char *name() const noexcept
- const auto name = bt_field_class_variant_option_get_name(this->libObjPtr());
-
- if (name) {
- return name;
- }
-
- return nonstd::nullopt;
+ return bt_field_class_variant_option_get_name(this->libObjPtr());
}
_FieldClass fieldClass() const noexcept
}
_FieldClass fieldClass() const noexcept
return ConstVariantFieldClassOption {_Spec::asBaseOption(this->libObjPtr())};
}
return ConstVariantFieldClassOption {_Spec::asBaseOption(this->libObjPtr())};
}
- nonstd::optional<bpstd::string_view> name() const noexcept
+ const char *name() const noexcept
{
return this->asBaseOption().name();
}
{
return this->asBaseOption().name();
}
#include "common/assert.h"
#include "cpp-common/optional.hpp"
#include "common/assert.h"
#include "cpp-common/optional.hpp"
-#include "cpp-common/string_view.hpp"
#include "borrowed-object.hpp"
#include "field-class.hpp"
#include "borrowed-object.hpp"
#include "field-class.hpp"
- bpstd::string_view operator[](const std::uint64_t index) const noexcept
+ const char *operator[](const std::uint64_t index) const noexcept
{
return _mLabels[index];
}
{
return _mLabels[index];
}
#include <babeltrace2/babeltrace.h>
#include "cpp-common/optional.hpp"
#include <babeltrace2/babeltrace.h>
#include "cpp-common/optional.hpp"
-#include "cpp-common/string_view.hpp"
#include "borrowed-object.hpp"
#include "clock-class.hpp"
#include "borrowed-object.hpp"
#include "clock-class.hpp"
this->name(name.data());
}
this->name(name.data());
}
- nonstd::optional<bpstd::string_view> name() const noexcept
+ const char *name() const noexcept
- const auto name = bt_stream_get_name(this->libObjPtr());
-
- if (name) {
- return name;
- }
-
- return nonstd::nullopt;
+ return bt_stream_get_name(this->libObjPtr());
}
template <typename LibValT>
}
template <typename LibValT>
struct ConstEnvironmentEntry
{
struct ConstEnvironmentEntry
{
- bpstd::string_view name;
this->name(name.data());
}
this->name(name.data());
}
- nonstd::optional<bpstd::string_view> name() const noexcept
+ const char *name() const noexcept
- const auto name = bt_trace_get_name(this->libObjPtr());
-
- if (name) {
- return name;
- }
-
- return nonstd::nullopt;
+ return bt_trace_get_name(this->libObjPtr());
}
void uuid(const bt2_common::UuidView& uuid) const noexcept
}
void uuid(const bt2_common::UuidView& uuid) const noexcept
this->name(name.data());
}
this->name(name.data());
}
- nonstd::optional<bpstd::string_view> name() const noexcept
+ const char *name() const noexcept
- const auto name = bt_event_class_get_name(this->libObjPtr());
-
- if (name) {
- return name;
- }
-
- return nonstd::nullopt;
+ return bt_event_class_get_name(this->libObjPtr());
}
void logLevel(const LogLevel logLevel) const noexcept
}
void logLevel(const LogLevel logLevel) const noexcept
this->emfUri(emfUri.data());
}
this->emfUri(emfUri.data());
}
- nonstd::optional<bpstd::string_view> emfUri() const noexcept
+ const char *emfUri() const noexcept
- const auto emfUri = bt_event_class_get_emf_uri(this->libObjPtr());
-
- if (emfUri) {
- return emfUri;
- }
-
- return nonstd::nullopt;
+ return bt_event_class_get_emf_uri(this->libObjPtr());
}
void payloadFieldClass(const StructureFieldClass fc) const
}
void payloadFieldClass(const StructureFieldClass fc) const
this->name(name.data());
}
this->name(name.data());
}
- nonstd::optional<bpstd::string_view> name() const noexcept
+ const char *name() const noexcept
- const auto name = bt_stream_class_get_name(this->libObjPtr());
-
- if (name) {
- return name;
- }
-
- return nonstd::nullopt;
+ return bt_stream_class_get_name(this->libObjPtr());
}
void assignsAutomaticEventClassId(const bool val) const noexcept
}
void assignsAutomaticEventClassId(const bool val) const noexcept
#include "common/assert.h"
#include "common/common.h"
#include "cpp-common/optional.hpp"
#include "common/assert.h"
#include "common/common.h"
#include "cpp-common/optional.hpp"
-#include "cpp-common/string_view.hpp"
#include "borrowed-object-iterator.hpp"
#include "borrowed-object.hpp"
#include "borrowed-object-iterator.hpp"
#include "borrowed-object.hpp"
* First argument is the entry's key, second is its value.
*/
template <typename ObjT>
* First argument is the entry's key, second is its value.
*/
template <typename ObjT>
-using CommonMapValueForEachUserFunc = std::function<void(const bpstd::string_view&, ObjT)>;
+using CommonMapValueForEachUserFunc = std::function<void(const char *, ObjT)>;
/*
* Template of a function to be passed to bt_value_map_foreach_entry()
/*
* Template of a function to be passed to bt_value_map_foreach_entry()