projects
/
babeltrace.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
cpp-common/bt2: add `CommonStringField::length` method
[babeltrace.git]
/
src
/
cpp-common
/
bt2
/
field.hpp
diff --git
a/src/cpp-common/bt2/field.hpp
b/src/cpp-common/bt2/field.hpp
index 2c40ae3307a46a3420faa29e20c184606eb32e0f..e051a806e4ab2ca1104bcbf42e2d24e93db78e2b 100644
(file)
--- a/
src/cpp-common/bt2/field.hpp
+++ b/
src/cpp-common/bt2/field.hpp
@@
-13,6
+13,7
@@
#include <babeltrace2/babeltrace.h>
#include "common/assert.h"
#include <babeltrace2/babeltrace.h>
#include "common/assert.h"
+#include "cpp-common/bt2c/c-string-view.hpp"
#include "borrowed-object.hpp"
#include "field-class.hpp"
#include "borrowed-object.hpp"
#include "field-class.hpp"
@@
-597,7
+598,7
@@
public:
return _mLen;
}
return _mLen;
}
-
const char *
operator[](const std::uint64_t index) const noexcept
+
bt2c::CStringView
operator[](const std::uint64_t index) const noexcept
{
return _mLabels[index];
}
{
return _mLabels[index];
}
@@
-932,7
+933,7
@@
private:
public:
using typename CommonField<LibObjT>::LibObjPtr;
public:
using typename CommonField<LibObjT>::LibObjPtr;
- using Value =
const char *
;
+ using Value =
bt2c::CStringView
;
explicit CommonStringField(const LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
{
explicit CommonStringField(const LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
{
@@
-956,29
+957,24
@@
public:
return CommonStringField<const bt_field> {*this};
}
return CommonStringField<const bt_field> {*this};
}
- Raw
String
ValueProxy<CommonStringField> operator*() const noexcept
+ RawValueProxy<CommonStringField> operator*() const noexcept
{
{
- return Raw
String
ValueProxy<CommonStringField> {*this};
+ return RawValueProxy<CommonStringField> {*this};
}
}
- void value(const
char * const
val) const
+ void value(const
Value
val) const
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstStringField`.");
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstStringField`.");
- const auto status = bt_field_string_set_value(this->libObjPtr(), val);
+ const auto status = bt_field_string_set_value(this->libObjPtr(),
*
val);
if (status == BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR) {
throw MemoryError {};
}
}
if (status == BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR) {
throw MemoryError {};
}
}
- void value(const std::string& val) const
- {
- this->value(val.data());
- }
-
- void append(const char * const begin, const std::uint64_t len) const
+ void append(const bt2c::CStringView begin, const std::uint64_t len) const
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstStringField`.");
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstStringField`.");
@@
-990,6
+986,11
@@
public:
}
}
}
}
+ void append(const bt2c::CStringView val) const
+ {
+ this->append(val, std::strlen(val));
+ }
+
void append(const std::string& val) const
{
this->append(val.data(), val.size());
void append(const std::string& val) const
{
this->append(val.data(), val.size());
@@
-1003,10
+1004,15
@@
public:
bt_field_string_clear(this->libObjPtr());
}
bt_field_string_clear(this->libObjPtr());
}
-
const char *
value() const noexcept
+
Value
value() const noexcept
{
return bt_field_string_get_value(this->libObjPtr());
}
{
return bt_field_string_get_value(this->libObjPtr());
}
+
+ std::uint64_t length() const noexcept
+ {
+ return bt_field_string_get_length(this->libObjPtr());
+ }
};
using StringField = CommonStringField<bt_field>;
};
using StringField = CommonStringField<bt_field>;
@@
-1117,15
+1123,11
@@
public:
return CommonField<LibObjT> {_Spec::memberFieldByIndex(this->libObjPtr(), index)};
}
return CommonField<LibObjT> {_Spec::memberFieldByIndex(this->libObjPtr(), index)};
}
- OptionalBorrowedObject<CommonField<LibObjT>> operator[](const char * const name) const noexcept
+ OptionalBorrowedObject<CommonField<LibObjT>>
+ operator[](const bt2c::CStringView name) const noexcept
{
return _Spec::memberFieldByName(this->libObjPtr(), name);
}
{
return _Spec::memberFieldByName(this->libObjPtr(), name);
}
-
- OptionalBorrowedObject<CommonField<LibObjT>> operator[](const std::string& name) const noexcept
- {
- return (*this)[name.data()];
- }
};
using StructureField = CommonStructureField<bt_field>;
};
using StructureField = CommonStructureField<bt_field>;
This page took
0.024738 seconds
and
4
git commands to generate.