From df91532ed6ba31c3dc5c4dcde33d9a4b0b805907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 5 Sep 2013 00:13:51 +0200 Subject: [PATCH] Trade: using `std::unique_ptr` when returning polymorphic types. This requires inclusion of heavyweight header (~25k LOC), but data import isn't something the user would want to do in every file, so it hopefully won't hurt compilation times too much. --- src/Trade/AbstractImporter.cpp | 15 +++++++++------ src/Trade/AbstractImporter.h | 22 ++++++++++------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Trade/AbstractImporter.cpp b/src/Trade/AbstractImporter.cpp index c4b3005e6..f6b8dd3f8 100644 --- a/src/Trade/AbstractImporter.cpp +++ b/src/Trade/AbstractImporter.cpp @@ -28,11 +28,14 @@ #include #include +#include "Trade/AbstractMaterialData.h" #include "Trade/CameraData.h" #include "Trade/ImageData.h" #include "Trade/LightData.h" #include "Trade/MeshData2D.h" #include "Trade/MeshData3D.h" +#include "Trade/ObjectData2D.h" +#include "Trade/ObjectData3D.h" #include "Trade/SceneData.h" #include "Trade/TextureData.h" @@ -209,13 +212,13 @@ std::string AbstractImporter::object2DName(const UnsignedInt id) { std::string AbstractImporter::doObject2DName(UnsignedInt) { return {}; } -ObjectData2D* AbstractImporter::object2D(const UnsignedInt id) { +std::unique_ptr AbstractImporter::object2D(const UnsignedInt id) { CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::object2D(): no file opened", {}); CORRADE_ASSERT(id < doObject2DCount(), "Trade::AbstractImporter::object2D(): index out of range", {}); return doObject2D(id); } -ObjectData2D* AbstractImporter::doObject2D(UnsignedInt) { return nullptr; } +std::unique_ptr AbstractImporter::doObject2D(UnsignedInt) { return nullptr; } UnsignedInt AbstractImporter::object3DCount() const { CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::object3DCount(): no file opened", {}); @@ -239,13 +242,13 @@ std::string AbstractImporter::object3DName(const UnsignedInt id) { std::string AbstractImporter::doObject3DName(UnsignedInt) { return {}; } -ObjectData3D* AbstractImporter::object3D(const UnsignedInt id) { +std::unique_ptr AbstractImporter::object3D(const UnsignedInt id) { CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::object3D(): no file opened", {}); CORRADE_ASSERT(id < doObject3DCount(), "Trade::AbstractImporter::object3D(): index out of range", {}); return doObject3D(id); } -ObjectData3D* AbstractImporter::doObject3D(UnsignedInt) { return nullptr; } +std::unique_ptr AbstractImporter::doObject3D(UnsignedInt) { return nullptr; } UnsignedInt AbstractImporter::mesh2DCount() const { CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::mesh2DCount(): no file opened", {}); @@ -329,13 +332,13 @@ std::string AbstractImporter::materialName(const UnsignedInt id) { std::string AbstractImporter::doMaterialName(UnsignedInt) { return {}; } -AbstractMaterialData* AbstractImporter::material(const UnsignedInt id) { +std::unique_ptr AbstractImporter::material(const UnsignedInt id) { CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::material(): no file opened", {}); CORRADE_ASSERT(id < doMaterialCount(), "Trade::AbstractImporter::material(): index out of range", {}); return doMaterial(id); } -AbstractMaterialData* AbstractImporter::doMaterial(UnsignedInt) { return nullptr; } +std::unique_ptr AbstractImporter::doMaterial(UnsignedInt) { return nullptr; } UnsignedInt AbstractImporter::textureCount() const { CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::textureCount(): no file opened", {}); diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index 356a636e2..20aff4140 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -28,6 +28,7 @@ * @brief Class Magnum::Trade::AbstractImporter */ +#include #include #include @@ -240,10 +241,9 @@ class MAGNUM_EXPORT AbstractImporter: public PluginManager::AbstractPlugin { * @brief Two-dimensional object * @param id Object ID, from range [0, object2DCount()). * - * Returns given object or `nullptr` if importing failed. Deleting the - * data is user responsibility. + * Returns given object or `nullptr` if importing failed. */ - ObjectData2D* object2D(UnsignedInt id); + std::unique_ptr object2D(UnsignedInt id); /** @brief Three-dimensional object count */ UnsignedInt object3DCount() const; @@ -268,10 +268,9 @@ class MAGNUM_EXPORT AbstractImporter: public PluginManager::AbstractPlugin { * @brief Three-dimensional object * @param id Object ID, from range [0, object3DCount()). * - * Returns given object or `nullptr` if importing failed. Deleting the - * data is user responsibility. + * Returns given object or `nullptr` if importing failed. */ - ObjectData3D* object3D(UnsignedInt id); + std::unique_ptr object3D(UnsignedInt id); /** @brief Two-dimensional mesh count */ UnsignedInt mesh2DCount() const; @@ -350,10 +349,9 @@ class MAGNUM_EXPORT AbstractImporter: public PluginManager::AbstractPlugin { * @brief Material * @param id Material ID, from range [0, materialCount()). * - * Returns given material or `nullptr` if importing failed. Deleting - * the data is user responsibility. + * Returns given material or `nullptr` if importing failed. */ - AbstractMaterialData* material(UnsignedInt id); + std::unique_ptr material(UnsignedInt id); /** @brief %Texture count */ UnsignedInt textureCount() const; @@ -539,7 +537,7 @@ class MAGNUM_EXPORT AbstractImporter: public PluginManager::AbstractPlugin { virtual std::string doObject2DName(UnsignedInt id); /** @brief Implementation for object2D() */ - virtual ObjectData2D* doObject2D(UnsignedInt id); + virtual std::unique_ptr doObject2D(UnsignedInt id); /** @brief Implementation for object3DCount() */ virtual UnsignedInt doObject3DCount() const; @@ -551,7 +549,7 @@ class MAGNUM_EXPORT AbstractImporter: public PluginManager::AbstractPlugin { virtual std::string doObject3DName(UnsignedInt id); /** @brief Implementation for object3D() */ - virtual ObjectData3D* doObject3D(UnsignedInt id); + virtual std::unique_ptr doObject3D(UnsignedInt id); /** @brief Implementation for mesh2DCount() */ virtual UnsignedInt doMesh2DCount() const; @@ -587,7 +585,7 @@ class MAGNUM_EXPORT AbstractImporter: public PluginManager::AbstractPlugin { virtual std::string doMaterialName(UnsignedInt id); /** @brief Implementation for material() */ - virtual AbstractMaterialData* doMaterial(UnsignedInt id); + virtual std::unique_ptr doMaterial(UnsignedInt id); /** @brief Implementation for textureCount() */ virtual UnsignedInt doTextureCount() const;