Add `bt2_common::DataLen` class (general-purpose data length)
This patch adds the `bt2_common::DataLen` class so that you can make
sure your function accepts an expected data length instead of specifying
that you need bits or bytes:
Something buildSomething(bt2_common::DataLen len, ...)
{
using namespace bt2_common::literals::datalen;
if (...) {
len += 16_MiBytes;
} else {
len *= 2;
}
// ...
}
// ...
const auto something = buildSomething(DataLen::fromBytes(sz), ...);
As you can see above, you can use the `bt2_common::literals::datalen`
namespace to access handy data length user literals.
The `bt2_common::DataLen` constructor is private: you need to use the
bt2_common::DataLen::fromBits() and bt2_common::DataLen::fromBytes()
static methods to build an instance.
Because a `bt2_common::DataLen` instance is just an `unsigned long long`
value in memory, the intention of this API is to copy data length
instances as much as possible. Therefore, I suppose it's cheaper to
accept a `const bt2_common::DataLen` parameter than
`const bt2_common::DataLen&` which would add an indirection.
The constructor and many methods are `constexpr` to make this useable in
constant context.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I1375fb5697c0d952f3669dc587603839d511dd18
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7726
This page took 0.036313 seconds and 5 git commands to generate.