1 // Copyright 2015 The Shaderc Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef LIBSHADERC_UTIL_SRC_FILE_FINDER_H_ 16 #define LIBSHADERC_UTIL_SRC_FILE_FINDER_H_ 17 18 #include <string> 19 #include <vector> 20 21 namespace shaderc_util { 22 23 // Finds files within a search path. 24 class FileFinder { 25 public: 26 // Searches for a read-openable file based on filename, which must be 27 // non-empty. The search is attempted on filename prefixed by each element of 28 // search_path() in turn. The first hit is returned, or an empty string if 29 // there are no hits. Search attempts treat their argument the way 30 // std::fopen() treats its filename argument, blind to whether the path is 31 // absolute or relative. 32 // 33 // If a search_path() element is non-empty and not ending in a slash, then a 34 // slash is inserted between it and filename before its search attempt. An 35 // empty string in search_path() means that the filename is tried as-is. 36 std::string FindReadableFilepath(const std::string& filename) const; 37 38 // Searches for a read-openable file based on filename, which must be 39 // non-empty. The search is first attempted as a path relative to 40 // the requesting_file parameter. If no file is found relative to the 41 // requesting_file then this acts as FindReadableFilepath does. If 42 // requesting_file does not contain a '/' or a '\' character then it is 43 // assumed to be a filename and the request will be relative to the 44 // current directory. 45 std::string FindRelativeReadableFilepath(const std::string& requesting_file, 46 const std::string& filename) const; 47 48 // Search path for Find(). Users may add/remove elements as desired. 49 std::vector<std::string>& search_path() { return search_path_; } 50 51 private: 52 std::vector<std::string> search_path_; 53 }; 54 55 } // namespace shaderc_util 56 57 #endif // LIBSHADERC_UTIL_SRC_FILE_FINDER_H_ 58