From 133eda0c2129e162ccbd149a808246cc7d3625f2 Mon Sep 17 00:00:00 2001 From: danij Date: Sun, 3 Mar 2013 21:42:34 +0000 Subject: [PATCH] MaterialScheme: Improved public interface --- .../client/include/resource/materialscheme.h | 6 ++++++ doomsday/client/src/resource/materials.cpp | 11 ++++------ .../client/src/resource/materialscheme.cpp | 20 ++++++++++++------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/doomsday/client/include/resource/materialscheme.h b/doomsday/client/include/resource/materialscheme.h index e02896d256..b9d533ce63 100644 --- a/doomsday/client/include/resource/materialscheme.h +++ b/doomsday/client/include/resource/materialscheme.h @@ -88,6 +88,12 @@ class MaterialScheme */ Manifest &declare(Path const &path); + /** + * Determines if a manifest exists on the given @a path. + * @return @c true if a manifest exists; otherwise @a false. + */ + bool has(Path const &path) const; + /** * Search the scheme for a manifest matching @a path. * diff --git a/doomsday/client/src/resource/materials.cpp b/doomsday/client/src/resource/materials.cpp index 147514eb40..aa136c352a 100644 --- a/doomsday/client/src/resource/materials.cpp +++ b/doomsday/client/src/resource/materials.cpp @@ -298,24 +298,21 @@ MaterialManifest &Materials::find(Uri const &uri) const // Does the user want a manifest in a specific scheme? if(!uri.scheme().isEmpty()) { - try + Scheme &specifiedScheme = scheme(uri.scheme()); + if(specifiedScheme.has(uri.path())) { - return scheme(uri.scheme()).find(uri.path()); + return specifiedScheme.find(uri.path()); } - catch(Scheme::NotFoundError const &) - {} // Ignore, we'll throw our own... } else { // No, check each scheme in priority order. foreach(Scheme *scheme, d->schemeCreationOrder) { - try + if(scheme->has(uri.path())) { return scheme->find(uri.path()); } - catch(Scheme::NotFoundError const &) - {} // Ignore, we'll throw our own... } } diff --git a/doomsday/client/src/resource/materialscheme.cpp b/doomsday/client/src/resource/materialscheme.cpp index 01a15c90d6..8c70c5c15d 100644 --- a/doomsday/client/src/resource/materialscheme.cpp +++ b/doomsday/client/src/resource/materialscheme.cpp @@ -35,7 +35,11 @@ DENG2_PIMPL(MaterialScheme) name(symbolicName) {} - ~Instance() { DENG_ASSERT(index.isEmpty()); } + ~Instance() + { + self.clear(); + DENG2_ASSERT(index.isEmpty()); + } }; MaterialScheme::MaterialScheme(String symbolicName) @@ -44,7 +48,6 @@ MaterialScheme::MaterialScheme(String symbolicName) MaterialScheme::~MaterialScheme() { - clear(); delete d; } @@ -81,16 +84,19 @@ MaterialManifest &MaterialScheme::declare(Path const &path) return *newManifest; } +bool MaterialScheme::has(Path const &path) const +{ + return d->index.has(path, Index::NoBranch | Index::MatchFull); +} + MaterialManifest const &MaterialScheme::find(Path const &path) const { - try + if(has(path)) { return d->index.find(path, Index::NoBranch | Index::MatchFull); } - catch(Index::NotFoundError const &er) - { - throw NotFoundError("MaterialScheme::find", er.asText()); - } + /// @throw NotFoundError Failed to locate a matching manifest. + throw NotFoundError("MaterialScheme::find", "Failed to locate a manifest matching \"" + path.asText() + "\""); } MaterialManifest &MaterialScheme::find(Path const &path)