diff --git a/src/AbstractImporter.cpp b/src/AbstractImporter.cpp new file mode 100644 index 000000000..c932f32a5 --- /dev/null +++ b/src/AbstractImporter.cpp @@ -0,0 +1,33 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "AbstractImporter.h" + +using namespace std; +using namespace Corrade::Utility; + +namespace Magnum { + +bool AbstractImporter::open(const std::string& filename) { + Error() << plugin() << "doesn't support opening files"; + return false; +} + +bool AbstractImporter::open(std::istream& in) { + Error() << plugin() << "doesn't support opening input streams"; + return false; +} + +} diff --git a/src/AbstractImporter.h b/src/AbstractImporter.h index b215c86a5..b6cc3994f 100644 --- a/src/AbstractImporter.h +++ b/src/AbstractImporter.h @@ -42,8 +42,9 @@ Importer is used for importing data like scenes, lights, objects, images, textures etc. @section AbstractImporterSubclassing Subclassing -

Plugin implements functions open(), close() and one or more pairs of data -access functions, based on which features are supported in given format.

+

Plugin implements function features(), one or more open() functions, +function close() and one or more pairs of data access functions, based on +which features are supported in given format.

For multi-data formats file opening shouldn't take long, all parsing should be done in data parsing functions, because the user might want to import only some data. This is obviously not the case for single-data formats like images, @@ -69,17 +70,41 @@ class AbstractImporter: public Corrade::PluginManager::Plugin { public: struct MeshData; + /** @brief Features supported by this importer */ + enum Feature { + OpenFile = 0x01, /**< Can open files specified by filename */ + OpenStream = 0x02, /**< Can open files from input streams */ + }; + /** @brief Constructor */ AbstractImporter(Corrade::PluginManager::AbstractPluginManager* manager = nullptr, const std::string& plugin = ""): Plugin(manager, plugin) {} + /** + * @brief Features supported by this importer + * @return OR-ed combination of values from Feature enum. + */ + virtual int features() const = 0; + /** * @brief Open file + * @param filename Filename + * @return Whether the file was successfully opened + * + * Closes previous file, if it was opened, and tries to open given + * file. See also Feature::OpenFile. Default implementation prints + * message to error output and returns false. + */ + virtual bool open(const std::string& filename); + + /** + * @brief Open stream * @param in Input stream * @return Whether the file was successfully opened * - * Closes previous file, if it was opened, and tries to open given file. + * See also open(const std::string&), Feature::OpenStream. Default + * implementation prints message to error output and returns false. */ - virtual bool open(std::istream& in) = 0; + virtual bool open(std::istream& in); /** @brief Close file */ virtual void close() = 0; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 67ecd37bc..368d66a5c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,7 @@ add_subdirectory(MeshTools) add_subdirectory(Primitives) set(Magnum_SRCS + AbstractImporter.cpp Object.cpp AbstractTexture.cpp AbstractShaderProgram.cpp