diff options
author | Jøger Hansegård <[email protected]> | 2023-10-31 19:35:07 +0100 |
---|---|---|
committer | Jøger Hansegård <[email protected]> | 2023-11-16 15:20:33 +0000 |
commit | c6a7c1b5e5235be369ec641fbd79035dc416c5eb (patch) | |
tree | 0c89008ee7538ad1bf160498811557197ef47a17 /src/tools/uic/cpp/cppwriteinitialization.cpp | |
parent | be62459ee5281b1bd323ef1346ef5051ed75d2bb (diff) |
Add QUniqueHandle - a general purpose RAII wrapper for non-memory types
When interfacing with C-style APIs, such as the Windows API, resources
are often represented using handle objects. Lifetime management of such
resources can be cumbersome and error prone, because typical handle
objects (ints) do not give any help to release resources, and to manage
ownership.
Although std::unique_ptr can be retro-fitted with a custom deleter, and
helps transfer of ownership, it is inherently a pointer type. It can
therefore be clumsy to use with C-style APIs, particularly if the
invalid (uninitialized) handle value is not a nullptr. Also, the
std::unique_ptr does not work well when an allocating function returns
the handle as a pointer argument.
The QUniqueHandle addresses these issues by providing a movable only
value type that is designed as a RAII handle wrapper.
A similar handle wrapper exists in the Windows SDK, as part of the WRL
library. Unfortunately, this is Microsoft specific, and is not supported
by MINGW.
Since the QUniqueHandle is platform independent, it can be used also
with non- Microsoft platforms, and can be useful with other C-style APIs
such as FFmpeg or SQLite.
Change-Id: Ibfc0cec3f361ec004febea5f284ebf75e27c0054
Reviewed-by: Tor Arne Vestbø <[email protected]>
Reviewed-by: Thiago Macieira <[email protected]>
Reviewed-by: Qt CI Bot <[email protected]>
(cherry picked from commit 8d367dec156c1aa63544bd851809caa7e72d307e)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
(cherry picked from commit 2168b0b18a2bd467098502e48cb9459f780e95cf)
Diffstat (limited to 'src/tools/uic/cpp/cppwriteinitialization.cpp')
0 files changed, 0 insertions, 0 deletions