cpp-common/bt2: use raw value proxy for scalar value classes
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 11 Nov 2023 16:46:36 +0000 (11:46 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 14 Dec 2023 15:57:04 +0000 (10:57 -0500)
commitb3f060ed119961106d34da4db9071653a37f5c53
tree995e0b0bfc6d0143f609fa657d90a455fe96e727
parenta699e23c5d369505002e5283207a871dbd62d59f
cpp-common/bt2: use raw value proxy for scalar value classes

This patch adds the `bt2::RawValueProxy` class of which an instance
contains a wrapper object `_mObj` and:

* Its `=` operator calls `_mObj.value()` to assign a value.
* Its raw value type operator returns what `_mObj.value()` returns.

Then, in scalar value wrapper classes of `value.hpp`:

* Remove the `=` operator which assigns a raw value.
* Add a value() method to assign a raw value.
* Add a `*` operator to return a raw value proxy containing this.

The goal of this patch is to avoid using the `=` operator on some value
object to both wrap another library object (pseudo copy assignment
operator) and assign a raw value. Now, to assign a raw value, you need
to "dereference" the wrapper object:

    void f(const bt2::UnsignedIntegerValue val) {
        *val = 23;
        std::cout << *val << std::endl;
    }

There's also `bt2::RawStringValueProxy` which adds the `=` operator to
`bt2::RawValueProxy` to assign a `const std::string&`.
`bt2::CommonStringValue` uses it.

Additionally, remove all the `=` operators to assign a raw value on
`bt2::CommonValue` and create a "master" raw value proxy class
(`CommonValueRawValueProxy`) to have all the `=` operators and raw value
type operators:

    void f(const bt2::Value val) {
        // We know it's a boolean value
        *val = true;
    }

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ia8559de36baba3021169b3d097ec83b914407f63
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11362
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
src/Makefile.am
src/cpp-common/bt2/raw-value-proxy.hpp [new file with mode: 0644]
src/cpp-common/bt2/value.hpp
This page took 0.024817 seconds and 4 git commands to generate.