Browse Source

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()).
pull/617/head
Vladimír Vondruš 3 years ago
parent
commit
3803ad8687
  1. 2
      src/Magnum/Trade/Data.cpp
  2. 28
      src/Magnum/Trade/Data.h

2
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; #define _c(v) case DataFlag::v: return debug << (packed ? "" : "::") << Debug::nospace << #v;
_c(Owned) _c(Owned)
_c(ExternallyOwned) _c(ExternallyOwned)
_c(Global)
_c(Mutable) _c(Mutable)
#undef _c #undef _c
/* LCOV_EXCL_STOP */ /* 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{}", { return Containers::enumSetDebugOutput(debug, value, debug.immediateFlags() >= Debug::Flag::Packed ? "{}" : "Trade::DataFlags{}", {
DataFlag::Owned, DataFlag::Owned,
DataFlag::ExternallyOwned, DataFlag::ExternallyOwned,
DataFlag::Global,
DataFlag::Mutable}); DataFlag::Mutable});
} }

28
src/Magnum/Trade/Data.h

@ -48,28 +48,40 @@ importer itself.
@see @ref DataFlags, @ref AnimationData::dataFlags(), @see @ref DataFlags, @ref AnimationData::dataFlags(),
@ref ImageData::dataFlags(), @ref MaterialData::attributeDataFlags(), @ref ImageData::dataFlags(), @ref MaterialData::attributeDataFlags(),
@ref MaterialData::layerDataFlags(), @ref MeshData::indexDataFlags(), @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 { enum class DataFlag: UnsignedByte {
/** /**
* Data is owned by the instance, meaning it stays in scope for as long as * 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 * the instance. If neither @ref DataFlag::Owned,
* set, the data is considered to be just a temporary allocation and no * @ref DataFlag::ExternallyOwned nor @ref DataFlag::Global is set, the
* assumptions about its lifetime can be made. * data is considered to be just a temporary allocation and no assumptions
* about its lifetime can be made.
*/ */
Owned = 1 << 0, Owned = 1 << 0,
/** /**
* Data has an owner external to the instance, for example a memory-mapped * 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 * file or a constant memory. In general the data lifetime exceeds lifetime
* of the instance wrapping it. If neither this flag nor * of the instance wrapping it. If neither @ref DataFlag::Owned,
* @ref DataFlag::ExternallyOwned is set, the data is considered to be just * @ref DataFlag::ExternallyOwned nor @ref DataFlag::Global is set, the
* a temporary allocation and no assumptions about its lifetime can be * data is considered to be just a temporary allocation and no assumptions
* made. * about its lifetime can be made.
* @m_since_latest * @m_since_latest
*/ */
ExternallyOwned = 1 << 3, 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 * 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. * example referencing a readonly memory-mapped file or a constant memory.

Loading…
Cancel
Save