Ceylan::System::Directory Class Reference

Abstract directory mother class, so that programs can always manipulate Ceylan::Directory instances, whereas per-platform specialized classes are actually used by the system. More...

#include <CeylanDirectory.h>

Inheritance diagram for Ceylan::System::Directory:

Inheritance graph
[legend]
Collaboration diagram for Ceylan::System::Directory:

Collaboration graph
[legend]

List of all members.

Public Types

enum  TextOutputFormat { rawText, html }
 Defines what text output formats for TextDisplayable instances are available. More...

Public Member Functions

virtual ~Directory () throw ()
 Destroys the directory reference, not the directory itself.
virtual bool hasDirectory (const std::string &subdirectoryName) const =0
 Tells whether the directory has a direct subdirectory named subdirectoryName.
virtual bool hasFile (const std::string &fileName) const =0
 Tells whether the directory has a direct file or symbolic link named fileName.
virtual bool hasEntry (const std::string &entryName) const =0
 Tells whether the directory has a direct entry named entryName.
virtual void getSubdirectories (std::list< std::string > &subDirectories) const =0
 Returns the names of all direct subdirectories of this directory, in the specified list.
virtual void getFiles (std::list< std::string > &files) const =0
 Returns the names of all files of this directory, in the specified list.
virtual void getEntries (std::list< std::string > &entries) const =0
 Returns the names of all direct entries of any type of this directory (including files and directories), in the specified list.
virtual void getSortedEntries (std::list< std::string > &subDirectories, std::list< std::string > &files, std::list< std::string > &otherEntries) const =0
 Returns the names of all direct entries of any type of this directory (including files and directories), in the corresponding specified list.
virtual void goDown (const std::string &subdirectoryName)
virtual bool isValid () const
 Tells whether the reference on the directory is valid.
virtual const std::string & getPath () const
 Returns the path of the directory which is referred to.
virtual void removeLeadingSeparator ()
 Removes the leading separator, if any, in the path of this directory path.
virtual const std::string toString (Ceylan::VerbosityLevels level=Ceylan::high) const
 Returns a user-friendly description of the state of this object.

Static Public Member Functions

static bool Exists (const std::string &directoryPath)
 Tells whether the directory directoryPath exists and is a directory indeed.
static void Remove (const std::string &directoryPath, bool recursive=false)
 Removes the directory from disk.
static void Move (const std::string &sourceDirectoryname, const std::string &targetDirectoryname)
 Moves specified directory on filesystem.
static void Copy (const std::string &sourceDirectoryname, const std::string &targetDirectoryname)
 Copies the directory on filesystem.
static time_t GetLastChangeTime (const std::string &directoryPath)
 Returns the last change time of the specified directory.
static bool IsAValidDirectoryPath (const std::string &directoryString)
 Returns whether specified string is a valid directory path.
static void RemoveLeadingSeparator (std::string &path)
 Removes the leading separator, if any, in specified directory's path.
static bool IsAbsolutePath (const std::string &path)
 Tells whether specified path is an absolute path.
static std::string GetCurrentWorkingDirectoryPath ()
 Returns the current working directory name.
static void ChangeWorkingDirectory (const std::string &newWorkingDirectory)
 Changes current working directory to newWorkingDirectory.
static std::list< std::string > SplitPath (const std::string &path)
static std::string JoinPath (const std::list< std::string > &pathElements)
static std::string JoinPath (const std::string &firstPath, const std::string &secondPath)
static void StripFilename (const std::string &path, std::string *base, std::string *file=0)
 Separates the full pathname path into a basename base and file name file.
static Ceylan::Latin1Char GetSeparator ()
static std::string GetSeparatorAsString ()
static DirectoryCreate (const std::string &newDirectoryName)
 Returns a Directory reference on a directory newly created on disk.
static DirectoryOpen (const std::string &directoryName="")
 Returns a Directory reference on specified already-existing directory, which will be "opened" (i.e.
static const std::string ToString (std::list< TextDisplayable * > displayables, Ceylan::VerbosityLevels level=Ceylan::high)
 Returns a user-friendly description of this list of pointers to text displayable instances.
static TextOutputFormat GetOutputFormat ()
 Returns the current overall text format to be used by TextDisplayable instances.
static void SetOutputFormat (TextOutputFormat newOutputFormat)
 Sets the current overall text format to be used by TextDisplayable instances.

Protected Member Functions

 Directory (const std::string &directoryName)
 Constructs a reference to the directory directoryName.
virtual FileSystemManagergetCorrespondingFileSystemManager () const =0
 Returns the filesystem manager that corresponds to the actual Directory child class.

Static Protected Member Functions

static FileSystemManagerGetCorrespondingFileSystemManager ()
 Returns the filesystem manager that should be used by Directory static methods, which is the default manager.

Protected Attributes

std::string _path
 The path a directory instance refers to.

Static Protected Attributes

static TextOutputFormat _OutputFormat = rawText
 The text format to be used currently by TextDisplayable instances.

Private Member Functions

 Directory (const Directory &source)
 Copy constructor made private to ensure that it will be never called.
Directoryoperator= (const Directory &source)
 Assignment operator made private to ensure that it will be never called.


Detailed Description

Abstract directory mother class, so that programs can always manipulate Ceylan::Directory instances, whereas per-platform specialized classes are actually used by the system.

Examples of convenient cross-platform Directory methods whose use is encouraged: Create, Open, Remove, ExistsAsDirectory.

See also:
File, FileSystemManager for other file-related operations.

Definition at line 91 of file CeylanDirectory.h.


Member Enumeration Documentation

Defines what text output formats for TextDisplayable instances are available.

Enumerator:
rawText 
html 

Definition at line 124 of file CeylanTextDisplayable.h.


Constructor & Destructor Documentation

Directory::~Directory (  )  throw () [virtual]

Destroys the directory reference, not the directory itself.

See also:
Remove
The destructor must be public as instances created by factories have to be deallocated by the user.

Definition at line 287 of file CeylanDirectory.cc.

Directory::Directory ( const std::string &  directoryName  )  [explicit, protected]

Constructs a reference to the directory directoryName.

Definition at line 417 of file CeylanDirectory.cc.

Ceylan::System::Directory::Directory ( const Directory source  )  [private]

Copy constructor made private to ensure that it will be never called.

The compiler should complain whenever this undefined constructor is called, implicitly or not.


Member Function Documentation

void Directory::ChangeWorkingDirectory ( const std::string &  newWorkingDirectory  )  [static]

Changes current working directory to newWorkingDirectory.

Parameters:
newWorkingDirectory the target working directory.
Exceptions:
DirectoryException if the operation failed or is not supported on this platform. This includes throwing a more specific DirectoryDelegatingException (a child class of DirectoryException), should the underlying filesystem manager not be retrieved as expected.

Definition at line 184 of file CeylanDirectory.cc.

References Ceylan::System::FileSystemManager::changeWorkingDirectory(), and GetCorrespondingFileSystemManager().

Referenced by Ceylan::System::Process::Restart().

void Directory::Copy ( const std::string &  sourceDirectoryname,
const std::string &  targetDirectoryname 
) [static]

Copies the directory on filesystem.

Parameters:
sourceDirectoryname the path of the directory to be copied.
targetDirectoryname the path of the target directory.
Exceptions:
DirectoryException,including DirectoryCopyFailed if the operation failed or is not supported on this platform, or DirectoryDelegatingException should the underlying filesystem manager not be retrieved as expected.

Definition at line 114 of file CeylanDirectory.cc.

References Ceylan::System::FileSystemManager::copyDirectory(), and GetCorrespondingFileSystemManager().

Directory & Directory::Create ( const std::string &  newDirectoryName  )  [static]

Returns a Directory reference on a directory newly created on disk.

Parameters:
newDirectoryName the name of the directory to create.
Directory factory, to be used instead of a specific Directory subclass constructor, so that it can return a Directory instance that is actually a specialized one (ex: a StandardDirectory, not an abstract Directory).

Exceptions:
DirectoryException,including DirectoryCreationFailed if the operation failed or is not supported on this platform, or DirectoryDelegatingException if the relevant filesystem manager could not be retrieved.

Reimplemented in Ceylan::System::LibfatDirectory, and Ceylan::System::StandardDirectory.

Definition at line 267 of file CeylanDirectory.cc.

References Ceylan::System::FileSystemManager::createDirectory(), and GetCorrespondingFileSystemManager().

Referenced by Ceylan::Log::LogAggregatorHTML::LogAggregatorHTML().

bool Directory::Exists ( const std::string &  directoryPath  )  [static]

Tells whether the directory directoryPath exists and is a directory indeed.

Parameters:
directoryPath the directory path to look-up.
Note:
On Windows, files and directories are case-insensitive, and 'c:' is not a directory (it is seen as a drive), whereas 'c:\' is a directory.
Exceptions:
DirectoryException,including DirectoryLookupFailed if the operation failed (existence test failed with no answer) or is not supported on this platform, or DirectoryDelegatingException should the underlying filesystem manager not be retrieved as expected.

Definition at line 80 of file CeylanDirectory.cc.

References Ceylan::System::FileSystemManager::existsAsDirectory(), and GetCorrespondingFileSystemManager().

FileSystemManager & Directory::GetCorrespondingFileSystemManager (  )  [static, protected]

Returns the filesystem manager that should be used by Directory static methods, which is the default manager.

Returns:
the default filesystem manager.
Exceptions:
DirectoryDelegatingException if the operation failed.

Definition at line 433 of file CeylanDirectory.cc.

References dataUtils::e, Ceylan::System::FileSystemManager::GetAnyDefaultFileSystemManager(), and Ceylan::Exception::toString().

Referenced by ChangeWorkingDirectory(), Copy(), Create(), Exists(), GetCurrentWorkingDirectoryPath(), GetLastChangeTime(), GetSeparator(), IsAbsolutePath(), IsAValidDirectoryPath(), JoinPath(), Move(), Open(), Remove(), RemoveLeadingSeparator(), SplitPath(), and StripFilename().

virtual FileSystemManager& Ceylan::System::Directory::getCorrespondingFileSystemManager (  )  const [protected, pure virtual]

Returns the filesystem manager that corresponds to the actual Directory child class.

Exceptions:
DirectoryDelegatingException if the operation failed.

Implemented in Ceylan::System::LibfatDirectory, and Ceylan::System::StandardDirectory.

Referenced by goDown(), isValid(), and removeLeadingSeparator().

string Directory::GetCurrentWorkingDirectoryPath (  )  [static]

Returns the current working directory name.

Exceptions:
DirectoryException if the operation failed or is not supported on this platform. This includes throwing a more specific DirectoryDelegatingException (a child class of DirectoryException), should the underlying filesystem manager not be retrieved as expected.

Definition at line 173 of file CeylanDirectory.cc.

References GetCorrespondingFileSystemManager(), and Ceylan::System::FileSystemManager::getCurrentWorkingDirectoryPath().

Referenced by Ceylan::System::Process::SaveState().

virtual void Ceylan::System::Directory::getEntries ( std::list< std::string > &  entries  )  const [pure virtual]

Returns the names of all direct entries of any type of this directory (including files and directories), in the specified list.

Parameters:
entries the caller-provided list in which entries will be added.
Exceptions:
DirectoryLookupFailed if the operation failed or is not supported.
Note:
Aliases for current and parent directories (ex: '.' and '..') will be filtered out.

Aliases for current and parent directories (ex: '.' and '..') will be filtered out.

Exceptions:
DirectoryLookupFailed if the operation failed or is not supported.

Implemented in Ceylan::System::LibfatDirectory, and Ceylan::System::StandardDirectory.

virtual void Ceylan::System::Directory::getFiles ( std::list< std::string > &  files  )  const [pure virtual]

Returns the names of all files of this directory, in the specified list.

Parameters:
files the caller-provided list in which subdirectories will be added.
Exceptions:
DirectoryLookupFailed if an error occured.

Implemented in Ceylan::System::LibfatDirectory, and Ceylan::System::StandardDirectory.

time_t Directory::GetLastChangeTime ( const std::string &  directoryPath  )  [static]

Returns the last change time of the specified directory.

Parameters:
directoryPath the path of the directory whose last change time is searched.
Exceptions:
DirectoryLastChangeTimeRequestFailed if the operation failed or is not supported on this platform, or DirectoryDelegatingException if the relevant filesystem manager could not be retrieved.

Definition at line 126 of file CeylanDirectory.cc.

References GetCorrespondingFileSystemManager(), and Ceylan::System::FileSystemManager::getLastChangeTimeDirectory().

TextDisplayable::TextOutputFormat TextDisplayable::GetOutputFormat (  )  [static, inherited]

const std::string & Directory::getPath (  )  const [virtual]

Returns the path of the directory which is referred to.

Returns:
the path, with no leading separator.

Definition at line 378 of file CeylanDirectory.cc.

References _path.

Referenced by Ceylan::Log::LogAggregatorHTML::aggregate(), and Ceylan::Log::LogAggregatorHTML::write().

Ceylan::Latin1Char Directory::GetSeparator (  )  [static]

string Directory::GetSeparatorAsString (  )  [static]

Definition at line 249 of file CeylanDirectory.cc.

References GetSeparator(), and toString().

virtual void Ceylan::System::Directory::getSortedEntries ( std::list< std::string > &  subDirectories,
std::list< std::string > &  files,
std::list< std::string > &  otherEntries 
) const [pure virtual]

Returns the names of all direct entries of any type of this directory (including files and directories), in the corresponding specified list.

Parameters:
subDirectories the caller-provided list in which subDirectories of this directory will be added.
files the caller-provided list in which files of this directory will be added.
otherEntries the caller-provided list in which other entries (named FIFO, sockets, block or character device, etc.) of this directory will be added.
Exceptions:
DirectoryLookupFailed if the operation failed or is not supported.
Note:
Aliases for current and parent directories (ex: '.' and '..') will be filtered out.

Implemented in Ceylan::System::LibfatDirectory, and Ceylan::System::StandardDirectory.

virtual void Ceylan::System::Directory::getSubdirectories ( std::list< std::string > &  subDirectories  )  const [pure virtual]

Returns the names of all direct subdirectories of this directory, in the specified list.

Parameters:
subDirectories the caller-provided list in which subdirectories will be added.
Exceptions:
DirectoryLookupFailed if an error occured.
Note:
Aliases for current and parent directories (ex: '.' and '..') will be filtered out.

Implemented in Ceylan::System::LibfatDirectory, and Ceylan::System::StandardDirectory.

void Directory::goDown ( const std::string &  subdirectoryName  )  [virtual]

virtual bool Ceylan::System::Directory::hasDirectory ( const std::string &  subdirectoryName  )  const [pure virtual]

Tells whether the directory has a direct subdirectory named subdirectoryName.

Parameters:
subdirectoryName the name of the directory entry to look-up. Alias for current directory (ex: '.') and parent one (ex: '..') are always deemed existing.
Exceptions:
DirectoryLookupFailed is the operation failed or is not supported.

Implemented in Ceylan::System::LibfatDirectory, and Ceylan::System::StandardDirectory.

virtual bool Ceylan::System::Directory::hasEntry ( const std::string &  entryName  )  const [pure virtual]

Tells whether the directory has a direct entry named entryName.

Parameters:
entryName the name of the entry to look-up.
Exceptions:
DirectoryLookupFailed is the operation failed or is not supported.

Implemented in Ceylan::System::LibfatDirectory, and Ceylan::System::StandardDirectory.

Referenced by goDown().

virtual bool Ceylan::System::Directory::hasFile ( const std::string &  fileName  )  const [pure virtual]

Tells whether the directory has a direct file or symbolic link named fileName.

Parameters:
fileName the name of the file to look-up.
Exceptions:
DirectoryLookupFailed is the operation failed or is not supported.

Implemented in Ceylan::System::LibfatDirectory, and Ceylan::System::StandardDirectory.

bool Directory::IsAbsolutePath ( const std::string &  path  )  [static]

Tells whether specified path is an absolute path.

Parameters:
path the path that may be absolute.
Exceptions:
DirectoryException if the operation failed or is not supported on this platform. This includes throwing a more specific DirectoryDelegatingException (a child class of DirectoryException), should the underlying filesystem manager not be retrieved as expected.

Definition at line 163 of file CeylanDirectory.cc.

References GetCorrespondingFileSystemManager(), and Ceylan::System::FileSystemManager::isAbsolutePath().

bool Directory::IsAValidDirectoryPath ( const std::string &  directoryString  )  [static]

Returns whether specified string is a valid directory path.

Parameters:
directoryString the directory string.
Note:
If no regular expression support is available, then the name will be deemed always correct.
Exceptions:
DirectoryException if the operation failed or is not supported on this platform. This includes throwing a more specific DirectoryDelegatingException (a child class of DirectoryException), should the underlying filesystem manager not be retrieved as expected.

Definition at line 141 of file CeylanDirectory.cc.

References GetCorrespondingFileSystemManager(), and Ceylan::System::FileSystemManager::isAValidDirectoryPath().

bool Directory::isValid (  )  const [virtual]

Tells whether the reference on the directory is valid.

Checks that corresponding path exists, and that it is a directory.

Exceptions:
DirectoryException if the operation failed or is not supported.

Definition at line 364 of file CeylanDirectory.cc.

References _path, Ceylan::System::FileSystemManager::existsAsDirectory(), and getCorrespondingFileSystemManager().

Referenced by Ceylan::System::LibfatDirectory::LibfatDirectory(), and Ceylan::System::StandardDirectory::StandardDirectory().

string Directory::JoinPath ( const std::string &  firstPath,
const std::string &  secondPath 
) [static]

string Directory::JoinPath ( const std::list< std::string > &  pathElements  )  [static]

void Directory::Move ( const std::string &  sourceDirectoryname,
const std::string &  targetDirectoryname 
) [static]

Moves specified directory on filesystem.

A special case of directory moving is directory renaming.

Parameters:
sourceDirectoryname the path of the directory to be moved.
targetDirectoryname the path of the target directory.
Exceptions:
DirectoryException,including DirectoryMoveFailed if the operation failed or is not supported on this platform, or DirectoryDelegatingException should the underlying filesystem manager not be retrieved as expected.

Definition at line 102 of file CeylanDirectory.cc.

References GetCorrespondingFileSystemManager(), and Ceylan::System::FileSystemManager::moveDirectory().

Directory & Directory::Open ( const std::string &  directoryName = ""  )  [static]

Returns a Directory reference on specified already-existing directory, which will be "opened" (i.e.

referred to).

Parameters:
directoryName the name of the directory. If not specified (the string is empty), returns a reference to the current working directory.
Directory factory, to be used instead of a specific Directory subclass constructor, so that it can return a Directory instance that is actually a specialized one (ex: a StandardDirectory, not an abstract Directory).

Exceptions:
DirectoryException,including DirectoryOpeningFailed if the operation failed or is not supported on this platform, or DirectoryDelegatingException if the relevant filesystem manager could not be retrieved.

Reimplemented in Ceylan::System::LibfatDirectory, and Ceylan::System::StandardDirectory.

Definition at line 277 of file CeylanDirectory.cc.

References GetCorrespondingFileSystemManager(), and Ceylan::System::FileSystemManager::openDirectory().

Directory& Ceylan::System::Directory::operator= ( const Directory source  )  [private]

Assignment operator made private to ensure that it will be never called.

The compiler should complain whenever this undefined operator is called, implicitly or not.

void Directory::Remove ( const std::string &  directoryPath,
bool  recursive = false 
) [static]

Removes the directory from disk.

Parameters:
directoryPath the path of the target directory.
recursive if false, the specified directory is expected to be empty, and it will be removed. If true, then the full directory content (including all files and possible subdirectories) and this directory itself will be removed.
Exceptions:
DirectoryException,including DirectoryRemoveFailed if the operation failed or is not supported on this platform, or DirectoryDelegatingException should the underlying filesystem manager not be retrieved as expected.

Definition at line 91 of file CeylanDirectory.cc.

References GetCorrespondingFileSystemManager(), and Ceylan::System::FileSystemManager::removeDirectory().

void Directory::removeLeadingSeparator (  )  [virtual]

Removes the leading separator, if any, in the path of this directory path.

Exceptions:
DirectoryException if the operation failed or is not supported.

Definition at line 387 of file CeylanDirectory.cc.

References _path, getCorrespondingFileSystemManager(), and Ceylan::System::FileSystemManager::removeLeadingSeparator().

Referenced by Ceylan::System::LibfatDirectory::LibfatDirectory(), and Ceylan::System::StandardDirectory::StandardDirectory().

void Directory::RemoveLeadingSeparator ( std::string &  path  )  [static]

Removes the leading separator, if any, in specified directory's path.

Parameters:
path the path that will be modified.
Exceptions:
DirectoryException if the operation failed or is not supported on this platform. This includes throwing a more specific DirectoryDelegatingException (a child class of DirectoryException), should the underlying filesystem manager not be retrieved as expected.

Definition at line 152 of file CeylanDirectory.cc.

References GetCorrespondingFileSystemManager(), and Ceylan::System::FileSystemManager::removeLeadingSeparator().

void TextDisplayable::SetOutputFormat ( TextOutputFormat  newOutputFormat  )  [static, inherited]

Sets the current overall text format to be used by TextDisplayable instances.

Parameters:
newOutputFormat the new output format.

Definition at line 72 of file CeylanTextDisplayable.cc.

References Ceylan::TextDisplayable::_OutputFormat.

Referenced by Ceylan::Log::LogHolder::LogHolder().

list< string > Directory::SplitPath ( const std::string &  path  )  [static]

void Directory::StripFilename ( const std::string &  path,
std::string *  base,
std::string *  file = 0 
) [static]

Separates the full pathname path into a basename base and file name file.

For example, this method applied to "/mnt/raid/md0/LOANI-0.3" returns respectively "/mnt/raid/md0" and "LOANI-0.3", when the separator is '/'.

Parameters:
path the path which is to be stripped.
base if non null, must be a pointer to an already allocated string where the basename will be stored. If not interested in the basename, specify a null (0) pointer instead: this method will act as UNIX "basename".
file if non null, must be a pointer to an already allocated string where the filename will be stored. If not interested in the filename, specify a null (0) pointer instead: this method will act as UNIX "dirname".
Exceptions:
DirectoryException if the operation failed or is not supported on this platform. This includes throwing a more specific DirectoryDelegatingException (a child class of DirectoryException), should the underlying filesystem manager not be retrieved as expected.

Definition at line 227 of file CeylanDirectory.cc.

References GetCorrespondingFileSystemManager(), and Ceylan::System::FileSystemManager::stripFilename().

Referenced by Ceylan::Log::LogPlug::GetSpeakerNameFrom().

const std::string TextDisplayable::ToString ( std::list< TextDisplayable * >  displayables,
Ceylan::VerbosityLevels  level = Ceylan::high 
) [static, inherited]

Returns a user-friendly description of this list of pointers to text displayable instances.

Parameters:
displayables a list of pointers to TextDisplayable instances/
level the requested verbosity level.
Note:
Text output format is determined from overall settings.
See also:
toString, Ceylan::VerbosityLevels

Definition at line 45 of file CeylanTextDisplayable.cc.

References Ceylan::formatStringList().

const string Directory::toString ( Ceylan::VerbosityLevels  level = Ceylan::high  )  const [virtual]

Returns a user-friendly description of the state of this object.

Parameters:
level the requested verbosity level.
Note:
Text output format is determined from overall settings.
See also:
TextDisplayable

Implements Ceylan::TextDisplayable.

Reimplemented in Ceylan::System::LibfatDirectory, and Ceylan::System::StandardDirectory.

Definition at line 401 of file CeylanDirectory.cc.

References _path.

Referenced by GetSeparatorAsString().


Member Data Documentation

TextDisplayable::TextOutputFormat TextDisplayable::_OutputFormat = rawText [static, protected, inherited]

The text format to be used currently by TextDisplayable instances.

Note:
Defaults to raw text.

Definition at line 158 of file CeylanTextDisplayable.h.

Referenced by Ceylan::TextDisplayable::GetOutputFormat(), and Ceylan::TextDisplayable::SetOutputFormat().

std::string Ceylan::System::Directory::_path [protected]


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

Generated on Thu Jun 4 20:40:47 2009 for Ceylan by  doxygen 1.5.8