Browse Source

AbstractImporter: allow direct file opening, added Feature enum.

Each importer must now specify whether it can open files or streams in
features() and implement one or both open() functions. Default
implementation of open() functions now prints message on error output
and returns false.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
96b072f87d
  1. 33
      src/AbstractImporter.cpp
  2. 33
      src/AbstractImporter.h
  3. 1
      src/CMakeLists.txt

33
src/AbstractImporter.cpp

@ -0,0 +1,33 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
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;
}
}

33
src/AbstractImporter.h

@ -42,8 +42,9 @@ Importer is used for importing data like scenes, lights, objects, images,
textures etc. textures etc.
@section AbstractImporterSubclassing Subclassing @section AbstractImporterSubclassing Subclassing
<p>Plugin implements functions open(), close() and one or more pairs of data <p>Plugin implements function features(), one or more open() functions,
access functions, based on which features are supported in given format.</p> function close() and one or more pairs of data access functions, based on
which features are supported in given format.</p>
<p>For multi-data formats file opening shouldn't take long, all parsing should <p>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 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, 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: public:
struct MeshData; 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 */ /** @brief Constructor */
AbstractImporter(Corrade::PluginManager::AbstractPluginManager* manager = nullptr, const std::string& plugin = ""): Plugin(manager, plugin) {} 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 * @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 * @param in Input stream
* @return Whether the file was successfully opened * @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 */ /** @brief Close file */
virtual void close() = 0; virtual void close() = 0;

1
src/CMakeLists.txt

@ -7,6 +7,7 @@ add_subdirectory(MeshTools)
add_subdirectory(Primitives) add_subdirectory(Primitives)
set(Magnum_SRCS set(Magnum_SRCS
AbstractImporter.cpp
Object.cpp Object.cpp
AbstractTexture.cpp AbstractTexture.cpp
AbstractShaderProgram.cpp AbstractShaderProgram.cpp

Loading…
Cancel
Save