Reference documentation for deal.II version 9.1.1
|
#include <deal.II/base/path_search.h>
Public Types | |
enum | Position { back, front, after_none } |
Public Member Functions | |
PathSearch (const std::string &cls, const unsigned int debug=0) | |
std::string | find (const std::string &filename, const char *open_mode="r") |
std::string | find (const std::string &filename, const std::string &suffix, const char *open_mode="r") |
template<class StreamType > | |
void | show (StreamType &stream) const |
void | add_path (const std::string &path, Position pos=back) |
void | add_suffix (const std::string &suffix, Position pos=back) |
Static Public Member Functions | |
static void | add_class (const std::string &cls) |
static ::ExceptionBase & | ExcNoClass (std::string arg1) |
static ::ExceptionBase & | ExcFileNotFound (std::string arg1, std::string arg2) |
Private Types | |
using | map_type = std::map< std::string, std::vector< std::string > >::value_type |
Static Private Member Functions | |
static void | initialize_classes () |
static std::vector< std::string > & | get_path_list (const std::string &cls) |
static std::vector< std::string > & | get_suffix_list (const std::string &cls) |
Private Attributes | |
const std::string | cls |
std::vector< std::string > & | my_path_list |
std::vector< std::string > & | my_suffix_list |
const unsigned int | debug |
Static Private Attributes | |
static std::map< std::string, std::vector< std::string > > | path_lists |
static std::map< std::string, std::vector< std::string > > | suffix_lists |
static std::string | empty |
Support for searching files in a list of paths and with a list of suffixes.
A list of search paths is maintained for each file class supported. A file class is defined by a unique string. The classes provided are
.prm
) Additional file classes can be added easily by using add_class().
Usage: First, you construct a PathSearch object for a certain file class, e.g. meshes. Then, you use the find() method to obtain a full path name and you can open the file.
This piece of code will first traverse all paths in the list set up for file class MESH
. If it manages to open a file, it returns the istream
object. If not, it will try to append the first suffix of the suffix list and do the same. And so on. If no file is found in the end, an exception is thrown.
If you want to restrict your search to a certain mesh format, .inp
for instance, then either use "grid.inp"
in the code above or use the alternative find(const std::string&,const std::string&,const char*) function
Path lists are by default starting with the current directory ("./"
), followed optionally by a standard directory of deal.II. Use show() to find out the path list for a given class. Paths and suffixes can be added using the functions add_path() and add_suffix(), respectively.
"/"
, while suffixes should always start with a dot. These characters are not added automatically (allowing you to do some real file name editing).Definition at line 84 of file path_search.h.
|
private |
Type of values in the class maps.
Definition at line 200 of file path_search.h.
enum PathSearch::Position |
Position for adding a new item to a list.
Enumerator | |
---|---|
back | Add new item at end of list. |
front | Add new item at front of list. |
after_none | Add in path list after empty element. |
Definition at line 90 of file path_search.h.
PathSearch::PathSearch | ( | const std::string & | cls, |
const unsigned int | debug = 0 |
||
) |
Constructor. The first argument is a string identifying the class of files to be searched for.
The debug argument determines the verbosity of this class.
Definition at line 103 of file path_search.cc.
std::string PathSearch::find | ( | const std::string & | filename, |
const char * | open_mode = "r" |
||
) |
Find a file in the class specified by the constructor and return its complete path name (including a possible suffix).
File search works by actually trying to open the file. If fopen
is successful with the provided open_mode
, then the file is found, otherwise the search continues.
open_mode!
In particular, use "w"
with great care! If the file does not exist, it cannot be found. If it does exist, the fopen
function will truncate it to zero length.filename | The base name of the file to be found, without path components and suffix. |
open_mode | The mode handed over to the fopen function. |
Definition at line 171 of file path_search.cc.
std::string PathSearch::find | ( | const std::string & | filename, |
const std::string & | suffix, | ||
const char * | open_mode = "r" |
||
) |
Find a file in the class specified by the constructor and return its complete path name. Do not use the standard suffix list, but only try to apply the suffix given.
File search works by actually trying to open the file. If fopen
is successful with the provided open_mode
, then the file is found, otherwise the search continues.
open_mode!
In particular, use "w"
with great care! If the file does not exist, it cannot be found. If it does exist, the fopen
function will truncate it to zero length.filename | The base name of the file to be found, without path components and suffix. |
suffix | The suffix to be used for opening. |
open_mode | The mode handed over to the fopen function. |
Definition at line 112 of file path_search.cc.
|
inline |
Show the paths and suffixes used for this object.
Definition at line 264 of file path_search.h.
|
static |
Add a new class.
Definition at line 198 of file path_search.cc.
Add a path to the current class. See PathSearch::Position for possible position arguments.
Definition at line 214 of file path_search.cc.
Add a path to the current class. See PathSearch::Position for possible position arguments.
Definition at line 232 of file path_search.cc.
|
staticprivate |
Initialize the static list objects for further use.
Definition at line 33 of file path_search.cc.
|
staticprivate |
Get path list for a certain class. Used to set up my_path_list in constructor.
Definition at line 70 of file path_search.cc.
|
staticprivate |
Get suffix list for a certain class. Used to set up my_suffix_list in constructor.
Definition at line 87 of file path_search.cc.
|
private |
The file class handled by this object.
Definition at line 225 of file path_search.h.
|
staticprivate |
All path lists for all classes, such that we can build them only once.
Definition at line 230 of file path_search.h.
|
staticprivate |
List of suffixes for each class.
Definition at line 235 of file path_search.h.
|
private |
Path list for the class this object belongs to.
Definition at line 240 of file path_search.h.
|
private |
Suffix list for the class this object belongs to.
Definition at line 245 of file path_search.h.
|
private |
Debug flag. No output if zero.
Definition at line 250 of file path_search.h.
|
staticprivate |
The empty string.
Definition at line 255 of file path_search.h.