Browse Source

Trade: got rid of opening input streams in AbstractImporter.

Now it is possible to open either pure data arrays or arrays specified
with filename. The function calls might be ambiguous now (i.e.
open("image.tga") would open data array instead of handling it as
filename), renamed them to avoid that. Default implementations now
fire an assertion. Bumped plugin interface string version as this is
pretty incompatible change.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
d6f5560262
  1. 20
      src/Trade/AbstractImporter.cpp
  2. 48
      src/Trade/AbstractImporter.h

20
src/Trade/AbstractImporter.cpp

@ -24,9 +24,7 @@
#include "AbstractImporter.h"
#include <Utility/Debug.h>
#include "Magnum.h"
#include <Utility/Assert.h>
namespace Magnum { namespace Trade {
@ -34,14 +32,18 @@ AbstractImporter::AbstractImporter() = default;
AbstractImporter::AbstractImporter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin): AbstractPlugin(manager, std::move(plugin)) {}
bool AbstractImporter::open(const std::string&) {
Error() << plugin() << "doesn't support opening files";
return false;
bool AbstractImporter::openData(const void* const, const std::size_t) {
CORRADE_ASSERT(features() & Feature::OpenData,
"Trade::AbstractImporter::openData(): feature advertised but not implemented", nullptr);
CORRADE_ASSERT(false, "Trade::AbstractImporter::openData(): feature not implemented", nullptr);
}
bool AbstractImporter::open(std::istream&) {
Error() << plugin() << "doesn't support opening input streams";
return false;
bool AbstractImporter::openFile(const std::string&) {
CORRADE_ASSERT(features() & Feature::OpenFile,
"Trade::AbstractImporter::openFile(): feature advertised but not implemented", nullptr);
CORRADE_ASSERT(false, "Trade::AbstractImporter::openFile(): feature not implemented", nullptr);
}
}}

48
src/Trade/AbstractImporter.h

@ -54,7 +54,7 @@ some data. This is obviously not the case for single-data formats like images,
as the file contains all data user wants to import.
*/
class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::AbstractPlugin {
PLUGIN_INTERFACE("cz.mosra.magnum.Trade.AbstractImporter/0.2")
PLUGIN_INTERFACE("cz.mosra.magnum.Trade.AbstractImporter/0.2.1")
public:
/**
@ -62,13 +62,13 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::AbstractPlu
*
* @see Features, features()
*/
enum class Feature {
OpenFile = 0x01, /**< Can open files specified by filename */
OpenStream = 0x02 /**< Can open files from input streams */
enum class Feature: UnsignedByte {
OpenData = 1 << 0, /**< Opening files from raw data */
OpenFile = 1 << 1 /**< Opening files specified by filename */
};
/** @brief Set of features supported by this importer */
typedef Corrade::Containers::EnumSet<Feature, int> Features;
typedef Corrade::Containers::EnumSet<Feature, UnsignedByte> Features;
/** @brief Default constructor */
explicit AbstractImporter();
@ -80,26 +80,38 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::AbstractPlu
virtual Features features() const = 0;
/**
* @brief Open file
* @param filename Filename
* @return Whether the file was successfully opened
* @brief Open raw data
* @param data Data
* @param size Data size
*
* Closes previous file, if it was opened, and tries to open given
* file. See also @ref Feature "Feature::OpenFile". Default
* implementation prints message to error output and returns false.
* file. Available only if @ref Feature "Feature::OpenData" is
* supported. Returns `true` on success, `false` otherwise.
* @see features(), openFile()
*/
virtual bool open(const std::string& filename);
virtual bool openData(const void* const data, const std::size_t size);
/**
* @brief Open stream
* @param in Input stream
* @return Whether the file was successfully opened
* @brief Open raw data
* @param data Data
*
* See also open(const std::string&), @ref Feature
* "Feature::OpenStream". Default implementation prints message to
* error output and returns false.
* Convenience alternative to above function useful when array size is
* known at compile-time.
*/
template<std::size_t size, class T> inline bool openData(const T(&data)[size]) {
return openData(data, size*sizeof(T));
}
/**
* @brief Open file
* @param filename Filename
*
* Closes previous file, if it was opened, and tries to open given
* file. Available only if @ref Feature "Feature::OpenFile" is
* supported. Returns `true` on success, `false` otherwise.
* @see features(), openData()
*/
virtual bool open(std::istream& in);
virtual bool openFile(const std::string& filename);
/** @brief Close file */
virtual void close() = 0;

Loading…
Cancel
Save