Example #1
0
    FileList getAllFilesWithExt(SearchPath dirPath, const std::string &ext) {
        FileList filesPaths;

        for (const auto &path : dirPath) {
            using boost::filesystem::directory_iterator;
            using boost::make_iterator_range;
            boost::filesystem::path directoryPath(path);

            // Make sure that directory exists
            if (!boost::filesystem::exists(directoryPath)) {
                continue;
            }

            // Get a list of files inside the dir that match the extension
            for (const auto &pathName : make_iterator_range(
                     directory_iterator(directoryPath), directory_iterator())) {
                if (!boost::filesystem::is_regular_file(pathName) ||
                    pathName.path().extension() != ext)
                    continue;

                filesPaths.push_back(pathName.path().generic_string());
            }
        }

        return filesPaths;
    }
Example #2
0
File: main.cpp Project: CCJY/coliru
int main() {
    using Value = std::pair<box, int>;
    using Tree  = bgi::rtree<Value, bgi::rstar<32> >;

    Tree idx;

    std::vector<point> const points { point {1,10}, point {2,5}, point {5,8}, point {1,2}, point {8,10}, };

    for (size_t i = 0; i < points.size(); ++i)
        idx.insert(Value { boxof(points[i]), i });

    for (auto& entry : make_iterator_range(qbegin(idx, bgi::nearest(point{0,0}, 100)), {}))
        std::cout << bg::dsv(points[entry.second]) << " ";
}
Example #3
0
inline boost::optional<std::string>
find_in_path(const std::string &executable) {
  using std::string;
  using boost::is_equal;
  using boost::filesystem::path;
  using boost::make_iterator_range;

  const string PATH = getenv("PATH");

  for (const auto &token : make_iterator_range(
           make_split_iterator(PATH, first_finder(":", is_equal())), {})) {
    const auto full_path = path(token.begin(), token.end()) / executable;
    if (exists(full_path)) {
      return full_path.string();
    }
  }

  return {};
}
Example #4
0
    std::string findPlugin(const std::string &pluginName) {
        auto searchPaths = getPluginSearchPath();
        for (const auto &searchPath : searchPaths) {
            if (!boost::filesystem::exists(searchPath))
                continue;

            using boost::filesystem::directory_iterator;
            using boost::make_iterator_range;

            for (const auto &pluginPathName : make_iterator_range(
                     directory_iterator(searchPath), directory_iterator())) {
                /// Must be a regular file
                /// @todo does this mean symlinks get excluded?
                if (!boost::filesystem::is_regular_file(pluginPathName))
                    continue;

                const auto pluginCandidate =
                    boost::filesystem::path(pluginPathName);

                /// Needs right extension
                if (pluginCandidate.extension().generic_string() !=
                    OSVR_PLUGIN_EXTENSION) {
                    continue;
                }
                const auto pluginBaseName =
                    pluginCandidate.filename().stem().generic_string();
                /// If the name is right or has the manual load suffix, this is
                /// a good one.
                if ((pluginBaseName == pluginName) ||
                    (pluginBaseName ==
                     pluginName + OSVR_PLUGIN_IGNORE_SUFFIX)) {
                    return pluginPathName.path().generic_string();
                }
            }
        }

        return std::string();
    }