21 #ifndef ELEMENTSKERNEL__IMPL_PATH_ICPP_
22 #define ELEMENTSKERNEL__IMPL_PATH_ICPP_
26 #include <unordered_set>
29 #include <boost/filesystem.hpp>
30 #include <boost/algorithm/string/join.hpp>
36 template <
typename T,
typename U>
42 path file_path {file_name};
45 [file_path](
const U& l) {
46 return boost::filesystem::exists(
path {l} / file_path);
49 if (found_pos != locations.
cend()) {
50 found_path =
path {*found_pos} / file_path;
57 template <
typename T,
typename U>
63 path file_path {file_name};
67 [file_path](
const U& l){
68 return path {l} / file_path;
71 auto found_pos =
std::remove_if(file_list.begin(), file_list.end(),
73 return not boost::filesystem::exists(p);
76 file_list.erase(found_pos, file_list.end());
100 vector<string> elems(path_list.
size());
113 template <
typename... Args>
114 auto join(Args&&... args) -> decltype(
joinPath(std::forward<Args>(args)...)) {
115 return joinPath(std::forward<Args>(args)...);
118 template <
typename... Args>
120 return splitPath(std::forward<Args>(args)...);
124 template <
typename T,
typename U>
130 vector<path> result(initial_locations.
size()*suffixes.
size());
132 auto pos = result.begin();
135 [&pos, &suffixes](
const T& l) {
149 template <
typename T>
158 auto end = copy_if(path_list.
cbegin(), path_list.
cend(), output.begin(),
163 output.erase(end, output.
end());
173 #endif // ELEMENTSKERNEL__IMPL_PATH_ICPP_
boost::filesystem::path getPathFromEnvVariable(const T &file_name, const std::string &path_variable)
retrieve path from a file name and an environment variable to look into
auto split(Args &&...args) -> decltype(splitPath(std::forward< Args >(args)...))
alias for the splitPath function
boost::filesystem::path getPathFromLocations(const T &file_name, const std::vector< U > &locations)
retrieve path from a file name and a set of location to look into
std::vector< boost::filesystem::path > multiPathAppend(const std::vector< T > &initial_locations, const std::vector< U > &suffixes)
path join each suffix to each initial locations
ELEMENTS_API const std::string PATH_SEP
Separator of path entries. Usually ":" on Unix.
ELEMENTS_API std::vector< boost::filesystem::path > splitPath(const std::string &path_string)
split a string into a vector of path using PATH_SEP
boost::filesystem::path path
std::string joinPath(const std::vector< T > &path_list)
collate a vector of path into a string using PATH_SEP
std::vector< boost::filesystem::path > getAllPathFromLocations(const T &file_name, const std::vector< U > &locations)
retrieve all the paths from a file name and a set of location to look into
auto join(Args &&...args) -> decltype(joinPath(std::forward< Args >(args)...))
alias for the joinPath function
ELEMENTS_API std::vector< boost::filesystem::path > getLocationsFromEnv(const std::string &path_variable, bool exist_only=false)
function to get the locations from an environment variable
std::vector< boost::filesystem::path > removeDuplicates(const std::vector< T > &path_list)
remove duplicated paths keeping the order