1 // ResourceManager.hxx -- manage finding resources by names/paths
2 // Copyright (C) 2010 James Turner
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Library General Public
6 // License as published by the Free Software Foundation; either
7 // version 2 of the License, or (at your option) any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Library General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef SG_RESOURCE_MANAGER_HXX
22 #define SG_RESOURCE_MANAGER_HXX
26 #include <simgear/misc/sg_path.hxx>
31 class ResourceProvider;
34 * singleton management of resources
41 PRIORITY_FALLBACK = -100,
42 PRIORITY_NORMAL = 100,
46 static ResourceManager* instance();
49 * add a simple fixed resource location, to resolve against
51 void addBasePath(const SGPath& aPath, Priority aPriority = PRIORITY_DEFAULT);
56 void addProvider(ResourceProvider* aProvider);
59 * given a resource name (or path), find the appropriate real resource
61 * @param aContext an optional current location to resolve relative names
62 * against (e.g a current directory)
64 SGPath findPath(const std::string& aResource, SGPath aContext = SGPath());
69 typedef std::vector<ResourceProvider*> ProviderVec;
70 ProviderVec _providers;
73 class ResourceProvider
76 virtual SGPath resolve(const std::string& aResource, SGPath& aContext) const = 0;
78 virtual int priority() const
84 ResourceProvider(int aPriority) :
91 } // of simgear namespace
93 #endif // of header guard