Browse Source

Trade: make AbstractImporter::defaultScene() const.

Makes more sense as the function isn't expected to fail (and thus any
kind of lazy population is not possible as it would be too late for
error checks anyway).

*Not* updating interface strings even though this is an ABI break
because we're doing that right after the skin import interface bump.
pull/470/head
Vladimír Vondruš 6 years ago
parent
commit
ddb7185417
  1. 6
      doc/changelog.dox
  2. 4
      src/Magnum/Trade/AbstractImporter.cpp
  3. 12
      src/Magnum/Trade/AbstractImporter.h
  4. 2
      src/Magnum/Trade/Test/AbstractImporterTest.cpp
  5. 2
      src/MagnumPlugins/AnySceneImporter/AnySceneImporter.cpp
  6. 2
      src/MagnumPlugins/AnySceneImporter/AnySceneImporter.h

6
doc/changelog.dox

@ -248,6 +248,12 @@ See also:
@cpp Trade::AbstractMaterialData @ce aliases to, doesn't have a @cpp Trade::AbstractMaterialData @ce aliases to, doesn't have a
@cpp virtual @ce destructor as subclasses with extra data members aren't a @cpp virtual @ce destructor as subclasses with extra data members aren't a
desired use case anymore. desired use case anymore.
- @ref Trade::AbstractImporter::doDefaultScene() is now @cpp const @ce ---
since the function is not expected to fail, no kind of complex lazy
population can be done anyway. This is now consistent with `do*Count()`
interfaces, which are also @cpp const @ce and can't fail. Documentation of
each function was expanded to suggest a recommended place for potential
error handling.
@section changelog-2020-06 2020.06 @section changelog-2020-06 2020.06

4
src/Magnum/Trade/AbstractImporter.cpp

@ -212,12 +212,12 @@ void AbstractImporter::close() {
} }
} }
Int AbstractImporter::defaultScene() { Int AbstractImporter::defaultScene() const {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::defaultScene(): no file opened", -1); CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::defaultScene(): no file opened", -1);
return doDefaultScene(); return doDefaultScene();
} }
Int AbstractImporter::doDefaultScene() { return -1; } Int AbstractImporter::doDefaultScene() const { return -1; }
UnsignedInt AbstractImporter::sceneCount() const { UnsignedInt AbstractImporter::sceneCount() const {
CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::sceneCount(): no file opened", 0); CORRADE_ASSERT(isOpened(), "Trade::AbstractImporter::sceneCount(): no file opened", 0);

12
src/Magnum/Trade/AbstractImporter.h

@ -537,11 +537,8 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
* When there is more than one scene, returns ID of the default one. * When there is more than one scene, returns ID of the default one.
* If there is no default scene, returns @cpp -1 @ce. Expects that a * If there is no default scene, returns @cpp -1 @ce. Expects that a
* file is opened. * file is opened.
*
* @note The function is not const, because the value will probably
* be lazy-populated.
*/ */
Int defaultScene(); Int defaultScene() const;
/** /**
* @brief Scene count * @brief Scene count
@ -1475,9 +1472,12 @@ class MAGNUM_TRADE_EXPORT AbstractImporter: public PluginManager::AbstractManagi
/** /**
* @brief Implementation for @ref defaultScene() * @brief Implementation for @ref defaultScene()
* *
* Default implementation returns @cpp -1 @ce. * Default implementation returns @cpp -1 @ce. This function isn't
* expected to fail --- if an import error occus (for example because
* the default scene index is out of bounds), it should be handled
* already during file opening.
*/ */
virtual Int doDefaultScene(); virtual Int doDefaultScene() const;
/** /**
* @brief Implementation for @ref sceneCount() * @brief Implementation for @ref sceneCount()

2
src/Magnum/Trade/Test/AbstractImporterTest.cpp

@ -1431,7 +1431,7 @@ void AbstractImporterTest::defaultScene() {
bool doIsOpened() const override { return true; } bool doIsOpened() const override { return true; }
void doClose() override {} void doClose() override {}
Int doDefaultScene() override { return 42; } Int doDefaultScene() const override { return 42; }
} importer; } importer;
CORRADE_COMPARE(importer.defaultScene(), 42); CORRADE_COMPARE(importer.defaultScene(), 42);

2
src/MagnumPlugins/AnySceneImporter/AnySceneImporter.cpp

@ -165,7 +165,7 @@ Int AnySceneImporter::doAnimationForName(const std::string& name) { return _in->
std::string AnySceneImporter::doAnimationName(const UnsignedInt id) { return _in->animationName(id); } std::string AnySceneImporter::doAnimationName(const UnsignedInt id) { return _in->animationName(id); }
Containers::Optional<AnimationData> AnySceneImporter::doAnimation(const UnsignedInt id) { return _in->animation(id); } Containers::Optional<AnimationData> AnySceneImporter::doAnimation(const UnsignedInt id) { return _in->animation(id); }
Int AnySceneImporter::doDefaultScene() { return _in->defaultScene(); } Int AnySceneImporter::doDefaultScene() const { return _in->defaultScene(); }
UnsignedInt AnySceneImporter::doSceneCount() const { return _in->sceneCount(); } UnsignedInt AnySceneImporter::doSceneCount() const { return _in->sceneCount(); }
Int AnySceneImporter::doSceneForName(const std::string& name) { return _in->sceneForName(name); } Int AnySceneImporter::doSceneForName(const std::string& name) { return _in->sceneForName(name); }

2
src/MagnumPlugins/AnySceneImporter/AnySceneImporter.h

@ -149,7 +149,7 @@ class MAGNUM_ANYSCENEIMPORTER_EXPORT AnySceneImporter: public AbstractImporter {
MAGNUM_ANYSCENEIMPORTER_LOCAL Int doAnimationForName(const std::string& name) override; MAGNUM_ANYSCENEIMPORTER_LOCAL Int doAnimationForName(const std::string& name) override;
MAGNUM_ANYSCENEIMPORTER_LOCAL Containers::Optional<AnimationData> doAnimation(UnsignedInt id) override; MAGNUM_ANYSCENEIMPORTER_LOCAL Containers::Optional<AnimationData> doAnimation(UnsignedInt id) override;
MAGNUM_ANYSCENEIMPORTER_LOCAL Int doDefaultScene() override; MAGNUM_ANYSCENEIMPORTER_LOCAL Int doDefaultScene() const override;
MAGNUM_ANYSCENEIMPORTER_LOCAL UnsignedInt doSceneCount() const override; MAGNUM_ANYSCENEIMPORTER_LOCAL UnsignedInt doSceneCount() const override;
MAGNUM_ANYSCENEIMPORTER_LOCAL Int doSceneForName(const std::string& name) override; MAGNUM_ANYSCENEIMPORTER_LOCAL Int doSceneForName(const std::string& name) override;

Loading…
Cancel
Save