29 #ifndef LBANN_UTILS_FILE_HPP_INCLUDED 30 #define LBANN_UTILS_FILE_HPP_INCLUDED 44 static std::string
preferred() {
return std::string(1, characters[0]); }
45 static bool check(
const char ch)
47 return (characters.find(ch) != std::string::npos);
51 return (characters.find(ch) != std::string::npos);
57 std::vector<int>
get_tokens(std::string str,
const std::vector<char> delims);
59 std::vector<std::string>
get_tokens(
const std::string str,
60 const std::string delims =
" :;\t\r\n");
66 std::string& basename);
71 const std::string tag,
72 const std::string new_ext =
"");
81 bool load_file(
const std::string filename,
82 std::vector<char>& buf,
87 ui = ((ui >> 24) | ((ui << 8) & 0x00FF0000) | ((ui >> 8) & 0x0000FF00) |
93 std::basic_string<T>
pad(
const std::basic_string<T>& s,
94 typename std::basic_string<T>::size_type n,
99 t.insert(t.begin(), n - t.length(), c);
108 #if !defined(DOXYGEN_SHOULD_SKIP_THIS) 111 template <
typename BaseTypeT,
typename... PathRepresentationType>
112 std::string join_path_impl(BaseTypeT
const& base,
113 PathRepresentationType&&... rest);
116 inline std::string
const& join_path_impl(std::string
const& x) {
return x; }
117 inline std::string join_path_impl(
char const*
const x)
119 return std::string(x);
123 template <
typename... PathRepresentationType>
124 std::string join_path_impl(std::string
const& base,
125 PathRepresentationType&&... rest)
128 join_path_impl(std::forward<PathRepresentationType>(rest)...);
131 template <
typename BaseType,
typename... PathRepresentationType>
132 std::string join_path_impl(BaseType
const& base,
133 PathRepresentationType&&... rest)
135 return std::string(base) +
"/" +
136 join_path_impl(std::forward<PathRepresentationType>(rest)...);
140 #endif // !defined(DOXYGEN_SHOULD_SKIP_THIS) 146 template <
typename... PathNameType>
149 return details::join_path_impl(std::forward<PathNameType>(paths)...);
185 #endif // LBANN_UTILS_FILE_HPP_INCLUDED bool check_if_file_exists(const std::string &filename)
std::vector< int > get_tokens(std::string str, const std::vector< char > delims)
std::basic_string< T > pad(const std::basic_string< T > &s, typename std::basic_string< T >::size_type n, T c)
std::string modify_file_name(const std::string file_name, const std::string tag, const std::string new_ext="")
static std::string preferred()
bool check_if_dir_exists(const std::string &dirname)
std::string get_ext_name(const std::string file_name)
static const std::string characters
bool load_file(const std::string filename, std::vector< char > &buf, bool append=false)
void make_directory(const std::string &path)
Create directory if needed.
std::string join_path(PathNameType &&... paths)
Concatenate all paths, injecting path separators between each argument.
std::string extract_parent_directory(const std::string &path)
Wrapper around dirname.
std::string extract_base_name(const std::string &path)
Wrapper around basename.
bool directory_exists(const std::string &path)
Check if directory exists.
bool create_dir(const std::string output_dir)
std::string add_delimiter(const std::string dir)
static bool check(const char ch)
bool operator()(const char ch) const
bool file_exists(const std::string &path)
Check if file exists.
void remove_multiple_slashes(std::string &str)
void __swapEndianInt(unsigned int &ui)
std::string get_basename_without_ext(const std::string file_name)
bool parse_path(const std::string &path, std::string &dir, std::string &basename)