MEPP2 Project
Functions
FEVV::FileUtils Namespace Reference

Functions

std::string get_file_extension (const std::string &file_name)
 
std::string get_file_extension (const char *file_name)
 
bool has_extension (const std::string &file_name)
 
bool has_extension (const char *file_name)
 
bool has_extension (const std::string &file_name, const std::string &ext_name, bool case_sensitive=false)
 
bool has_extension (const char *file_name, const char *ext_name, bool case_sensitive=false)
 
bool has_extension (const std::string &file_name, const std::vector< std::string > &ext_names, bool case_sensitive=false)
 
std::string get_file_name (const std::string &file_name)
 
std::string get_file_name (const char *file_name)
 
std::string get_file_full_name (const std::string &file_name)
 
unsigned int count_file_lines (const std::string &file_name)
 
unsigned int count_file_lines (const char *file_name)
 
std::string get_parent_directory (const std::string &file_name)
 
std::ifstream & safe_getline (std::ifstream &input, std::string &str)
 
bool getline_skip_comment (std::istream &input, std::string &line)
 
bool getline_skip_comment (std::istream &input, std::string &line, std::istringstream &line_ss)
 
void copy_file (const std::string &from, const std::string &to)
 
void create_dir (const std::string &dirname)
 
void remove_dir (const std::string &dirname)
 
std::string get_wdir (void)
 
void change_wdir (const std::string &dirname)
 
std::string load_file (const std::string &file_name)
 

Function Documentation

◆ change_wdir()

void FEVV::FileUtils::change_wdir ( const std::string &  dirname)
inline

Change the current working directory.

Parameters
dir_paththe path/name of the directory

Definition at line 338 of file FileUtilities.hpp.

◆ copy_file()

void FEVV::FileUtils::copy_file ( const std::string &  from,
const std::string &  to 
)
inline

Copy a file. Display a warning if destination file exists and do not overwrite it.

Parameters
fromthe name of the file to be copied
tothe name of the target file

Definition at line 281 of file FileUtilities.hpp.

◆ count_file_lines() [1/2]

unsigned int FEVV::FileUtils::count_file_lines ( const char *  file_name)
inline

Returns the number of lines in the file.

Definition at line 180 of file FileUtilities.hpp.

Here is the call graph for this function:

◆ count_file_lines() [2/2]

unsigned int FEVV::FileUtils::count_file_lines ( const std::string &  file_name)
inline

Returns the number of lines in the file.

Definition at line 163 of file FileUtilities.hpp.

Here is the caller graph for this function:

◆ create_dir()

void FEVV::FileUtils::create_dir ( const std::string &  dirname)
inline

Create a directory.

Parameters
dir_paththe path/name of the directory

Definition at line 301 of file FileUtilities.hpp.

◆ get_file_extension() [1/2]

std::string FEVV::FileUtils::get_file_extension ( const char *  file_name)
inline

Returns the file name extension or an empty string if the file name has no extension.

Definition at line 47 of file FileUtilities.hpp.

Here is the call graph for this function:

◆ get_file_extension() [2/2]

std::string FEVV::FileUtils::get_file_extension ( const std::string &  file_name)
inline

Returns the file name extension or an empty string if the file name has no extension.

Definition at line 36 of file FileUtilities.hpp.

Here is the caller graph for this function:

◆ get_file_full_name()

std::string FEVV::FileUtils::get_file_full_name ( const std::string &  file_name)
inline

Returns the file name with no path. Example: for '/path/foo.bar', returns 'foo.bar'.

Definition at line 152 of file FileUtilities.hpp.

Here is the caller graph for this function:

◆ get_file_name() [1/2]

std::string FEVV::FileUtils::get_file_name ( const char *  file_name)
inline

Returns the file name with no path and no extension. Example: for '/path/foo.bar', returns 'foo'.

Definition at line 141 of file FileUtilities.hpp.

Here is the call graph for this function:

◆ get_file_name() [2/2]

std::string FEVV::FileUtils::get_file_name ( const std::string &  file_name)
inline

Returns the file name with no path and no extension. Example: for '/path/foo.bar', returns 'foo'.

Definition at line 128 of file FileUtilities.hpp.

Here is the caller graph for this function:

◆ get_parent_directory()

std::string FEVV::FileUtils::get_parent_directory ( const std::string &  file_name)
inline

Returns the file path. Example: for '/dir1/dir2/foo.bar', returns '/dir1/dir2'.

Definition at line 191 of file FileUtilities.hpp.

Here is the caller graph for this function:

◆ get_wdir()

std::string FEVV::FileUtils::get_wdir ( void  )
inline

Get the current working directory.

Definition at line 325 of file FileUtilities.hpp.

◆ getline_skip_comment() [1/2]

bool FEVV::FileUtils::getline_skip_comment ( std::istream &  input,
std::string &  line 
)
inline

Get a line from the input stream skipping any commented or empty line. To be used in the same way as std::getline(stream, string).

Parameters
inputthe input stream to read from
linethe string that will be filled with the line being read
Returns
true if the read succeeded, else false (aka when EOF)

Definition at line 230 of file FileUtilities.hpp.

Here is the caller graph for this function:

◆ getline_skip_comment() [2/2]

bool FEVV::FileUtils::getline_skip_comment ( std::istream &  input,
std::string &  line,
std::istringstream &  line_ss 
)
inline

Get a line from the input stream skipping any commented line. To be used in the same way as std::getline(stream, string).

Parameters
inputthe input stream to read from
linethe string that will be filled with the line being read
line_ssthe stringstream based on the read line
Returns
true if the read succeeded, else false (aka when EOF)

Definition at line 260 of file FileUtilities.hpp.

Here is the call graph for this function:

◆ has_extension() [1/5]

bool FEVV::FileUtils::has_extension ( const char *  file_name)
inline

Returns true if the file name has an extension, aka ends up with '.something'.

Definition at line 69 of file FileUtilities.hpp.

Here is the call graph for this function:

◆ has_extension() [2/5]

bool FEVV::FileUtils::has_extension ( const char *  file_name,
const char *  ext_name,
bool  case_sensitive = false 
)
inline

Returns true if the file name ends up with the provided extension.

Definition at line 99 of file FileUtilities.hpp.

Here is the call graph for this function:

◆ has_extension() [3/5]

bool FEVV::FileUtils::has_extension ( const std::string &  file_name)
inline

Returns true if the file name has an extension, aka ends up with '.something'.

Definition at line 58 of file FileUtilities.hpp.

Here is the caller graph for this function:

◆ has_extension() [4/5]

bool FEVV::FileUtils::has_extension ( const std::string &  file_name,
const std::string &  ext_name,
bool  case_sensitive = false 
)
inline

Returns true if the file name ends up with the provided extension.

Definition at line 79 of file FileUtilities.hpp.

Here is the call graph for this function:

◆ has_extension() [5/5]

bool FEVV::FileUtils::has_extension ( const std::string &  file_name,
const std::vector< std::string > &  ext_names,
bool  case_sensitive = false 
)
inline

Returns true if the file name ends up with one of the provided extensions.

Definition at line 112 of file FileUtilities.hpp.

◆ load_file()

std::string FEVV::FileUtils::load_file ( const std::string &  file_name)
inline

Load a whole file into a string.

Parameters
file_namethe name of the file to read.
Returns
a string hosting the file content.
See also
http://insanecoding.blogspot.com/2011/11/how-to-read-in-file-in-c.html

Definition at line 354 of file FileUtilities.hpp.

◆ remove_dir()

void FEVV::FileUtils::remove_dir ( const std::string &  dirname)
inline

Remove a directory and its content.

Parameters
dir_paththe path/name of the directory

Definition at line 314 of file FileUtilities.hpp.

◆ safe_getline()

std::ifstream& FEVV::FileUtils::safe_getline ( std::ifstream &  input,
std::string &  str 
)
inline

Get a line from the file and fix DOS end of line extra character if any. To be used in the same way as std::getline(stream, string).

Parameters
inputthe file-stream to read from
strthe string that will be filled with the line being read
Returns
the file-stream (mimic the return type of std::getline)

Definition at line 208 of file FileUtilities.hpp.

Here is the caller graph for this function: