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

#include <gromacs/utility/directoryenumerator.h>

Description

Lists files in a directory.

If multiple threads share the same DirectoryEnumerator, they must take responsibility for their mutual synchronization, particularly with regard to calling nextFile().

Public Member Functions

 DirectoryEnumerator (const char *dirname, bool bThrow=true)
 Opens a directory for listing. More...
 
 DirectoryEnumerator (const std::string &dirname, bool bThrow=true)
 Opens a directory for listing. More...
 
bool nextFile (std::string *filename)
 Gets next file in a directory. More...
 

Static Public Member Functions

static std::vector< std::string > enumerateFilesWithExtension (const char *dirname, const char *extension, bool bThrow)
 Convenience function to list files with certain extension from a directory. More...
 

Constructor & Destructor Documentation

gmx::DirectoryEnumerator::DirectoryEnumerator ( const char *  dirname,
bool  bThrow = true 
)
explicit

Opens a directory for listing.

Parameters
[in]dirnamePath to the directory to list.
[in]bThrowWhether failure to open the directory should throw.
Exceptions
std::bad_allocif out of memory.
FileIOErrorif opening the directory fails and bThrow == true
gmx::DirectoryEnumerator::DirectoryEnumerator ( const std::string &  dirname,
bool  bThrow = true 
)
explicit

Opens a directory for listing.

Parameters
[in]dirnamePath to the directory to list.
[in]bThrowWhether failure to open the directory should throw.
Exceptions
std::bad_allocif out of memory.
FileIOErrorif opening the directory fails and bThrow == true

Member Function Documentation

std::vector< std::string > gmx::DirectoryEnumerator::enumerateFilesWithExtension ( const char *  dirname,
const char *  extension,
bool  bThrow 
)
static

Convenience function to list files with certain extension from a directory.

Parameters
[in]dirnamePath to the directory to list.
[in]extensionList files with the given extension (or suffix in file name).
[in]bThrowWhether failure to open the directory should throw.
Returns
List of files with the given extension in dirname.
Exceptions
std::bad_allocif out of memory.
FileIOErrorif opening the directory fails and bThrow == true.
FileIOErrorif some other I/O error occurs.
bool gmx::DirectoryEnumerator::nextFile ( std::string *  filename)

Gets next file in a directory.

Parameters
[out]filenameName of the next file.
Returns
false if there were no more files.
Exceptions
std::bad_allocif out of memory.
FileIOErrorif listing the next file fails.

If all files from the directory have been returned (or there are no files in the directory and this is the first call), the method returns false and filename is cleared. Otherwise, the return value is true and the first/next file name is returned in filename. filename will not contain any path information, only the name of the file.

If bThrow passed to the constructor was false and the directory was not successfully opened, the first call to this function will return false.

This method is not thread safe when called on the same object by multiple threads. Such use requires external synchronization.


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