Gromacs  2022.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions
gmx::DataFileFinder Class Reference

#include <gromacs/utility/datafilefinder.h>

Description

Searches data files from a set of paths.

Public Member Functions

 DataFileFinder ()
 Constructs a default data file finder. More...
 
void setSearchPathFromEnv (const char *envVarName)
 Adds search path from an environment variable. More...
 
FilePtr openFile (const DataFileOptions &options) const
 Opens a data file (if found) in an RAII-style FILE handle. More...
 
std::string findFile (const DataFileOptions &options) const
 Finds a full path to a data file if found. More...
 
std::vector< DataFileInfoenumerateFiles (const DataFileOptions &options) const
 Enumerates files in the data directories. More...
 

Constructor & Destructor Documentation

gmx::DataFileFinder::DataFileFinder ( )

Constructs a default data file finder.

The constructed finder searches only in the directory specified by the global program context (see IProgramContext), and optionally in the current directory.

Does not throw.

Member Function Documentation

std::vector< DataFileInfo > gmx::DataFileFinder::enumerateFiles ( const DataFileOptions options) const

Enumerates files in the data directories.

Parameters
[in]optionsIdenfies files to be searched for.
Returns
Information about each found file.
Exceptions
std::bad_allocif out of memory.
FileIOErrorif no such file can be found, and options specifies that an exception should be thrown.

Enumerates all files in the data directories that have the extension/suffix specified by the file name in options. Unlike findFile() and openFile(), this only works on files that are in the actual data directories, not for any entry within subdirectories of those. See DataFileInfo for details on what is returned for each found file. Files from the same directory will be returned as a continuous block in the returned vector.

std::string gmx::DataFileFinder::findFile ( const DataFileOptions options) const

Finds a full path to a data file if found.

Parameters
[in]optionsIdentifies the file to be searched for.
Returns
Full path to the data file, or an empty string if the file could not be found and exceptions were turned off.
Exceptions
std::bad_allocif out of memory.
FileIOErrorif no such file can be found, and options specifies that an exception should be thrown.

Searches for a data file in the search paths configured for the finder, as well as in the current directory if so required. Returns the full path to the first file found.

FilePtr gmx::DataFileFinder::openFile ( const DataFileOptions options) const

Opens a data file (if found) in an RAII-style FILE handle.

Parameters
[in]optionsIdentifies the file to be searched for.
Returns
The opened file handle, or NULL if the file could not be found and exceptions were turned off.
Exceptions
std::bad_allocif out of memory.
FileIOErrorif
  • no such file can be found, and options specifies that an exception should be thrown, or
  • there is an error opening the file (note that a file is skipped during the search if the user does not have rights to open the file at all).

See findFile() for more details.

void gmx::DataFileFinder::setSearchPathFromEnv ( const char *  envVarName)

Adds search path from an environment variable.

Parameters
[in]envVarNameName of the environment variable to use.
Exceptions
std::bad_allocif out of memory.

If the specified environment variable is set, it is interpreted like a PATH environment variable on the platform (split at appropriate separators), and each path found is added to the search path this finder searches. The added paths take precedence over the default directory specified by the global program context, but the current directory is searched first.


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