summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmetatype.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-07-29 16:34:44 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2020-07-31 09:46:54 +0200
commitcb8072028753c32b11f6838cf8717f5414511975 (patch)
tree74f6f6999acdfc68856f780cf19bcce54a4d4a3c /src/corelib/kernel/qmetatype.cpp
parent61ccfefb25d61da95a1a1cdf0313da1448dc23c6 (diff)
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 <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/kernel/qmetatype.cpp')
-rw-r--r--src/corelib/kernel/qmetatype.cpp25
1 files changed, 23 insertions, 2 deletions
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
{
@@ -510,6 +510,27 @@ int QMetaType::sizeOf() const
}
/*!
+ \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)
{