From: Philippe Proulx Date: Fri, 3 Nov 2023 18:48:52 +0000 (-0400) Subject: cpp-common/bt2: add and use `bt2::internal::Dep*` type alias templates X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=8047a1755063eb23e5a07b3b96441e50c366ea87 cpp-common/bt2: add and use `bt2::internal::Dep*` type alias templates Those new templates take care of using `std::conditional` instead of having to use it at each site. The template parameters of `bt2::internal::DepType` are: 1. What to check for constness. 2. The effective type if `LibObjT` is NOT `const`. 3. The effective type if `LibObjT` is `const`. Other `bt2::internal::Dep*` reuse `DepType` with specific types for parameters 2 and 3 for common uses. For example: using UserAttributes = typename std::conditional::value, ConstMapValue, MapValue>::type; gets replaced by: using UserAttributes = internal::DepUserAttrs; Signed-off-by: Philippe Proulx Change-Id: I434b9ae82d170c6fe8359488e78c0e3e34a064cd Reviewed-on: https://review.lttng.org/c/babeltrace/+/11234 Reviewed-by: Simon Marchi --- diff --git a/src/cpp-common/bt2/clock-class.hpp b/src/cpp-common/bt2/clock-class.hpp index 589526ed..48ff132e 100644 --- a/src/cpp-common/bt2/clock-class.hpp +++ b/src/cpp-common/bt2/clock-class.hpp @@ -101,8 +101,7 @@ private: public: using Shared = SharedObject<_ThisCommonClockClass, LibObjT, internal::ClockClassRefFuncs>; - using UserAttributes = - typename std::conditional::value, ConstMapValue, MapValue>::type; + using UserAttributes = internal::DepUserAttrs; explicit CommonClockClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} { diff --git a/src/cpp-common/bt2/field-class.hpp b/src/cpp-common/bt2/field-class.hpp index 461321fb..a053da3d 100644 --- a/src/cpp-common/bt2/field-class.hpp +++ b/src/cpp-common/bt2/field-class.hpp @@ -172,9 +172,7 @@ protected: public: using Shared = SharedFieldClass, LibObjT>; - - using UserAttributes = - typename std::conditional::value, ConstMapValue, MapValue>::type; + using UserAttributes = internal::DepUserAttrs; explicit CommonFieldClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} { @@ -998,13 +996,10 @@ class CommonStructureFieldClassMember final : public BorrowedObject private: using typename BorrowedObject::_LibObjPtr; using typename BorrowedObject::_ThisBorrowedObject; - - using _FieldClass = - typename std::conditional::value, ConstFieldClass, FieldClass>::type; + using _FieldClass = internal::DepFc; public: - using UserAttributes = - typename std::conditional::value, ConstMapValue, MapValue>::type; + using UserAttributes = internal::DepUserAttrs; explicit CommonStructureFieldClassMember(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} @@ -1131,9 +1126,9 @@ private: public: using Shared = SharedFieldClass, LibObjT>; + using Member = - typename std::conditional::value, ConstStructureFieldClassMember, - StructureFieldClassMember>::type; + internal::DepType; using Iterator = CommonIterator, Member>; @@ -1274,9 +1269,7 @@ class CommonArrayFieldClass : public CommonFieldClass { private: using typename CommonFieldClass::_ThisCommonFieldClass; - - using _FieldClass = - typename std::conditional::value, ConstFieldClass, FieldClass>::type; + using _FieldClass = internal::DepFc; protected: using typename CommonFieldClass::_LibObjPtr; @@ -1517,9 +1510,7 @@ class CommonOptionFieldClass : public CommonFieldClass { private: using typename CommonFieldClass::_ThisCommonFieldClass; - - using _FieldClass = - typename std::conditional::value, ConstFieldClass, FieldClass>::type; + using _FieldClass = internal::DepFc; protected: using typename CommonFieldClass::_LibObjPtr; @@ -1909,13 +1900,10 @@ class CommonVariantFieldClassOption : public BorrowedObject private: using typename BorrowedObject::_ThisBorrowedObject; using typename BorrowedObject::_LibObjPtr; - - using _FieldClass = - typename std::conditional::value, ConstFieldClass, FieldClass>::type; + using _FieldClass = internal::DepFc; public: - using UserAttributes = - typename std::conditional::value, ConstMapValue, MapValue>::type; + using UserAttributes = internal::DepUserAttrs; explicit CommonVariantFieldClassOption(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} @@ -2167,8 +2155,7 @@ public: using Shared = SharedFieldClass, LibObjT>; using Option = - typename std::conditional::value, ConstVariantFieldClassOption, - VariantFieldClassOption>::type; + internal::DepType; using Iterator = CommonIterator; diff --git a/src/cpp-common/bt2/field.hpp b/src/cpp-common/bt2/field.hpp index 187d6a57..aa160289 100644 --- a/src/cpp-common/bt2/field.hpp +++ b/src/cpp-common/bt2/field.hpp @@ -102,8 +102,7 @@ protected: using _ThisCommonField = CommonField; public: - using Class = - typename std::conditional::value, ConstFieldClass, FieldClass>::type; + using Class = internal::DepFc; explicit CommonField(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} { @@ -333,8 +332,7 @@ private: using typename CommonField::_ThisCommonField; public: - using Class = typename std::conditional::value, ConstBitArrayFieldClass, - BitArrayFieldClass>::type; + using Class = internal::DepType; explicit CommonBitArrayField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr} { @@ -426,9 +424,7 @@ protected: public: using Value = std::uint64_t; - - using Class = typename std::conditional::value, ConstIntegerFieldClass, - IntegerFieldClass>::type; + using Class = internal::DepType; explicit CommonUnsignedIntegerField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr} @@ -515,9 +511,7 @@ protected: public: using Value = std::int64_t; - - using Class = typename std::conditional::value, ConstIntegerFieldClass, - IntegerFieldClass>::type; + using Class = internal::DepType; explicit CommonSignedIntegerField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr} @@ -631,9 +625,8 @@ private: using typename CommonField::_LibObjPtr; public: - using Class = - typename std::conditional::value, ConstUnsignedEnumerationFieldClass, - UnsignedEnumerationFieldClass>::type; + using Class = internal::DepType; explicit CommonUnsignedEnumerationField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonUnsignedIntegerField {libObjPtr} @@ -715,8 +708,7 @@ private: public: using Class = - typename std::conditional::value, ConstSignedEnumerationFieldClass, - SignedEnumerationFieldClass>::type; + internal::DepType; explicit CommonSignedEnumerationField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonSignedIntegerField {libObjPtr} @@ -1094,8 +1086,7 @@ private: using _Spec = internal::CommonStructureFieldSpec; public: - using Class = typename std::conditional::value, ConstStructureFieldClass, - StructureFieldClass>::type; + using Class = internal::DepType; explicit CommonStructureField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr} @@ -1213,8 +1204,7 @@ protected: using _ThisCommonArrayField = CommonArrayField; public: - using Class = typename std::conditional::value, ConstArrayFieldClass, - ArrayFieldClass>::type; + using Class = internal::DepType; explicit CommonArrayField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr} { @@ -1383,8 +1373,7 @@ private: using _Spec = internal::CommonOptionFieldSpec; public: - using Class = typename std::conditional::value, ConstOptionFieldClass, - OptionFieldClass>::type; + using Class = internal::DepType; explicit CommonOptionField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr} { @@ -1493,8 +1482,7 @@ private: using _Spec = internal::CommonVariantFieldSpec; public: - using Class = typename std::conditional::value, ConstVariantFieldClass, - VariantFieldClass>::type; + using Class = internal::DepType; explicit CommonVariantField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr} { diff --git a/src/cpp-common/bt2/internal/utils.hpp b/src/cpp-common/bt2/internal/utils.hpp index 3c655b88..4ec736fd 100644 --- a/src/cpp-common/bt2/internal/utils.hpp +++ b/src/cpp-common/bt2/internal/utils.hpp @@ -7,9 +7,26 @@ #ifndef BABELTRACE_CPP_COMMON_BT2_INTERNAL_UTILS_HPP #define BABELTRACE_CPP_COMMON_BT2_INTERNAL_UTILS_HPP +#include + +#include + #include "../exc.hpp" namespace bt2 { + +template +class CommonMapValue; + +template +class CommonFieldClass; + +template +class CommonPacket; + +template +class CommonStream; + namespace internal { template @@ -20,6 +37,23 @@ void validateCreatedObjPtr(const LibObjPtrT libOjbPtr) } } +template +using DepType = + typename std::conditional::value, ConstDepObjT, DepObjT>::type; + +template +using DepUserAttrs = DepType, CommonMapValue>; + +template +using DepFc = + DepType, CommonFieldClass>; + +template +using DepPacket = DepType, CommonPacket>; + +template +using DepStream = DepType, CommonStream>; + template struct TypeDescr; diff --git a/src/cpp-common/bt2/message.hpp b/src/cpp-common/bt2/message.hpp index b3a6355b..1de0c481 100644 --- a/src/cpp-common/bt2/message.hpp +++ b/src/cpp-common/bt2/message.hpp @@ -230,10 +230,7 @@ class CommonStreamBeginningMessage final : public CommonMessage private: using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; - - using _Stream = - typename std::conditional::value, CommonStream, - CommonStream>::type; + using _Stream = internal::DepStream; public: using Shared = SharedMessage, LibObjT>; @@ -348,10 +345,7 @@ class CommonStreamEndMessage final : public CommonMessage private: using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; - - using _Stream = - typename std::conditional::value, CommonStream, - CommonStream>::type; + using _Stream = internal::DepStream; public: using Shared = SharedMessage, LibObjT>; @@ -465,10 +459,7 @@ class CommonPacketBeginningMessage final : public CommonMessage private: using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; - - using _Packet = - typename std::conditional::value, CommonPacket, - CommonPacket>::type; + using _Packet = internal::DepPacket; public: using Shared = SharedMessage, LibObjT>; @@ -578,10 +569,7 @@ class CommonPacketEndMessage final : public CommonMessage private: using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; - - using _Packet = - typename std::conditional::value, CommonPacket, - CommonPacket>::type; + using _Packet = internal::DepPacket; public: using Shared = SharedMessage, LibObjT>; @@ -690,10 +678,7 @@ class CommonEventMessage final : public CommonMessage private: using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; - - using _Event = - typename std::conditional::value, CommonEvent, - CommonEvent>::type; + using _Event = internal::DepType, CommonEvent>; public: using Shared = SharedMessage, LibObjT>; @@ -793,10 +778,7 @@ class CommonDiscardedEventsMessage final : public CommonMessage private: using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; - - using _Stream = - typename std::conditional::value, CommonStream, - CommonStream>::type; + using _Stream = internal::DepStream; public: using Shared = SharedMessage, LibObjT>; @@ -927,10 +909,7 @@ class CommonDiscardedPacketsMessage final : public CommonMessage private: using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; - - using _Stream = - typename std::conditional::value, CommonStream, - CommonStream>::type; + using _Stream = internal::DepStream; public: using Shared = SharedMessage, LibObjT>; diff --git a/src/cpp-common/bt2/trace-ir.hpp b/src/cpp-common/bt2/trace-ir.hpp index 0542cd95..245a9d4f 100644 --- a/src/cpp-common/bt2/trace-ir.hpp +++ b/src/cpp-common/bt2/trace-ir.hpp @@ -121,6 +121,9 @@ struct CommonEventSpec final } }; +template +using DepStructField = DepType; + } /* namespace internal */ template @@ -130,22 +133,13 @@ private: using typename BorrowedObject::_ThisBorrowedObject; using typename BorrowedObject::_LibObjPtr; using _Spec = internal::CommonEventSpec; - - using _Packet = - typename std::conditional::value, CommonPacket, - CommonPacket>::type; - - using _Stream = - typename std::conditional::value, CommonStream, - CommonStream>::type; - - using _StructureField = typename std::conditional::value, - ConstStructureField, StructureField>::type; + using _Packet = internal::DepPacket; + using _Stream = internal::DepStream; + using _StructureField = internal::DepStructField; public: - using Class = typename std::conditional::value, - CommonEventClass, - CommonEventClass>::type; + using Class = internal::DepType, + CommonEventClass>; explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} { @@ -283,13 +277,8 @@ private: using typename BorrowedObject::_LibObjPtr; using _Spec = internal::CommonPacketSpec; using _ThisCommonPacket = CommonPacket; - - using _Stream = - typename std::conditional::value, CommonStream, - CommonStream>::type; - - using _StructureField = typename std::conditional::value, - ConstStructureField, StructureField>::type; + using _Stream = internal::DepStream; + using _StructureField = internal::DepStructField; public: using Shared = SharedObject<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>; @@ -438,20 +427,14 @@ private: using typename BorrowedObject::_LibObjPtr; using _Spec = internal::CommonStreamSpec; using _ThisCommonStream = CommonStream; - - using _Trace = - typename std::conditional::value, CommonTrace, - CommonTrace>::type; + using _Trace = internal::DepType, CommonTrace>; public: using Shared = SharedObject<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>; + using UserAttributes = internal::DepUserAttrs; - using Class = typename std::conditional::value, - CommonStreamClass, - CommonStreamClass>::type; - - using UserAttributes = - typename std::conditional::value, ConstMapValue, MapValue>::type; + using Class = internal::DepType, + CommonStreamClass>; explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} { @@ -653,20 +636,14 @@ private: using typename BorrowedObject::_LibObjPtr; using _Spec = internal::CommonTraceSpec; using _ThisCommonTrace = CommonTrace; - - using _Stream = - typename std::conditional::value, CommonStream, - CommonStream>::type; + using _Stream = internal::DepStream; public: using Shared = SharedObject<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>; + using UserAttributes = internal::DepUserAttrs; - using Class = typename std::conditional::value, - CommonTraceClass, - CommonTraceClass>::type; - - using UserAttributes = - typename std::conditional::value, ConstMapValue, MapValue>::type; + using Class = internal::DepType, + CommonTraceClass>; struct ConstEnvironmentEntry { @@ -952,6 +929,9 @@ struct CommonEventClassSpec final } }; +template +using DepStructFc = DepType; + } /* namespace internal */ template @@ -962,20 +942,15 @@ private: using typename BorrowedObject::_LibObjPtr; using _Spec = internal::CommonEventClassSpec; using _ThisCommonEventClass = CommonEventClass; + using _StructureFieldClass = internal::DepStructFc; - using _StreamClass = typename std::conditional::value, - CommonStreamClass, - CommonStreamClass>::type; - - using _StructureFieldClass = - typename std::conditional::value, ConstStructureFieldClass, - StructureFieldClass>::type; + using _StreamClass = internal::DepType, + CommonStreamClass>; public: using Shared = SharedObject<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>; - using UserAttributes = - typename std::conditional::value, ConstMapValue, MapValue>::type; + using UserAttributes = internal::DepUserAttrs; enum class LogLevel { @@ -1307,27 +1282,20 @@ private: using typename BorrowedObject::_LibObjPtr; using _Spec = internal::CommonStreamClassSpec; using _ThisCommonStreamClass = CommonStreamClass; + using _StructureFieldClass = internal::DepStructFc; - using _TraceClass = typename std::conditional::value, - CommonTraceClass, - CommonTraceClass>::type; - - using _EventClass = typename std::conditional::value, - CommonEventClass, - CommonEventClass>::type; + using _TraceClass = internal::DepType, + CommonTraceClass>; - using _StructureFieldClass = - typename std::conditional::value, ConstStructureFieldClass, - StructureFieldClass>::type; + using _EventClass = internal::DepType, + CommonEventClass>; - using _ClockClass = - typename std::conditional::value, ConstClockClass, ClockClass>::type; + using _ClockClass = internal::DepType; public: using Shared = SharedObject<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>; - using UserAttributes = - typename std::conditional::value, ConstMapValue, MapValue>::type; + using UserAttributes = internal::DepUserAttrs; explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} @@ -1753,15 +1721,13 @@ private: using _Spec = internal::CommonTraceClassSpec; using _ThisCommonTraceClass = CommonTraceClass; - using _StreamClass = typename std::conditional::value, - CommonStreamClass, - CommonStreamClass>::type; + using _StreamClass = internal::DepType, + CommonStreamClass>; public: using Shared = SharedObject<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>; - using UserAttributes = - typename std::conditional::value, ConstMapValue, MapValue>::type; + using UserAttributes = internal::DepUserAttrs; explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} {