Skip to content

Commit

Permalink
MaterialScheme: Improved public interface
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 3, 2013
1 parent fa6c1fd commit 133eda0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
6 changes: 6 additions & 0 deletions doomsday/client/include/resource/materialscheme.h
Expand Up @@ -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.
*
Expand Down
11 changes: 4 additions & 7 deletions doomsday/client/src/resource/materials.cpp
Expand Up @@ -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...
}
}

Expand Down
20 changes: 13 additions & 7 deletions doomsday/client/src/resource/materialscheme.cpp
Expand Up @@ -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)
Expand All @@ -44,7 +48,6 @@ MaterialScheme::MaterialScheme(String symbolicName)

MaterialScheme::~MaterialScheme()
{
clear();
delete d;
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 133eda0

Please sign in to comment.