21 #ifdef ELEMENTSKERNEL_ELEMENTSKERNEL_PATH_IMPL_
25 #include <unordered_set>
28 #include <boost/filesystem/operations.hpp>
29 #include <boost/algorithm/string/join.hpp>
35 template <
typename T,
typename U>
39 Item file_path {file_name};
42 [file_path](
const U& l) {
43 return boost::filesystem::exists(
Item {l} / file_path);
46 if (found_pos != locations.
cend()) {
47 found_path =
Item {*found_pos} / file_path;
54 template <
typename T,
typename U>
58 Item file_path {file_name};
62 [file_path](
const U& l){
63 return Item {l} / file_path;
66 auto found_pos =
std::remove_if(file_list.begin(), file_list.end(),
68 return not boost::filesystem::exists(p);
71 file_list.erase(found_pos, file_list.end());
94 vector<string> elems(path_list.
size());
99 return Item{
s}.string();
107 template <
typename... Args>
108 auto join(Args&&... args) -> decltype(
joinPath(std::forward<Args>(args)...)) {
109 return joinPath(std::forward<Args>(args)...);
112 template <
typename... Args>
113 auto split(Args&&... args) -> decltype(
splitPath(std::forward<Args>(args)...)) {
114 return splitPath(std::forward<Args>(args)...);
118 template <
typename T,
typename U>
123 vector<Item> result(initial_locations.
size()*suffixes.
size());
125 auto pos = result.
begin();
128 [&pos, &suffixes](
const T& l) {
142 template <
typename T>
154 output.erase(end, output.
end());
164 #endif // ELEMENTSKERNEL_ELEMENTSKERNEL_PATH_IMPL_
ELEMENTS_API auto split(Args &&...args) -> decltype(splitPath(std::forward< Args >(args)...))
alias for the splitPath function
ELEMENTS_API std::vector< Item > multiPathAppend(const std::vector< T > &initial_locations, const std::vector< U > &suffixes)
path join each suffix to each initial locations
ELEMENTS_API Item getPathFromEnvVariable(const T &file_name, const std::string &path_variable)
retrieve path from a file name and an environment variable to look into
ELEMENTS_API std::vector< Item > removeDuplicates(const std::vector< T > &path_list)
remove duplicated paths keeping the order
ELEMENTS_API Item getPathFromLocations(const T &file_name, const std::vector< U > &locations)
retrieve path from a file name and a set of location to look into
ELEMENTS_API std::vector< Item > 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
ELEMENTS_API const std::string PATH_SEP
Separator of path entries. Usually ":" on Unix.
boost::filesystem::path Item
ELEMENTS_API std::vector< Item > splitPath(const std::string &path_string)
split a string into a vector of path using PATH_SEP
ELEMENTS_API std::string joinPath(const std::vector< T > &path_list)
collate a vector of path into a string using PATH_SEP
ELEMENTS_API auto join(Args &&...args) -> decltype(joinPath(std::forward< Args >(args)...))
alias for the joinPath function
ELEMENTS_API std::vector< Item > getLocationsFromEnv(const std::string &path_variable, bool exist_only=false)
function to get the locations from an environment variable