/*] Copyright (c) 2009-2010, Charles McGarvey [************************** **] All rights reserved. * * vi:ts=4 sw=4 tw=75 * * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * **************************************************************************/ #include #include #include "Log.hh" #include "Resource.hh" namespace Mf { // static member std::vector Resource::gSearchPaths; void Resource::addSearchPaths(const std::string& path) { std::vector paths; boost::split(paths, path, boost::is_any_of(":")); addSearchPaths(paths); } void Resource::addSearchPaths(const std::vector& path) { std::vector::const_iterator it; for (it = path.begin(); it != path.end(); ++it) { std::string onePath(*it); ASSERT(!onePath.empty() && "empty search path string"); // add a slash if there isn't one already if (*onePath.rbegin() != '/') { onePath += '/'; } #if defined(_WIN32) boost::replace_all(onePath, "/", "\\"); #endif gSearchPaths.push_back(onePath); logInfo << "added search path " << onePath << std::endl; } } std::string Resource::getPath(const std::string& name) { std::vector::iterator it; std::string path(name); #if defined(_WIN32) boost::replace_all(path, "/", "\\"); #endif for (it = gSearchPaths.begin(); it != gSearchPaths.end(); ++it) { std::string fullPath(*it); fullPath += path; if (access(fullPath.c_str(), R_OK) == 0) return fullPath; } logWarning << "cannot find resource " << name << std::endl; // empty string return std::string(); } } // namespace Mf