From 5a1f3e8dd1bfc80157e16b5cbb6824e2c7748c2b Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Wed, 6 Oct 2021 18:11:29 +0100 Subject: [PATCH] Explicit template instantiations for mixins for PQ and units --- src/blackmisc/pq/physicalquantity.cpp | 10 +++++ src/blackmisc/pq/physicalquantity.h | 57 ++++++++++++++++++++++++++- src/blackmisc/pq/units.cpp | 10 +++++ src/blackmisc/pq/units.h | 48 ++++++++++++++++++++++ 4 files changed, 124 insertions(+), 1 deletion(-) diff --git a/src/blackmisc/pq/physicalquantity.cpp b/src/blackmisc/pq/physicalquantity.cpp index 3dd079165..8a0993f14 100644 --- a/src/blackmisc/pq/physicalquantity.cpp +++ b/src/blackmisc/pq/physicalquantity.cpp @@ -36,6 +36,16 @@ #include #include +BLACK_DEFINE_PQ_MIXINS(CAngleUnit, CAngle) +BLACK_DEFINE_PQ_MIXINS(CLengthUnit, CLength) +BLACK_DEFINE_PQ_MIXINS(CPressureUnit, CPressure) +BLACK_DEFINE_PQ_MIXINS(CFrequencyUnit, CFrequency) +BLACK_DEFINE_PQ_MIXINS(CMassUnit, CMass) +BLACK_DEFINE_PQ_MIXINS(CTemperatureUnit, CTemperature) +BLACK_DEFINE_PQ_MIXINS(CSpeedUnit, CSpeed) +BLACK_DEFINE_PQ_MIXINS(CTimeUnit, CTime) +BLACK_DEFINE_PQ_MIXINS(CAccelerationUnit, CAcceleration) + namespace BlackMisc::PhysicalQuantities { template diff --git a/src/blackmisc/pq/physicalquantity.h b/src/blackmisc/pq/physicalquantity.h index 84c5d8883..cf7516154 100644 --- a/src/blackmisc/pq/physicalquantity.h +++ b/src/blackmisc/pq/physicalquantity.h @@ -28,6 +28,62 @@ #include #include +namespace BlackMisc::PhysicalQuantities +{ + template class CPhysicalQuantity; +} + +//! \cond +#define BLACK_TEMPLATE_PQ_MIXINS(MU, PQ, Extern, Export) \ + namespace BlackMisc::PhysicalQuantities { class PQ; } \ + namespace BlackMisc::Private \ + { \ + Extern template struct Export CValueObjectMetaInfo; \ + Extern template struct Export MetaTypeHelper; \ + } \ + namespace BlackMisc::Mixin \ + { \ + Extern template class Export DBusOperators>; \ + Extern template class Export DataStreamOperators>;\ + Extern template class Export JsonOperators>; \ + Extern template class Export Index; \ + Extern template class Export MetaType; \ + Extern template class Export String; \ + Extern template class Export Icon>; \ + } +//! \endcond + +/*! + * \def BLACK_DECLARE_PQ_MIXINS + * Explicit template declaration of mixins for a CPhysicalQuantity subclass + * to be placed near the top of the header that defines the class + */ + +/*! + * \def BLACK_DEFINE_PQ_MIXINS + * Explicit template definition of mixins for a CPhysicalQuantity subclass + */ +#if defined(Q_OS_WIN) && defined(Q_CC_GNU) +# define BLACK_DECLARE_PQ_MIXINS(MU, PQ) +# define BLACK_DEFINE_PQ_MIXINS(MU, PQ) +#elif defined(Q_OS_WIN) && defined(Q_CC_CLANG) +# define BLACK_DECLARE_PQ_MIXINS(MU, PQ) BLACK_TEMPLATE_PQ_MIXINS(MU, PQ, extern, ) +# define BLACK_DEFINE_PQ_MIXINS(MU, PQ) BLACK_TEMPLATE_PQ_MIXINS(MU, PQ, , BLACKMISC_EXPORT) +#else +# define BLACK_DECLARE_PQ_MIXINS(MU, PQ) BLACK_TEMPLATE_PQ_MIXINS(MU, PQ, extern, ) +# define BLACK_DEFINE_PQ_MIXINS(MU, PQ) BLACK_TEMPLATE_PQ_MIXINS(MU, PQ, , ) +#endif + +BLACK_DECLARE_PQ_MIXINS(CAngleUnit, CAngle) +BLACK_DECLARE_PQ_MIXINS(CLengthUnit, CLength) +BLACK_DECLARE_PQ_MIXINS(CPressureUnit, CPressure) +BLACK_DECLARE_PQ_MIXINS(CFrequencyUnit, CFrequency) +BLACK_DECLARE_PQ_MIXINS(CMassUnit, CMass) +BLACK_DECLARE_PQ_MIXINS(CTemperatureUnit, CTemperature) +BLACK_DECLARE_PQ_MIXINS(CSpeedUnit, CSpeed) +BLACK_DECLARE_PQ_MIXINS(CTimeUnit, CTime) +BLACK_DECLARE_PQ_MIXINS(CAccelerationUnit, CAcceleration) + namespace BlackMisc::PhysicalQuantities { class CAngle; @@ -38,7 +94,6 @@ namespace BlackMisc::PhysicalQuantities class CTemperature; class CSpeed; class CTime; - class CPressure; class CAcceleration; /*! diff --git a/src/blackmisc/pq/units.cpp b/src/blackmisc/pq/units.cpp index 9891bd57d..1f09ce932 100644 --- a/src/blackmisc/pq/units.cpp +++ b/src/blackmisc/pq/units.cpp @@ -11,6 +11,16 @@ #include +BLACK_DEFINE_UNIT_MIXINS(CAngleUnit) +BLACK_DEFINE_UNIT_MIXINS(CLengthUnit) +BLACK_DEFINE_UNIT_MIXINS(CPressureUnit) +BLACK_DEFINE_UNIT_MIXINS(CFrequencyUnit) +BLACK_DEFINE_UNIT_MIXINS(CMassUnit) +BLACK_DEFINE_UNIT_MIXINS(CTemperatureUnit) +BLACK_DEFINE_UNIT_MIXINS(CSpeedUnit) +BLACK_DEFINE_UNIT_MIXINS(CTimeUnit) +BLACK_DEFINE_UNIT_MIXINS(CAccelerationUnit) + namespace BlackMisc::PhysicalQuantities { using BlackMisc::Math::CMathUtils; diff --git a/src/blackmisc/pq/units.h b/src/blackmisc/pq/units.h index ce6459dcb..8c6ab9e57 100644 --- a/src/blackmisc/pq/units.h +++ b/src/blackmisc/pq/units.h @@ -29,6 +29,54 @@ #include #include +//! \cond +#define BLACK_TEMPLATE_UNIT_MIXINS(MU, Extern, Export) \ + namespace BlackMisc::PhysicalQuantities { class MU; } \ + namespace BlackMisc::Private \ + { \ + Extern template struct Export CValueObjectMetaInfo; \ + Extern template struct Export MetaTypeHelper; \ + } \ + namespace BlackMisc::Mixin \ + { \ + Extern template class Export MetaType; \ + Extern template class Export DBusOperators; \ + Extern template class Export DataStreamOperators; \ + Extern template class Export Index; \ + } +//! \endcond + +/*! + * \def BLACK_DECLARE_UNIT_MIXINS + * Explicit template declaration of mixins for a CMeasurementUnit subclass + * to be placed near the top of the header that defines the class + */ + +/*! + * \def BLACK_DEFINE_UNIT_MIXINS + * Explicit template definition of mixins for a CMeasurementUnit subclass + */ +#if defined(Q_OS_WIN) && defined(Q_CC_GNU) +# define BLACK_DECLARE_UNIT_MIXINS(MU) +# define BLACK_DEFINE_UNIT_MIXINS(MU) +#elif defined(Q_OS_WIN) && defined(Q_CC_CLANG) +# define BLACK_DECLARE_UNIT_MIXINS(MU) BLACK_TEMPLATE_UNIT_MIXINS(MU, extern, ) +# define BLACK_DEFINE_UNIT_MIXINS(MU) BLACK_TEMPLATE_UNIT_MIXINS(MU, , BLACKMISC_EXPORT) +#else +# define BLACK_DECLARE_UNIT_MIXINS(MU) BLACK_TEMPLATE_UNIT_MIXINS(MU, extern, ) +# define BLACK_DEFINE_UNIT_MIXINS(MU) BLACK_TEMPLATE_UNIT_MIXINS(MU, , ) +#endif + +BLACK_DECLARE_UNIT_MIXINS(CAngleUnit) +BLACK_DECLARE_UNIT_MIXINS(CLengthUnit) +BLACK_DECLARE_UNIT_MIXINS(CPressureUnit) +BLACK_DECLARE_UNIT_MIXINS(CFrequencyUnit) +BLACK_DECLARE_UNIT_MIXINS(CMassUnit) +BLACK_DECLARE_UNIT_MIXINS(CTemperatureUnit) +BLACK_DECLARE_UNIT_MIXINS(CSpeedUnit) +BLACK_DECLARE_UNIT_MIXINS(CTimeUnit) +BLACK_DECLARE_UNIT_MIXINS(CAccelerationUnit) + // // Used with the template for quantities. This is the reason for // having all units in one file, since template requires concrete instantiations