MARLEY (Model of Argon Reaction Low Energy Yields)  v1.2.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
marley::FileManager Class Reference

Singleton class that handles file searches. More...

#include <FileManager.hh>

Public Member Functions

 FileManager (const FileManager &)=delete
 Deleted copy constructor.
 
 FileManager (FileManager &&)=delete
 Deleted move constructor.
 
std::string find_file (const std::string &base_name, const std::string &search_path=marley::FileManager::default_search_path_) const
 Searches for a file in the given search path. More...
 
std::string find_file (const std::string &base_name, const std::vector< std::string > &search_dirs) const
 Searches for a file in the given directories. More...
 
std::vector< std::string > list_all_files (const std::string &search_path=FileManager::default_search_path_) const
 Get a vector of full paths for all regular files in the requested search path. More...
 
std::vector< std::string > list_all_files (const std::vector< std::string > &search_dirs) const
 Get a vector of full paths for all regular files in the requested directories. More...
 
std::string marley_dir () const
 Returns the path to the root MARLEY folder.
 
FileManageroperator= (const FileManager &)=delete
 Deleted copy assignment operator.
 
FileManageroperator= (FileManager &&)=delete
 Deleted move assignment operator.
 

Static Public Member Functions

static const FileManagerInstance ()
 Get a const reference to the singleton instance of the FileManager.
 
static std::vector< std::string > search_path_to_dir_vector (const std::string &search_path=FileManager::default_search_path_)
 Converts a ':'-delimited search path (given as a single string) into a vector of directory names. More...
 

Protected Member Functions

 FileManager ()
 Create the singleton FileManager object.
 

Static Protected Member Functions

static bool dir_iterate (const std::string &dir_name, const std::function< bool(const std::string &, const std::string &)> &func)
 Helper function that executes a std::function on the name of each regular file found while scanning through a single directory (non-recursively) More...
 

Protected Attributes

std::string marley_dir_
 Stores the value of the MARLEY environment variable (which points to the root folder of the source code distribution)
 

Static Protected Attributes

static std::string default_search_path_
 By default, use this search path when looking for files.
 

Detailed Description

Singleton class that handles file searches.

Member Function Documentation

◆ dir_iterate()

bool marley::FileManager::dir_iterate ( const std::string &  dir_name,
const std::function< bool(const std::string &, const std::string &)> &  func 
)
staticprotected

Helper function that executes a std::function on the name of each regular file found while scanning through a single directory (non-recursively)

Parameters
dir_nameThe name of the directory to be scanned
funcThe function to execute. The first argument is the full file name (including the path). The second is the base name of the file (no path). The return value should be true if no further iterations are needed (e.g., because a file matching a desired name was found) and false otherwise.
Returns
True if the iterations were stopped early (due to function returning true) or false if they were completed

◆ find_file() [1/2]

std::string marley::FileManager::find_file ( const std::string &  base_name,
const std::string &  search_path = marley::FileManager::default_search_path_ 
) const

Searches for a file in the given search path.

The search is non-recursive, i.e., no subdirectories are included in the search

Parameters
base_nameThe base name (file name without any path) of the desired file
search_pathA string containing a ':'-delimited list of directories that should be searched for the file
Returns
The full path to the file, or an empty string if no match could be found

◆ find_file() [2/2]

std::string marley::FileManager::find_file ( const std::string &  base_name,
const std::vector< std::string > &  search_dirs 
) const

Searches for a file in the given directories.

The search is non-recursive, i.e., no subdirectories are included in the search

Parameters
base_nameThe base name (file name without any path) of the desired file
search_dirsA vector of strings specifying the directories that should be searched for the file
Returns
The full path to the file, or an empty string if no match could be found

◆ list_all_files() [1/2]

std::vector< std::string > marley::FileManager::list_all_files ( const std::string &  search_path = FileManager::default_search_path_) const

Get a vector of full paths for all regular files in the requested search path.

Files in subdirectories are not included (the search is non-recursive)

Parameters
search_pathA string containing a ':'-delimited list of directories that should be scanned for files
Returns
A vector of strings giving the full path to each regular file that was found

◆ list_all_files() [2/2]

std::vector< std::string > marley::FileManager::list_all_files ( const std::vector< std::string > &  search_dirs) const

Get a vector of full paths for all regular files in the requested directories.

Files in subdirectories are not included (the search is non-recursive)

Parameters
search_dirsA vector of strings specifying the directories that should be scanned
Returns
A vector of strings giving the full path to each regular file that was found

◆ search_path_to_dir_vector()

std::vector< std::string > marley::FileManager::search_path_to_dir_vector ( const std::string &  search_path = FileManager::default_search_path_)
static

Converts a ':'-delimited search path (given as a single string) into a vector of directory names.

Parameters
search_pathThe search path to convert that should be searched for the file
Returns
A vector of directory names corresponding to those given in the search path

The documentation for this class was generated from the following files: