From 3803ad86873f0d2513a440db947e9bad686bb5d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 13 Apr 2023 12:33:28 +0200 Subject: [PATCH] Trade: add DataFlag::Global. For more robust handling of non-owning *Data instanced and refcounting in Python bindings I need to differentiate between, say, a MeshData referencing global memory (such as Primitives::cubeSolid()) and MeshData referencing just some temporary allocation or another MeshData (such as the output of MeshTools::filterOnlyAttributes()). --- src/Magnum/Trade/Data.cpp | 2 ++ src/Magnum/Trade/Data.h | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Magnum/Trade/Data.cpp b/src/Magnum/Trade/Data.cpp index c3f9c9a52..da0f9300c 100644 --- a/src/Magnum/Trade/Data.cpp +++ b/src/Magnum/Trade/Data.cpp @@ -40,6 +40,7 @@ Debug& operator<<(Debug& debug, const DataFlag value) { #define _c(v) case DataFlag::v: return debug << (packed ? "" : "::") << Debug::nospace << #v; _c(Owned) _c(ExternallyOwned) + _c(Global) _c(Mutable) #undef _c /* LCOV_EXCL_STOP */ @@ -52,6 +53,7 @@ Debug& operator<<(Debug& debug, const DataFlags value) { return Containers::enumSetDebugOutput(debug, value, debug.immediateFlags() >= Debug::Flag::Packed ? "{}" : "Trade::DataFlags{}", { DataFlag::Owned, DataFlag::ExternallyOwned, + DataFlag::Global, DataFlag::Mutable}); } diff --git a/src/Magnum/Trade/Data.h b/src/Magnum/Trade/Data.h index 6468087fe..b907c4aee 100644 --- a/src/Magnum/Trade/Data.h +++ b/src/Magnum/Trade/Data.h @@ -48,28 +48,40 @@ importer itself. @see @ref DataFlags, @ref AnimationData::dataFlags(), @ref ImageData::dataFlags(), @ref MaterialData::attributeDataFlags(), @ref MaterialData::layerDataFlags(), @ref MeshData::indexDataFlags(), - @ref MeshData::vertexDataFlags(), @ref AbstractImporter::doOpenData() + @ref MeshData::vertexDataFlags(), @ref SceneData::dataFlags(), + @ref AbstractImporter::doOpenData() */ enum class DataFlag: UnsignedByte { /** * Data is owned by the instance, meaning it stays in scope for as long as - * the instance. If neither this flag nor @ref DataFlag::ExternallyOwned is - * set, the data is considered to be just a temporary allocation and no - * assumptions about its lifetime can be made. + * the instance. If neither @ref DataFlag::Owned, + * @ref DataFlag::ExternallyOwned nor @ref DataFlag::Global is set, the + * data is considered to be just a temporary allocation and no assumptions + * about its lifetime can be made. */ Owned = 1 << 0, /** * Data has an owner external to the instance, for example a memory-mapped * file or a constant memory. In general the data lifetime exceeds lifetime - * of the instance wrapping it. If neither this flag nor - * @ref DataFlag::ExternallyOwned is set, the data is considered to be just - * a temporary allocation and no assumptions about its lifetime can be - * made. + * of the instance wrapping it. If neither @ref DataFlag::Owned, + * @ref DataFlag::ExternallyOwned nor @ref DataFlag::Global is set, the + * data is considered to be just a temporary allocation and no assumptions + * about its lifetime can be made. * @m_since_latest */ ExternallyOwned = 1 << 3, + /** + * Data is global, for example stored in static memory, so guaranteed to + * never go out of scope. Usually such data are not @ref DataFlag::Mutable. + * If neither @ref DataFlag::Owned, @ref DataFlag::ExternallyOwned nor + * @ref DataFlag::Global is set, the data is considered to be just a + * temporary allocation and no assumptions about its lifetime can be made. + * @m_since_latest + */ + Global = 1 << 4, + /** * Data is mutable. If this flag is not set, the instance might be for * example referencing a readonly memory-mapped file or a constant memory.