Public Member Functions | Static Public Member Functions | List of all members
G::Directory Class Reference

An encapsulation of a file system directory which allows for iterating through the set of contained files. More...

#include <gdirectory.h>

Public Member Functions

 Directory ()
 Default constructor for the current directory. More...
 
 Directory (const char *path)
 Constructor. More...
 
 Directory (const Path &path)
 Constructor. More...
 
 Directory (const std::string &path)
 Constructor. More...
 
 ~Directory ()
 Destructor. More...
 
bool valid (bool for_creating_files=false) const
 Returns true if the object represents a valid directory. More...
 
bool writeable (std::string probe_filename=tmp()) const
 Tries to create and then delete an empty test file in the directory. More...
 
Path path () const
 Returns the directory's path. More...
 
 Directory (const Directory &other)
 Copy constructor. More...
 
Directoryoperator= (const Directory &)
 Assignment operator. More...
 

Static Public Member Functions

static Directory root ()
 Returns a root directory object. More...
 
static std::string tmp ()
 A convenience function for constructing a filename for writeable(). More...
 

Detailed Description

An encapsulation of a file system directory which allows for iterating through the set of contained files.

See also
G::Path, G::FileSystem, G::File

Definition at line 46 of file gdirectory.h.

Constructor & Destructor Documentation

G::Directory::Directory ( )

Default constructor for the current directory.

Definition at line 27 of file gdirectory.cpp.

G::Directory::Directory ( const char *  path)
explicit

Constructor.

Definition at line 39 of file gdirectory.cpp.

G::Directory::Directory ( const Path path)
explicit

Constructor.

Definition at line 49 of file gdirectory.cpp.

G::Directory::Directory ( const std::string &  path)
explicit

Constructor.

Definition at line 44 of file gdirectory.cpp.

G::Directory::~Directory ( )

Destructor.

Definition at line 54 of file gdirectory.cpp.

G::Directory::Directory ( const Directory other)

Copy constructor.

Definition at line 58 of file gdirectory.cpp.

Member Function Documentation

G::Directory & G::Directory::operator= ( const Directory rhs)

Assignment operator.

Definition at line 63 of file gdirectory.cpp.

G::Path G::Directory::path ( ) const

Returns the directory's path.

Definition at line 69 of file gdirectory.cpp.

Referenced by G::DirectoryIteratorImp::DirectoryIteratorImp().

G::Directory G::Directory::root ( )
static

Returns a root directory object.

For DOSy file systems this will not contain a drive part.

Definition at line 32 of file gdirectory.cpp.

References G::FileSystem::slash().

std::string G::Directory::tmp ( )
static

A convenience function for constructing a filename for writeable().

This is factored out so that client code can minimise the time spent with a privileged effective userid.

Definition at line 69 of file gdirectory_unix.cpp.

References G::DateTime::now(), and G::Process::Id::str().

bool G::Directory::valid ( bool  for_creating_files = false) const

Returns true if the object represents a valid directory.

Does additional checks if the 'for-creating-files' parameter is true. But note that the answer is not definitive – file creation may fail, even if valid() returns true. For a more accurate test use writeable().

Definition at line 39 of file gdirectory_unix.cpp.

References G::Path::str().

Referenced by G::DirectoryIteratorImp::isDir().

bool G::Directory::writeable ( std::string  probe_filename = tmp()) const

Tries to create and then delete an empty test file in the directory.

Returns true on success. Precondition: valid()

Definition at line 76 of file gdirectory_unix.cpp.

References G::Path::pathAppend(), and G::Path::str().


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