ROSE  0.11.145.0
Classes | Typedefs | Functions | Variables
Rose::FileSystem Namespace Reference

Description

Functions for operating on files in a filesystem.

Classes

class  baseNameMatches
 Predicate returning true for matching names. More...
 

Typedefs

typedef boost::filesystem::path Path
 Name of entities in a filesystem. More...
 
typedef boost::filesystem::directory_iterator DirectoryIterator
 Iterate over directory contents non-recursively. More...
 
typedef boost::filesystem::recursive_directory_iterator RecursiveDirectoryIterator
 Iterate recursively into subdirectories. More...
 

Functions

ROSE_UTIL_API bool isExisting (const Path &path)
 Predicate returning true if path exists. More...
 
ROSE_UTIL_API bool isFile (const Path &path)
 Predicate returning true for existing regular files. More...
 
ROSE_UTIL_API bool isDirectory (const Path &path)
 Predicate returning true for existing directories. More...
 
ROSE_UTIL_API bool isSymbolicLink (const Path &path)
 Predicate returning true for existing symbolic links. More...
 
ROSE_UTIL_API bool isNotSymbolicLink (const Path &path)
 Predicate returning inverse of isSymbolicLink. More...
 
ROSE_UTIL_API Path createTemporaryDirectory ()
 Create a temporary directory. More...
 
ROSE_UTIL_API Path makeNormal (const Path &)
 Normalize a path name. More...
 
ROSE_UTIL_API Path makeRelative (const Path &path, const Path &root=boost::filesystem::current_path())
 Make path relative. More...
 
ROSE_UTIL_API Path makeAbsolute (const Path &path, const Path &root=boost::filesystem::current_path())
 Make path absolute. More...
 
ROSE_UTIL_API void copyFile (const Path &sourceFileName, const Path &destinationFileName)
 Copy a file. More...
 
ROSE_UTIL_API void copyFiles (const std::vector< Path > &files, const Path &root, const Path &destinationDirectory)
 Copy files from one directory to another. More...
 
template<class Select , class Descend >
void copyFilesRecursively (const Path &root, const Path &destination, Select select, Descend descend)
 Recursively copy files. More...
 
ROSE_UTIL_API std::vector< PathfindRoseFilesRecursively (const Path &root)
 Return a list of all rose_* files.
 
ROSE_UTIL_API std::string toString (const Path &)
 Convert a path to a string. More...
 
template<class Container >
Container readFile (const boost::filesystem::path &fileName, std::ios_base::openmode openMode=std::ios_base::in|std::ios_base::binary)
 Load an entire file into an STL container. More...
 
template<class Container >
void writeFile (const boost::filesystem::path &fileName, const Container &data, std::ios_base::openmode openMode=std::ios_base::out|std::ios_base::binary)
 Write a container to a file. More...
 
template<class Select >
std::vector< PathfindNames (const Path &root, Select select)
 Entries within a directory. More...
 
ROSE_UTIL_API std::vector< PathfindNames (const Path &root)
 Entries within a directory. More...
 
template<class Select , class Descend >
std::vector< PathfindNamesRecursively (const Path &root, Select select, Descend descend)
 Recursive list of names satisfying predicate. More...
 
template<class Select >
std::vector< PathfindNamesRecursively (const Path &root, Select select)
 Recursive list of names satisfying predicate. More...
 
ROSE_UTIL_API std::vector< PathfindNamesRecursively (const Path &root)
 Recursive list of names satisfying predicate. More...
 

Variables

const char * tempNamePattern
 Pattern to use when creating temporary files. More...
 

Typedef Documentation

typedef boost::filesystem::path Rose::FileSystem::Path

Name of entities in a filesystem.

Definition at line 24 of file Rose/FileSystem.h.

typedef boost::filesystem::directory_iterator Rose::FileSystem::DirectoryIterator

Iterate over directory contents non-recursively.

Definition at line 27 of file Rose/FileSystem.h.

typedef boost::filesystem::recursive_directory_iterator Rose::FileSystem::RecursiveDirectoryIterator

Iterate recursively into subdirectories.

Definition at line 30 of file Rose/FileSystem.h.

Function Documentation

ROSE_UTIL_API bool Rose::FileSystem::isExisting ( const Path path)

Predicate returning true if path exists.

ROSE_UTIL_API bool Rose::FileSystem::isFile ( const Path path)

Predicate returning true for existing regular files.

Referenced by copyFilesRecursively().

ROSE_UTIL_API bool Rose::FileSystem::isDirectory ( const Path path)

Predicate returning true for existing directories.

Referenced by findNames(), and findNamesRecursively().

ROSE_UTIL_API bool Rose::FileSystem::isSymbolicLink ( const Path path)

Predicate returning true for existing symbolic links.

ROSE_UTIL_API bool Rose::FileSystem::isNotSymbolicLink ( const Path path)

Predicate returning inverse of isSymbolicLink.

ROSE_UTIL_API Path Rose::FileSystem::createTemporaryDirectory ( )

Create a temporary directory.

The temporary directory is created as a subdirectory of the directory which is suitable for temporary files under the conventions of the operating system. The specifics of how this path is determined are implementation defined (see boost::filesystem::temp_directory_path). The created subdirectory has a name of the form "rose-%%%%%%%%-%%%%%%%%" where each "%" is a random hexadecimal digit. Returns the path to this directory.

ROSE_UTIL_API Path Rose::FileSystem::makeNormal ( const Path )

Normalize a path name.

Normalizes a path by removing "." and ".." components to the extent which is possible.

For instance, a name like "/foo/bar/../baz" will become "/foo/baz" and the name "/foo/./baz" will become "/foo/baz". However, the names "/../foo" and "./foo" cannot be changed because removing the ".." in the first case would place it in a different directory if the name were appended to another name, and in the second case it would convert a relative name to an absolute name.

ROSE_UTIL_API Path Rose::FileSystem::makeRelative ( const Path path,
const Path root = boost::filesystem::current_path() 
)

Make path relative.

Makes the specified path relative to another path or the current working directory.

ROSE_UTIL_API Path Rose::FileSystem::makeAbsolute ( const Path path,
const Path root = boost::filesystem::current_path() 
)

Make path absolute.

Makes the specified path an absolute path if it is a relative path. If relative, then assume root is what the path is relative to.

template<class Select >
std::vector<Path> Rose::FileSystem::findNames ( const Path root,
Select  select 
)

Entries within a directory.

Returns a list of entries in a directory–the contents of a directory–without recursing into subdirectories. The return value is a sorted list of paths, each of which contains root as a prefix. If a select predicate is supplied then only paths for which the predicate returns true become part of the return value. The predicate is called with the path that would become part of the return value. The root itself is never returned and never tested by the predicate.

If select is not specified then all entries are returned.

Definition at line 106 of file Rose/FileSystem.h.

References isDirectory().

ROSE_UTIL_API std::vector<Path> Rose::FileSystem::findNames ( const Path root)

Entries within a directory.

Returns a list of entries in a directory–the contents of a directory–without recursing into subdirectories. The return value is a sorted list of paths, each of which contains root as a prefix. If a select predicate is supplied then only paths for which the predicate returns true become part of the return value. The predicate is called with the path that would become part of the return value. The root itself is never returned and never tested by the predicate.

If select is not specified then all entries are returned.

template<class Select , class Descend >
std::vector<Path> Rose::FileSystem::findNamesRecursively ( const Path root,
Select  select,
Descend  descend 
)

Recursive list of names satisfying predicate.

Returns a list of entries in a directory and all subdirectories recursively. The return value is a sorted list of paths, each of which contains root as a prefix. If a select predicate is supplied then only paths for which the predicate returns true become part of the return value. If a descend predicate is supplied then this algorithm only recurses into subdirectories for which descend returns true. The predicates are called with the path that would become part of the return value. The root itself is never returned and never tested by the select or descend predicates.

If select is not specified then all entries are returned. If descend is not specified then the algorithm traverses into all subdirectories. Symbolic links to directories are never followed, but are returned if the select predicate allows them.

Definition at line 135 of file Rose/FileSystem.h.

Referenced by copyFilesRecursively(), and findNamesRecursively().

template<class Select >
std::vector<Path> Rose::FileSystem::findNamesRecursively ( const Path root,
Select  select 
)

Recursive list of names satisfying predicate.

Returns a list of entries in a directory and all subdirectories recursively. The return value is a sorted list of paths, each of which contains root as a prefix. If a select predicate is supplied then only paths for which the predicate returns true become part of the return value. If a descend predicate is supplied then this algorithm only recurses into subdirectories for which descend returns true. The predicates are called with the path that would become part of the return value. The root itself is never returned and never tested by the select or descend predicates.

If select is not specified then all entries are returned. If descend is not specified then the algorithm traverses into all subdirectories. Symbolic links to directories are never followed, but are returned if the select predicate allows them.

Definition at line 149 of file Rose/FileSystem.h.

References findNamesRecursively(), and isDirectory().

ROSE_UTIL_API std::vector<Path> Rose::FileSystem::findNamesRecursively ( const Path root)

Recursive list of names satisfying predicate.

Returns a list of entries in a directory and all subdirectories recursively. The return value is a sorted list of paths, each of which contains root as a prefix. If a select predicate is supplied then only paths for which the predicate returns true become part of the return value. If a descend predicate is supplied then this algorithm only recurses into subdirectories for which descend returns true. The predicates are called with the path that would become part of the return value. The root itself is never returned and never tested by the select or descend predicates.

If select is not specified then all entries are returned. If descend is not specified then the algorithm traverses into all subdirectories. Symbolic links to directories are never followed, but are returned if the select predicate allows them.

ROSE_UTIL_API void Rose::FileSystem::copyFile ( const Path sourceFileName,
const Path destinationFileName 
)

Copy a file.

Copies the contents of the source file to the destination file, overwriting the destination file if it existed.

ROSE_UTIL_API void Rose::FileSystem::copyFiles ( const std::vector< Path > &  files,
const Path root,
const Path destinationDirectory 
)

Copy files from one directory to another.

Each of the specified files are copied from their location under root to a similar location under destinationDirectory. Subdirectories of the destination directory are created as necessary.

Any file whose name is outside the root directory will similarly be created outside the destinationDirectory. For instance, copyFiles(["bar/baz"], "foo", "frob") will copy "bar/baz" to "frob/../bar/baz" since "bar" is apparently a sibling of "foo", and therefore must be a sibling of "frob".

Throws a boost::filesystem::filesystem_error on failure.

Referenced by copyFilesRecursively().

template<class Select , class Descend >
void Rose::FileSystem::copyFilesRecursively ( const Path root,
const Path destination,
Select  select,
Descend  descend 
)

Recursively copy files.

Get a list of files by recursively matching files under root and then copy them to similar locations relative to destination. The root and destination must not overlap. The select and descend arguments are the same as for the findAllNames method.

Definition at line 179 of file Rose/FileSystem.h.

References copyFiles(), findNamesRecursively(), and isFile().

ROSE_UTIL_API std::string Rose::FileSystem::toString ( const Path )

Convert a path to a string.

Try not to use this. Paths contain more information than std::string and the conversion may loose that info.

template<class Container >
Container Rose::FileSystem::readFile ( const boost::filesystem::path &  fileName,
std::ios_base::openmode  openMode = std::ios_base::in | std::ios_base::binary 
)

Load an entire file into an STL container.

Throws an exception if the file cannot be opened or the entire contents of the file cannot be read.

Definition at line 197 of file Rose/FileSystem.h.

template<class Container >
void Rose::FileSystem::writeFile ( const boost::filesystem::path &  fileName,
const Container &  data,
std::ios_base::openmode  openMode = std::ios_base::out | std::ios_base::binary 
)

Write a container to a file.

Writes the contents of the container to a file. Throws an exception if the file cannot be opened or not all the data can be written.

Definition at line 215 of file Rose/FileSystem.h.

Variable Documentation

const char* Rose::FileSystem::tempNamePattern

Pattern to use when creating temporary files.