diff options
Diffstat (limited to 'project2/common/environment.cpp')
-rw-r--r-- | project2/common/environment.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/project2/common/environment.cpp b/project2/common/environment.cpp index c0f84a2..9d79ca0 100644 --- a/project2/common/environment.cpp +++ b/project2/common/environment.cpp @@ -6,6 +6,7 @@ #include <stdio.h> #include <fstream> #include <boost/filesystem/convenience.hpp> +#include <boost/tuple/tuple_comparison.hpp> #include <boost/foreach.hpp> #include <boost/bind.hpp> @@ -109,11 +110,22 @@ ScriptReaderPtr Environment::resolveScript(const std::string & group, const std::string & name, bool ii) const { typedef std::map<std::string, boost::shared_ptr<ScriptReaderLoader> > ReaderLoaders; - BOOST_FOREACH(const ReaderLoaders::value_type & rl, *LoaderBase::objLoaders<ScriptReaderLoader>()) { - ScriptReaderPtr rs = rl.second->resolveScript(group, name); - if (rs) { - return rs; + boost::filesystem::path e(name); + while (!e.empty()) { + ScriptKey sk(group, e.string()); + ScriptCache::const_iterator i = scriptCache.find(sk); + if (i != scriptCache.end() && i->second->isCurrent()) { + return i->second; } + else { + BOOST_FOREACH(const ReaderLoaders::value_type & rl, *LoaderBase::objLoaders<ScriptReaderLoader>()) { + ScriptReaderPtr rs = rl.second->resolveScript(group, e.string()); + if (rs) { + return (scriptCache[sk] = rs); + } + } + } + e = e.parent_path(); } if (ii) { throw DependencyNotFound(group, name); |