From cb8072028753c32b11f6838cf8717f5414511975 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Wed, 29 Jul 2020 16:34:44 +0200 Subject: Expose QMetaTypeInterface::alignof in QMetaType We already have the information in the QMetaTypeInterface, and provide functions to access sizeof. Adding alignof support seems natural, and should make it easier to handle over-aligned types. This should also be helpful in QVariant. Change-Id: I166be76f4b7d2d2e524a3a1e513bd2f361e887c1 Reviewed-by: Lars Knoll --- src/corelib/kernel/qmetatype.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/corelib/kernel/qmetatype.cpp') diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index ba3d788d53..1422e60a1c 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -500,7 +500,7 @@ int QMetaType::id() const This function is typically used together with construct() to perform low-level management of the memory used by a type. - \sa QMetaType::construct(), QMetaType::sizeOf() + \sa QMetaType::construct(), QMetaType::sizeOf(), QMetaType::alignOf() */ int QMetaType::sizeOf() const { @@ -509,6 +509,27 @@ int QMetaType::sizeOf() const return 0; } +/*! + \fn int QMetaType::alignOf() const + \since 6.0 + + Returns the alignment of the type in bytes (i.e. alignof(T), + where T is the actual type for which this QMetaType instance + was constructed for). + + This function is typically used together with construct() + to perform low-level management of the memory used by a type. + + \sa QMetaType::construct(), QMetaType::sizeOf() + + */ +int QMetaType::alignOf() const +{ + if (d_ptr) + return d_ptr->alignment; + return 0; +} + /*! \fn TypeFlags QMetaType::flags() const \since 5.0 @@ -1585,7 +1606,7 @@ void QMetaType::destruct(int type, void *where) This function is typically used together with construct() to perform low-level management of the memory used by a type. - \sa construct() + \sa construct(), QMetaType::alignOf() */ int QMetaType::sizeOf(int type) { -- cgit v1.2.3