cpp-common/bt2: systematize the `const` method situation
This patch attempts to systematize the `const` situation regarding
methods (member functions and operators).
The current issue is that, because those wrappers are expected to be
passed and returned by copy (they only wrap a libbabeltrace2 pointer),
one cannot rely on the `const` qualifier to ensure immutability at the
library level. For example:
void f(const bt2::ArrayValue val)
{
// Want to modify what `val` wraps? No problem:
auto newVal = val;
newVal += 23;
}
The signature of f() here doesn't guarantee to the caller that what
`val` wraps is immutable. To achieve this, it needs to accept the
`Const` version of the wrapper:
void f(bt2::ConstArrayValue val)
{
// Now there's no way to modify what `val` wraps
}
Therefore, since using the `const` keyword is so fragile, this patch
makes `const` (almost) all the methods of wrapper classes: those methods
do not modify the wrapped pointer value, therefore they may be `const`.
This makes the wrapping system have this correspondence:
bt_xyz * bt2::Xyz
bt_xyz * const const bt2::Xyz
const bt_xyz * bt2::ConstXyz
const bt_xyz * const const bt2::ConstXyz
Because there were many overloads to return a `bt2::Const*` instance
when the object is `const`, this patch removes a lot of code, with the
added benefit of reducing code duplication.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ie633e7e9d67a8eb0138800ad8ae14c8d9bd0ca4c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11228
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
This page took 0.025839 seconds and 4 git commands to generate.