From 4927bae7b89dff01618509f362c9400ee1993e94 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 9 May 2022 16:08:23 -0400 Subject: [PATCH] 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::Type` is `bt2::ConstClockClass` and `bt2::RemoveConst::Type` is `bt2::MapValue`. I needed this to call something like bt2::RemoveConst::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 : public XyzTypeDescr { }; template <> struct TypeDescr : public XyzTypeDescr { }; } /* namespace internal */ The type trait structure templates in `type-traits.hpp` just use `internal::TypeDescr`, for example: template struct RemoveConst { using Type = typename internal::TypeDescr::NonConst; }; Signed-off-by: Philippe Proulx Change-Id: Ia4d44a286fd836dcdb2a0f37c5a08a43bad5508e Reviewed-on: https://review.lttng.org/c/babeltrace/+/8008 Reviewed-on: https://review.lttng.org/c/babeltrace/+/10791 Tested-by: jenkins --- src/cpp-common/bt2/clock-class.hpp | 20 ++ src/cpp-common/bt2/field-class.hpp | 372 ++++++++++++++++++++++- src/cpp-common/bt2/field.hpp | 285 +++++++++++++++++ src/cpp-common/bt2/integer-range-set.hpp | 35 +++ src/cpp-common/bt2/internal/utils.hpp | 3 + src/cpp-common/bt2/message.hpp | 155 +++++++++- src/cpp-common/bt2/trace-ir.hpp | 136 +++++++++ src/cpp-common/bt2/type-traits.hpp | 28 ++ src/cpp-common/bt2/value.hpp | 173 ++++++++++- 9 files changed, 1204 insertions(+), 3 deletions(-) create mode 100644 src/cpp-common/bt2/type-traits.hpp diff --git a/src/cpp-common/bt2/clock-class.hpp b/src/cpp-common/bt2/clock-class.hpp index 92caa9e4..15273164 100644 --- a/src/cpp-common/bt2/clock-class.hpp +++ b/src/cpp-common/bt2/clock-class.hpp @@ -14,6 +14,7 @@ #include "internal/borrowed-obj.hpp" #include "internal/shared-obj.hpp" +#include "internal/utils.hpp" #include "cpp-common/optional.hpp" #include "cpp-common/string_view.hpp" #include "cpp-common/uuid-view.hpp" @@ -285,6 +286,25 @@ public: using ClockClass = CommonClockClass; using ConstClockClass = CommonClockClass; +namespace internal { + +struct ClockClassTypeDescr +{ + using Const = ConstClockClass; + using NonConst = ClockClass; +}; + +template <> +struct TypeDescr : public ClockClassTypeDescr +{ +}; + +template <> +struct TypeDescr : public ClockClassTypeDescr +{ +}; + +} /* namespace internal */ } /* namespace bt2 */ #endif /* BABELTRACE_CPP_COMMON_BT2_CLOCK_CLASS_HPP */ diff --git a/src/cpp-common/bt2/field-class.hpp b/src/cpp-common/bt2/field-class.hpp index 4dbdee60..22dfa47b 100644 --- a/src/cpp-common/bt2/field-class.hpp +++ b/src/cpp-common/bt2/field-class.hpp @@ -14,6 +14,7 @@ #include "common/assert.h" #include "internal/borrowed-obj.hpp" #include "internal/shared-obj.hpp" +#include "internal/utils.hpp" #include "cpp-common/optional.hpp" #include "cpp-common/string_view.hpp" #include "common-iter.hpp" @@ -23,7 +24,6 @@ #include "value.hpp" namespace bt2 { - namespace internal { struct FieldClassRefFuncs final @@ -447,6 +447,26 @@ protected: using FieldClass = CommonFieldClass; using ConstFieldClass = CommonFieldClass; +namespace internal { + +struct FieldClassTypeDescr +{ + using Const = ConstFieldClass; + using NonConst = FieldClass; +}; + +template <> +struct TypeDescr : public FieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : public FieldClassTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonBitArrayFieldClass final : public CommonFieldClass { @@ -491,6 +511,26 @@ public: using BitArrayFieldClass = CommonBitArrayFieldClass; using ConstBitArrayFieldClass = CommonBitArrayFieldClass; +namespace internal { + +struct BitArrayFieldClassTypeDescr +{ + using Const = ConstBitArrayFieldClass; + using NonConst = BitArrayFieldClass; +}; + +template <> +struct TypeDescr : public BitArrayFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : public BitArrayFieldClassTypeDescr +{ +}; + +} /* namespace internal */ + enum class DisplayBase { BINARY = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY, @@ -568,6 +608,26 @@ using ConstIntegerFieldClass = CommonIntegerFieldClass; namespace internal { +struct IntegerFieldClassTypeDescr +{ + using Const = ConstIntegerFieldClass; + using NonConst = IntegerFieldClass; +}; + +template <> +struct TypeDescr : public IntegerFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : public IntegerFieldClassTypeDescr +{ +}; + +} /* namespace internal */ + +namespace internal { + template struct ConstEnumerationFieldClassMappingSpec; @@ -851,6 +911,38 @@ using ConstSignedEnumerationFieldClass = namespace internal { +struct UnsignedEnumerationFieldClassTypeDescr +{ + using Const = ConstUnsignedEnumerationFieldClass; + using NonConst = UnsignedEnumerationFieldClass; +}; + +template <> +struct TypeDescr : public UnsignedEnumerationFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : public UnsignedEnumerationFieldClassTypeDescr +{ +}; + +struct SignedEnumerationFieldClassTypeDescr +{ + using Const = ConstSignedEnumerationFieldClass; + using NonConst = SignedEnumerationFieldClass; +}; + +template <> +struct TypeDescr : public SignedEnumerationFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : public SignedEnumerationFieldClassTypeDescr +{ +}; + template struct CommonStructureFieldClassMemberSpec; @@ -933,6 +1025,22 @@ using ConstStructureFieldClassMember = namespace internal { +struct StructureFieldClassMemberTypeDescr +{ + using Const = ConstStructureFieldClassMember; + using NonConst = StructureFieldClassMember; +}; + +template <> +struct TypeDescr : public StructureFieldClassMemberTypeDescr +{ +}; + +template <> +struct TypeDescr : public StructureFieldClassMemberTypeDescr +{ +}; + template struct CommonStructureFieldClassSpec; @@ -1099,6 +1207,22 @@ using ConstStructureFieldClass = CommonStructureFieldClass namespace internal { +struct StructureFieldClassTypeDescr +{ + using Const = ConstStructureFieldClass; + using NonConst = StructureFieldClass; +}; + +template <> +struct TypeDescr : public StructureFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : public StructureFieldClassTypeDescr +{ +}; + template struct CommonArrayFieldClassSpec; @@ -1181,6 +1305,26 @@ public: using ArrayFieldClass = CommonArrayFieldClass; using ConstArrayFieldClass = CommonArrayFieldClass; +namespace internal { + +struct ArrayFieldClassTypeDescr +{ + using Const = ConstArrayFieldClass; + using NonConst = ArrayFieldClass; +}; + +template <> +struct TypeDescr : public ArrayFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : public ArrayFieldClassTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonStaticArrayFieldClass final : public CommonArrayFieldClass { @@ -1225,6 +1369,26 @@ public: using StaticArrayFieldClass = CommonStaticArrayFieldClass; using ConstStaticArrayFieldClass = CommonStaticArrayFieldClass; +namespace internal { + +struct StaticArrayFieldClassTypeDescr +{ + using Const = ConstStaticArrayFieldClass; + using NonConst = StaticArrayFieldClass; +}; + +template <> +struct TypeDescr : public StaticArrayFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : public StaticArrayFieldClassTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonDynamicArrayWithLengthFieldClass final : public CommonArrayFieldClass { @@ -1277,6 +1441,24 @@ using ConstDynamicArrayWithLengthFieldClass = namespace internal { +struct DynamicArrayWithLengthFieldClassTypeDescr +{ + using Const = ConstDynamicArrayWithLengthFieldClass; + using NonConst = DynamicArrayWithLengthFieldClass; +}; + +template <> +struct TypeDescr : + public DynamicArrayWithLengthFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : + public DynamicArrayWithLengthFieldClassTypeDescr +{ +}; + template struct CommonOptionFieldClassSpec; @@ -1359,6 +1541,26 @@ public: using OptionFieldClass = CommonOptionFieldClass; using ConstOptionFieldClass = CommonOptionFieldClass; +namespace internal { + +struct OptionFieldClassTypeDescr +{ + using Const = ConstOptionFieldClass; + using NonConst = OptionFieldClass; +}; + +template <> +struct TypeDescr : public OptionFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : public OptionFieldClassTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonOptionWithSelectorFieldClass : public CommonOptionFieldClass { @@ -1409,6 +1611,26 @@ public: using OptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass; using ConstOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass; +namespace internal { + +struct OptionWithSelectorFieldClassTypeDescr +{ + using Const = ConstOptionWithSelectorFieldClass; + using NonConst = OptionWithSelectorFieldClass; +}; + +template <> +struct TypeDescr : public OptionWithSelectorFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : public OptionWithSelectorFieldClassTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonOptionWithBoolSelectorFieldClass : public CommonOptionWithSelectorFieldClass { @@ -1462,6 +1684,24 @@ using ConstOptionWithBoolSelectorFieldClass = namespace internal { +struct OptionWithBoolSelectorFieldClassTypeDescr +{ + using Const = ConstOptionWithBoolSelectorFieldClass; + using NonConst = OptionWithBoolSelectorFieldClass; +}; + +template <> +struct TypeDescr : + public OptionWithBoolSelectorFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : + public OptionWithBoolSelectorFieldClassTypeDescr +{ +}; + template struct CommonOptionWithIntegerSelectorFieldClassSpec; @@ -1556,6 +1796,42 @@ using ConstOptionWithSignedIntegerSelectorFieldClass = namespace internal { +struct OptionWithUnsignedIntegerSelectorFieldClassTypeDescr +{ + using Const = ConstOptionWithUnsignedIntegerSelectorFieldClass; + using NonConst = OptionWithUnsignedIntegerSelectorFieldClass; +}; + +template <> +struct TypeDescr : + public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : + public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr +{ +}; + +struct OptionWithSignedIntegerSelectorFieldClassTypeDescr +{ + using Const = ConstOptionWithSignedIntegerSelectorFieldClass; + using NonConst = OptionWithSignedIntegerSelectorFieldClass; +}; + +template <> +struct TypeDescr : + public OptionWithSignedIntegerSelectorFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : + public OptionWithSignedIntegerSelectorFieldClassTypeDescr +{ +}; + template struct CommonVariantFieldClassOptionSpec; @@ -1637,6 +1913,22 @@ using ConstVariantFieldClassOption = namespace internal { +struct VariantFieldClassOptionTypeDescr +{ + using Const = ConstVariantFieldClassOption; + using NonConst = VariantFieldClassOption; +}; + +template <> +struct TypeDescr : public VariantFieldClassOptionTypeDescr +{ +}; + +template <> +struct TypeDescr : public VariantFieldClassOptionTypeDescr +{ +}; + template struct ConstVariantWithIntegerSelectorFieldClassOptionSpec; @@ -1905,6 +2197,26 @@ public: using VariantFieldClass = CommonVariantFieldClass; using ConstVariantFieldClass = CommonVariantFieldClass; +namespace internal { + +struct VariantFieldClassTypeDescr +{ + using Const = ConstVariantFieldClass; + using NonConst = VariantFieldClass; +}; + +template <> +struct TypeDescr : public VariantFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : public VariantFieldClassTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonVariantWithoutSelectorFieldClass : public CommonVariantFieldClass { @@ -1967,6 +2279,24 @@ using ConstVariantWithoutSelectorFieldClass = namespace internal { +struct VariantWithoutSelectorFieldClassTypeDescr +{ + using Const = ConstVariantWithoutSelectorFieldClass; + using NonConst = VariantWithoutSelectorFieldClass; +}; + +template <> +struct TypeDescr : + public VariantWithoutSelectorFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : + public VariantWithoutSelectorFieldClassTypeDescr +{ +}; + template struct CommonVariantWithIntegerSelectorFieldClassSpec; @@ -2178,6 +2508,46 @@ using VariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelec using ConstVariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< const bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>; +namespace internal { + +struct VariantWithUnsignedIntegerSelectorFieldClassTypeDescr +{ + using Const = ConstVariantWithUnsignedIntegerSelectorFieldClass; + using NonConst = VariantWithUnsignedIntegerSelectorFieldClass; +}; + +template <> +struct TypeDescr : + public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : + public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr +{ +}; + +struct VariantWithSignedIntegerSelectorFieldClassTypeDescr +{ + using Const = ConstVariantWithSignedIntegerSelectorFieldClass; + using NonConst = VariantWithSignedIntegerSelectorFieldClass; +}; + +template <> +struct TypeDescr : + public VariantWithSignedIntegerSelectorFieldClassTypeDescr +{ +}; + +template <> +struct TypeDescr : + public VariantWithSignedIntegerSelectorFieldClassTypeDescr +{ +}; + +} /* namespace internal */ + template CommonBitArrayFieldClass CommonFieldClass::asBitArray() const noexcept { diff --git a/src/cpp-common/bt2/field.hpp b/src/cpp-common/bt2/field.hpp index e075f8e6..25d0034f 100644 --- a/src/cpp-common/bt2/field.hpp +++ b/src/cpp-common/bt2/field.hpp @@ -13,6 +13,7 @@ #include "common/assert.h" #include "internal/borrowed-obj.hpp" +#include "internal/utils.hpp" #include "cpp-common/optional.hpp" #include "cpp-common/string_view.hpp" #include "field-class.hpp" @@ -222,6 +223,26 @@ public: using Field = CommonField; using ConstField = CommonField; +namespace internal { + +struct FieldTypeDescr +{ + using Const = ConstField; + using NonConst = Field; +}; + +template <> +struct TypeDescr : public FieldTypeDescr +{ +}; + +template <> +struct TypeDescr : public FieldTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonBoolField final : public CommonField { @@ -271,6 +292,26 @@ public: using BoolField = CommonBoolField; using ConstBoolField = CommonBoolField; +namespace internal { + +struct BoolFieldTypeDescr +{ + using Const = ConstBoolField; + using NonConst = BoolField; +}; + +template <> +struct TypeDescr : public BoolFieldTypeDescr +{ +}; + +template <> +struct TypeDescr : public BoolFieldTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonBitArrayField final : public CommonField { @@ -334,6 +375,26 @@ public: using BitArrayField = CommonBitArrayField; using ConstBitArrayField = CommonBitArrayField; +namespace internal { + +struct BitArrayFieldTypeDescr +{ + using Const = ConstBitArrayField; + using NonConst = BitArrayField; +}; + +template <> +struct TypeDescr : public BitArrayFieldTypeDescr +{ +}; + +template <> +struct TypeDescr : public BitArrayFieldTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonUnsignedIntegerField final : public CommonField { @@ -403,6 +464,26 @@ public: using UnsignedIntegerField = CommonUnsignedIntegerField; using ConstUnsignedIntegerField = CommonUnsignedIntegerField; +namespace internal { + +struct UnsignedIntegerFieldTypeDescr +{ + using Const = ConstUnsignedIntegerField; + using NonConst = UnsignedIntegerField; +}; + +template <> +struct TypeDescr : public UnsignedIntegerFieldTypeDescr +{ +}; + +template <> +struct TypeDescr : public UnsignedIntegerFieldTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonSignedIntegerField final : public CommonField { @@ -472,6 +553,26 @@ public: using SignedIntegerField = CommonSignedIntegerField; using ConstSignedIntegerField = CommonSignedIntegerField; +namespace internal { + +struct SignedIntegerFieldTypeDescr +{ + using Const = ConstSignedIntegerField; + using NonConst = SignedIntegerField; +}; + +template <> +struct TypeDescr : public SignedIntegerFieldTypeDescr +{ +}; + +template <> +struct TypeDescr : public SignedIntegerFieldTypeDescr +{ +}; + +} /* namespace internal */ + class EnumerationFieldClassMappingLabels { public: @@ -565,6 +666,26 @@ public: using UnsignedEnumerationField = CommonUnsignedEnumerationField; using ConstUnsignedEnumerationField = CommonUnsignedEnumerationField; +namespace internal { + +struct UnsignedEnumerationFieldTypeDescr +{ + using Const = ConstUnsignedEnumerationField; + using NonConst = UnsignedEnumerationField; +}; + +template <> +struct TypeDescr : public UnsignedEnumerationFieldTypeDescr +{ +}; + +template <> +struct TypeDescr : public UnsignedEnumerationFieldTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonSignedEnumerationField final : public CommonSignedIntegerField { @@ -626,6 +747,26 @@ public: using SignedEnumerationField = CommonSignedEnumerationField; using ConstSignedEnumerationField = CommonSignedEnumerationField; +namespace internal { + +struct SignedEnumerationFieldTypeDescr +{ + using Const = ConstSignedEnumerationField; + using NonConst = SignedEnumerationField; +}; + +template <> +struct TypeDescr : public SignedEnumerationFieldTypeDescr +{ +}; + +template <> +struct TypeDescr : public SignedEnumerationFieldTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonSinglePrecisionRealField final : public CommonField { @@ -679,6 +820,26 @@ public: using SinglePrecisionRealField = CommonSinglePrecisionRealField; using ConstSinglePrecisionRealField = CommonSinglePrecisionRealField; +namespace internal { + +struct SinglePrecisionRealFieldTypeDescr +{ + using Const = ConstSinglePrecisionRealField; + using NonConst = SinglePrecisionRealField; +}; + +template <> +struct TypeDescr : public SinglePrecisionRealFieldTypeDescr +{ +}; + +template <> +struct TypeDescr : public SinglePrecisionRealFieldTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonDoublePrecisionRealField final : public CommonField { @@ -732,6 +893,26 @@ public: using DoublePrecisionRealField = CommonDoublePrecisionRealField; using ConstDoublePrecisionRealField = CommonDoublePrecisionRealField; +namespace internal { + +struct DoublePrecisionRealFieldTypeDescr +{ + using Const = ConstDoublePrecisionRealField; + using NonConst = DoublePrecisionRealField; +}; + +template <> +struct TypeDescr : public DoublePrecisionRealFieldTypeDescr +{ +}; + +template <> +struct TypeDescr : public DoublePrecisionRealFieldTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonStringField final : public CommonField { @@ -793,6 +974,22 @@ using ConstStringField = CommonStringField; namespace internal { +struct StringFieldTypeDescr +{ + using Const = ConstStringField; + using NonConst = StringField; +}; + +template <> +struct TypeDescr : public StringFieldTypeDescr +{ +}; + +template <> +struct TypeDescr : public StringFieldTypeDescr +{ +}; + template struct CommonStructureFieldSpec; @@ -929,6 +1126,22 @@ using ConstStructureField = CommonStructureField; namespace internal { +struct StructureFieldTypeDescr +{ + using Const = ConstStructureField; + using NonConst = StructureField; +}; + +template <> +struct TypeDescr : public StructureFieldTypeDescr +{ +}; + +template <> +struct TypeDescr : public StructureFieldTypeDescr +{ +}; + template struct CommonArrayFieldSpec; @@ -1019,6 +1232,26 @@ public: using ArrayField = CommonArrayField; using ConstArrayField = CommonArrayField; +namespace internal { + +struct ArrayFieldTypeDescr +{ + using Const = ConstArrayField; + using NonConst = ArrayField; +}; + +template <> +struct TypeDescr : public ArrayFieldTypeDescr +{ +}; + +template <> +struct TypeDescr : public ArrayFieldTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonDynamicArrayField : public CommonArrayField { @@ -1069,6 +1302,22 @@ using ConstDynamicArrayField = CommonDynamicArrayField; namespace internal { +struct DynamicArrayFieldTypeDescr +{ + using Const = ConstDynamicArrayField; + using NonConst = DynamicArrayField; +}; + +template <> +struct TypeDescr : public DynamicArrayFieldTypeDescr +{ +}; + +template <> +struct TypeDescr : public DynamicArrayFieldTypeDescr +{ +}; + template struct CommonOptionFieldSpec; @@ -1175,6 +1424,22 @@ using ConstOptionField = CommonOptionField; namespace internal { +struct OptionFieldTypeDescr +{ + using Const = ConstOptionField; + using NonConst = OptionField; +}; + +template <> +struct TypeDescr : public OptionFieldTypeDescr +{ +}; + +template <> +struct TypeDescr : public OptionFieldTypeDescr +{ +}; + template struct CommonVariantFieldSpec; @@ -1268,6 +1533,26 @@ public: using VariantField = CommonVariantField; using ConstVariantField = CommonVariantField; +namespace internal { + +struct VariantFieldTypeDescr +{ + using Const = ConstVariantField; + using NonConst = VariantField; +}; + +template <> +struct TypeDescr : public VariantFieldTypeDescr +{ +}; + +template <> +struct TypeDescr : public VariantFieldTypeDescr +{ +}; + +} /* namespace internal */ + template CommonBoolField CommonField::asBool() const noexcept { diff --git a/src/cpp-common/bt2/integer-range-set.hpp b/src/cpp-common/bt2/integer-range-set.hpp index 3e88b61a..6cb17af0 100644 --- a/src/cpp-common/bt2/integer-range-set.hpp +++ b/src/cpp-common/bt2/integer-range-set.hpp @@ -249,6 +249,41 @@ using ConstUnsignedIntegerRangeSet = CommonIntegerRangeSet; using ConstSignedIntegerRangeSet = CommonIntegerRangeSet; +namespace internal { + +struct UnsignedIntegerRangeSetTypeDescr +{ + using Const = ConstUnsignedIntegerRangeSet; + using NonConst = UnsignedIntegerRangeSet; +}; + +template <> +struct TypeDescr : public UnsignedIntegerRangeSetTypeDescr +{ +}; + +template <> +struct TypeDescr : public UnsignedIntegerRangeSetTypeDescr +{ +}; + +struct SignedIntegerRangeSetTypeDescr +{ + using Const = ConstSignedIntegerRangeSet; + using NonConst = SignedIntegerRangeSet; +}; + +template <> +struct TypeDescr : public SignedIntegerRangeSetTypeDescr +{ +}; + +template <> +struct TypeDescr : public SignedIntegerRangeSetTypeDescr +{ +}; + +} /* namespace internal */ } /* namespace bt2 */ #endif /* BABELTRACE_CPP_COMMON_BT2_INTEGER_RANGE_SET_HPP */ diff --git a/src/cpp-common/bt2/internal/utils.hpp b/src/cpp-common/bt2/internal/utils.hpp index cbf761b0..34c52fff 100644 --- a/src/cpp-common/bt2/internal/utils.hpp +++ b/src/cpp-common/bt2/internal/utils.hpp @@ -22,6 +22,9 @@ void validateCreatedObjPtr(const LibObjPtrT libOjbPtr) } } +template +struct TypeDescr; + } /* namespace internal */ } /* namespace bt2 */ diff --git a/src/cpp-common/bt2/message.hpp b/src/cpp-common/bt2/message.hpp index 4a25821d..4e575722 100644 --- a/src/cpp-common/bt2/message.hpp +++ b/src/cpp-common/bt2/message.hpp @@ -22,7 +22,6 @@ #include "lib-error.hpp" namespace bt2 { - namespace internal { struct MessageRefFuncs final @@ -173,6 +172,22 @@ using ConstMessage = CommonMessage; namespace internal { +struct MessageTypeDescr +{ + using Const = ConstMessage; + using NonConst = Message; +}; + +template <> +struct TypeDescr : public MessageTypeDescr +{ +}; + +template <> +struct TypeDescr : public MessageTypeDescr +{ +}; + template struct CommonStreamBeginningMessageSpec; @@ -275,6 +290,22 @@ using ConstStreamBeginningMessage = CommonStreamBeginningMessage +struct TypeDescr : public StreamBeginningMessageTypeDescr +{ +}; + +template <> +struct TypeDescr : public StreamBeginningMessageTypeDescr +{ +}; + template struct CommonStreamEndMessageSpec; @@ -376,6 +407,22 @@ using ConstStreamEndMessage = CommonStreamEndMessage; namespace internal { +struct StreamEndMessageTypeDescr +{ + using Const = ConstStreamEndMessage; + using NonConst = StreamEndMessage; +}; + +template <> +struct TypeDescr : public StreamEndMessageTypeDescr +{ +}; + +template <> +struct TypeDescr : public StreamEndMessageTypeDescr +{ +}; + template struct CommonPacketBeginningMessageSpec; @@ -473,6 +520,22 @@ using ConstPacketBeginningMessage = CommonPacketBeginningMessage +struct TypeDescr : public PacketBeginningMessageTypeDescr +{ +}; + +template <> +struct TypeDescr : public PacketBeginningMessageTypeDescr +{ +}; + template struct CommonPacketEndMessageSpec; @@ -569,6 +632,22 @@ using ConstPacketEndMessage = CommonPacketEndMessage; namespace internal { +struct PacketEndMessageTypeDescr +{ + using Const = ConstPacketEndMessage; + using NonConst = PacketEndMessage; +}; + +template <> +struct TypeDescr : public PacketEndMessageTypeDescr +{ +}; + +template <> +struct TypeDescr : public PacketEndMessageTypeDescr +{ +}; + template struct CommonEventMessageSpec; @@ -657,6 +736,22 @@ using ConstEventMessage = CommonEventMessage; namespace internal { +struct EventMessageTypeDescr +{ + using Const = ConstEventMessage; + using NonConst = EventMessage; +}; + +template <> +struct TypeDescr : public EventMessageTypeDescr +{ +}; + +template <> +struct TypeDescr : public EventMessageTypeDescr +{ +}; + template struct CommonDiscardedEventsMessageSpec; @@ -775,6 +870,22 @@ using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage +struct TypeDescr : public DiscardedEventsMessageTypeDescr +{ +}; + +template <> +struct TypeDescr : public DiscardedEventsMessageTypeDescr +{ +}; + template struct CommonDiscardedPacketsMessageSpec; @@ -891,6 +1002,26 @@ public: using DiscardedPacketsMessage = CommonDiscardedPacketsMessage; using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage; +namespace internal { + +struct DiscardedPacketsMessageTypeDescr +{ + using Const = ConstDiscardedPacketsMessage; + using NonConst = DiscardedPacketsMessage; +}; + +template <> +struct TypeDescr : public DiscardedPacketsMessageTypeDescr +{ +}; + +template <> +struct TypeDescr : public DiscardedPacketsMessageTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonMessageIteratorInactivityMessage final : public CommonMessage { @@ -941,6 +1072,28 @@ using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage< using ConstMessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage; +namespace internal { + +struct MessageIteratorInactivityMessageTypeDescr +{ + using Const = ConstMessageIteratorInactivityMessage; + using NonConst = MessageIteratorInactivityMessage; +}; + +template <> +struct TypeDescr : + public MessageIteratorInactivityMessageTypeDescr +{ +}; + +template <> +struct TypeDescr : + public MessageIteratorInactivityMessageTypeDescr +{ +}; + +} /* namespace internal */ + template CommonStreamBeginningMessage CommonMessage::asStreamBeginning() const noexcept { diff --git a/src/cpp-common/bt2/trace-ir.hpp b/src/cpp-common/bt2/trace-ir.hpp index 33f77105..8677fde2 100644 --- a/src/cpp-common/bt2/trace-ir.hpp +++ b/src/cpp-common/bt2/trace-ir.hpp @@ -241,6 +241,22 @@ using ConstEvent = CommonEvent; namespace internal { +struct EventTypeDescr +{ + using Const = ConstEvent; + using NonConst = Event; +}; + +template <> +struct TypeDescr : public EventTypeDescr +{ +}; + +template <> +struct TypeDescr : public EventTypeDescr +{ +}; + struct PacketRefFuncs final { static void get(const bt_packet * const libObjPtr) @@ -359,6 +375,26 @@ public: using Packet = CommonPacket; using ConstPacket = CommonPacket; +namespace internal { + +struct PacketTypeDescr +{ + using Const = ConstPacket; + using NonConst = Packet; +}; + +template <> +struct TypeDescr : public PacketTypeDescr +{ +}; + +template <> +struct TypeDescr : public PacketTypeDescr +{ +}; + +} /* namespace internal */ + template nonstd::optional CommonEvent::packet() const noexcept { @@ -557,6 +593,26 @@ public: using Stream = CommonStream; using ConstStream = CommonStream; +namespace internal { + +struct StreamTypeDescr +{ + using Const = ConstStream; + using NonConst = Stream; +}; + +template <> +struct TypeDescr : public StreamTypeDescr +{ +}; + +template <> +struct TypeDescr : public StreamTypeDescr +{ +}; + +} /* namespace internal */ + template ConstStream CommonEvent::stream() const noexcept { @@ -886,6 +942,26 @@ public: using Trace = CommonTrace; using ConstTrace = CommonTrace; +namespace internal { + +struct TraceTypeDescr +{ + using Const = ConstTrace; + using NonConst = Trace; +}; + +template <> +struct TypeDescr : public TraceTypeDescr +{ +}; + +template <> +struct TypeDescr : public TraceTypeDescr +{ +}; + +} /* namespace internal */ + template ConstTrace CommonStream::trace() const noexcept { @@ -1207,6 +1283,26 @@ public: using EventClass = CommonEventClass; using ConstEventClass = CommonEventClass; +namespace internal { + +struct EventClassTypeDescr +{ + using Const = ConstEventClass; + using NonConst = EventClass; +}; + +template <> +struct TypeDescr : public EventClassTypeDescr +{ +}; + +template <> +struct TypeDescr : public EventClassTypeDescr +{ +}; + +} /* namespace internal */ + template ConstEventClass CommonEvent::cls() const noexcept { @@ -1710,6 +1806,26 @@ public: using StreamClass = CommonStreamClass; using ConstStreamClass = CommonStreamClass; +namespace internal { + +struct StreamClassTypeDescr +{ + using Const = ConstStreamClass; + using NonConst = StreamClass; +}; + +template <> +struct TypeDescr : public StreamClassTypeDescr +{ +}; + +template <> +struct TypeDescr : public StreamClassTypeDescr +{ +}; + +} /* namespace internal */ + template ConstStreamClass CommonEventClass::streamClass() const noexcept { @@ -2178,6 +2294,26 @@ private: using TraceClass = CommonTraceClass; using ConstTraceClass = CommonTraceClass; +namespace internal { + +struct TraceClassTypeDescr +{ + using Const = ConstTraceClass; + using NonConst = TraceClass; +}; + +template <> +struct TypeDescr : public TraceClassTypeDescr +{ +}; + +template <> +struct TypeDescr : public TraceClassTypeDescr +{ +}; + +} /* namespace internal */ + template ConstTraceClass CommonStreamClass::traceClass() const noexcept { diff --git a/src/cpp-common/bt2/type-traits.hpp b/src/cpp-common/bt2/type-traits.hpp new file mode 100644 index 00000000..53db3332 --- /dev/null +++ b/src/cpp-common/bt2/type-traits.hpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2020 Philippe Proulx + * + * SPDX-License-Identifier: MIT + */ + +#ifndef BABELTRACE_CPP_COMMON_BT2_TYPE_TRAITS_HPP +#define BABELTRACE_CPP_COMMON_BT2_TYPE_TRAITS_HPP + +#include "internal/utils.hpp" + +namespace bt2 { + +template +struct AddConst +{ + using Type = typename internal::TypeDescr::Const; +}; + +template +struct RemoveConst +{ + using Type = typename internal::TypeDescr::NonConst; +}; + +} /* namespace bt2 */ + +#endif /* BABELTRACE_CPP_COMMON_BT2_TYPE_TRAITS_HPP */ diff --git a/src/cpp-common/bt2/value.hpp b/src/cpp-common/bt2/value.hpp index dd05fea5..e9b61b13 100644 --- a/src/cpp-common/bt2/value.hpp +++ b/src/cpp-common/bt2/value.hpp @@ -24,7 +24,6 @@ #include "lib-error.hpp" namespace bt2 { - namespace internal { struct ValueRefFuncs final @@ -232,6 +231,26 @@ protected: using Value = CommonValue; using ConstValue = CommonValue; +namespace internal { + +struct ValueTypeDescr +{ + using Const = ConstValue; + using NonConst = Value; +}; + +template <> +struct TypeDescr : public ValueTypeDescr +{ +}; + +template <> +struct TypeDescr : public ValueTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonNullValue final : public CommonValue { @@ -266,6 +285,26 @@ public: using NullValue = CommonNullValue; using ConstNullValue = CommonNullValue; +namespace internal { + +struct NullValueTypeDescr +{ + using Const = ConstNullValue; + using NonConst = NullValue; +}; + +template <> +struct TypeDescr : public NullValueTypeDescr +{ +}; + +template <> +struct TypeDescr : public NullValueTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonBoolValue final : public CommonValue { @@ -329,6 +368,26 @@ public: using BoolValue = CommonBoolValue; using ConstBoolValue = CommonBoolValue; +namespace internal { + +struct BoolValueTypeDescr +{ + using Const = ConstBoolValue; + using NonConst = BoolValue; +}; + +template <> +struct TypeDescr : public BoolValueTypeDescr +{ +}; + +template <> +struct TypeDescr : public BoolValueTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonUnsignedIntegerValue final : public CommonValue { @@ -395,6 +454,26 @@ public: using UnsignedIntegerValue = CommonUnsignedIntegerValue; using ConstUnsignedIntegerValue = CommonUnsignedIntegerValue; +namespace internal { + +struct UnsignedIntegerValueTypeDescr +{ + using Const = ConstUnsignedIntegerValue; + using NonConst = UnsignedIntegerValue; +}; + +template <> +struct TypeDescr : public UnsignedIntegerValueTypeDescr +{ +}; + +template <> +struct TypeDescr : public UnsignedIntegerValueTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonSignedIntegerValue final : public CommonValue { @@ -461,6 +540,26 @@ public: using SignedIntegerValue = CommonSignedIntegerValue; using ConstSignedIntegerValue = CommonSignedIntegerValue; +namespace internal { + +struct SignedIntegerValueTypeDescr +{ + using Const = ConstSignedIntegerValue; + using NonConst = SignedIntegerValue; +}; + +template <> +struct TypeDescr : public SignedIntegerValueTypeDescr +{ +}; + +template <> +struct TypeDescr : public SignedIntegerValueTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonRealValue final : public CommonValue { @@ -524,6 +623,26 @@ public: using RealValue = CommonRealValue; using ConstRealValue = CommonRealValue; +namespace internal { + +struct RealValueTypeDescr +{ + using Const = ConstRealValue; + using NonConst = RealValue; +}; + +template <> +struct TypeDescr : public RealValueTypeDescr +{ +}; + +template <> +struct TypeDescr : public RealValueTypeDescr +{ +}; + +} /* namespace internal */ + template class CommonStringValue final : public CommonValue { @@ -598,6 +717,22 @@ using ConstStringValue = CommonStringValue; namespace internal { +struct StringValueTypeDescr +{ + using Const = ConstStringValue; + using NonConst = StringValue; +}; + +template <> +struct TypeDescr : public StringValueTypeDescr +{ +}; + +template <> +struct TypeDescr : public StringValueTypeDescr +{ +}; + template struct CommonArrayValueSpec; @@ -816,6 +951,22 @@ using ConstArrayValue = CommonArrayValue; namespace internal { +struct ArrayValueTypeDescr +{ + using Const = ConstArrayValue; + using NonConst = ArrayValue; +}; + +template <> +struct TypeDescr : public ArrayValueTypeDescr +{ +}; + +template <> +struct TypeDescr : public ArrayValueTypeDescr +{ +}; + /* * Type of a user function passed to `CommonMapValue::forEach()`. * @@ -1137,6 +1288,26 @@ private: using MapValue = CommonMapValue; using ConstMapValue = CommonMapValue; +namespace internal { + +struct MapValueTypeDescr +{ + using Const = ConstMapValue; + using NonConst = MapValue; +}; + +template <> +struct TypeDescr : public MapValueTypeDescr +{ +}; + +template <> +struct TypeDescr : public MapValueTypeDescr +{ +}; + +} /* namespace internal */ + template CommonNullValue CommonValue::asNull() const noexcept { -- 2.34.1