src/cpp-common/bt2: add `bt2::AddConst` and `bt2::RemoveConst`
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 9 May 2022 20:08:23 +0000 (16:08 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 11 Sep 2023 15:24:02 +0000 (11:24 -0400)
commit4927bae7b89dff01618509f362c9400ee1993e94
tree588ac0ed0b6cdb3243685d9216bce2244e6fb604
parent5d6ccdaeae400938ca68012cea84630f55687b6d
src/cpp-common/bt2: add `bt2::AddConst` and `bt2::RemoveConst`

This patch adds the `bt2::AddConst` and `bt2::RemoveConst` structure
templates in `src/cpp-common/bt2/type-traits.hpp` which both provide the
`Type` type alias to transform a const object type into a non-const
object type and vice versa.

For example, `bt2::AddConst<bt2::ClockClass>::Type` is
`bt2::ConstClockClass` and `bt2::RemoveConst<bt2::ConstMapValue>::Type`
is `bt2::MapValue`.

I needed this to call something like

    bt2::RemoveConst<typename LibFcT::Mapping::RangeSet>::Type::create()

where `LibFcT` is some non-const enumeration field class, but I decided
to implement it for all the types right now.

Internally, we add something like this for all type pairs:

    namespace internal {

    struct XyzTypeDescr
    {
        using Const = ConstXyz;
        using NonConst = Xyz;
    };

    template <>
    struct TypeDescr<Xyz> : public XyzTypeDescr
    {
    };

    template <>
    struct TypeDescr<ConstXyz> : public XyzTypeDescr
    {
    };

    } /* namespace internal */

The type trait structure templates in `type-traits.hpp` just use
`internal::TypeDescr`, for example:

    template <typename ObjT>
    struct RemoveConst
    {
        using Type = typename internal::TypeDescr<ObjT>::NonConst;
    };

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ia4d44a286fd836dcdb2a0f37c5a08a43bad5508e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8008
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10791
Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common/bt2/clock-class.hpp
src/cpp-common/bt2/field-class.hpp
src/cpp-common/bt2/field.hpp
src/cpp-common/bt2/integer-range-set.hpp
src/cpp-common/bt2/internal/utils.hpp
src/cpp-common/bt2/message.hpp
src/cpp-common/bt2/trace-ir.hpp
src/cpp-common/bt2/type-traits.hpp [new file with mode: 0644]
src/cpp-common/bt2/value.hpp
This page took 0.025429 seconds and 4 git commands to generate.