diff options
| author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-07-29 16:34:44 +0200 |
|---|---|---|
| committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-07-31 09:46:54 +0200 |
| commit | cb8072028753c32b11f6838cf8717f5414511975 (patch) | |
| tree | 74f6f6999acdfc68856f780cf19bcce54a4d4a3c /src | |
| parent | 61ccfefb25d61da95a1a1cdf0313da1448dc23c6 (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')
| -rw-r--r-- | src/corelib/kernel/qmetatype.cpp | 25 | ||||
| -rw-r--r-- | src/corelib/kernel/qmetatype.h | 1 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index ba3d788d53b..1422e60a1c6 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) { diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index f89ece7d23f..88a888c956d 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -505,6 +505,7 @@ public: bool isRegistered() const; int id() const; int sizeOf() const; + int alignOf() const; TypeFlags flags() const; const QMetaObject *metaObject() const; QT_PREPEND_NAMESPACE(QByteArray) name() const; |
