Ceylan::System::FileLocator Class Reference

File locators allow to find files in a set of directories, as Unix PATH variables do. More...

#include <CeylanFileLocator.h>

Inheritance diagram for Ceylan::System::FileLocator:

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

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

 FileLocator ()
 Creates a new empty file locator.
 FileLocator (const std::string &variableName, char separator= ':')
 Creates a new file locator, whose first registered paths come from specified environment variable, parsed according to the chosen separator.
virtual ~FileLocator () throw ()
 Virtual destructor.
virtual bool addPath (const std::string &newPath)
 Adds a new path to the set of directories gathered by the file locator.
virtual bool addPaths (const std::list< std::string > &paths)
 Adds all paths in specified list to the set of directories gathered by the file locator.
virtual bool addPathsFromEnvironmentVariable (const std::string &variableName, char separator= ':')
 Adds the set of directories specified by an environment variable, which are aggregated thanks to the specified separator.
virtual bool removePath (const std::string &pathToRemove)
 Removes specified path from the set of directories of the file locator, if present.
virtual std::string find (const std::string &filename) const
 Finds the specified file in directories listed by the locator, and returns the full path of the first match in the list.
virtual const std::list
< std::string > & 
getPaths () const
 Returns the internal list of paths managed by the locator.
virtual const std::string toString (Ceylan::VerbosityLevels level=Ceylan::high) const
 Returns an user-friendly description of the state of this object.

Static Public Member Functions

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 Attributes

std::list< std::string > _paths
 The internal list of paths of the locator.

Static Protected Attributes

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

Private Member Functions

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


Detailed Description

File locators allow to find files in a set of directories, as Unix PATH variables do.

Directories are searched in turn from the first registered one to the last.

The user may register non-existing directories in the locator. A given directory can be referenced at most one time in the locator.

Definition at line 76 of file CeylanFileLocator.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

FileLocator::FileLocator (  ) 

Creates a new empty file locator.

Definition at line 78 of file CeylanFileLocator.cc.

FileLocator::FileLocator ( const std::string &  variableName,
char  separator = ':' 
) [explicit]

Creates a new file locator, whose first registered paths come from specified environment variable, parsed according to the chosen separator.

See also:
addPathsFromEnvironmentVariable

Definition at line 86 of file CeylanFileLocator.cc.

References addPathsFromEnvironmentVariable().

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

Virtual destructor.

Definition at line 114 of file CeylanFileLocator.cc.

Ceylan::System::FileLocator::FileLocator ( const FileLocator 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

bool FileLocator::addPath ( const std::string &  newPath  )  [virtual]

Adds a new path to the set of directories gathered by the file locator.

Parameters:
newPath a new path to add.
Returns:
true iff the added path was not already listed.

Definition at line 121 of file CeylanFileLocator.cc.

References _paths, and generalUtils::true.

Referenced by addPaths().

bool FileLocator::addPaths ( const std::list< std::string > &  paths  )  [virtual]

Adds all paths in specified list to the set of directories gathered by the file locator.

Parameters:
paths the list of paths to add.
Returns:
true iff at least one path was not already listed.

Definition at line 137 of file CeylanFileLocator.cc.

References addPath(), and generalUtils::false.

Referenced by addPathsFromEnvironmentVariable().

bool FileLocator::addPathsFromEnvironmentVariable ( const std::string &  variableName,
char  separator = ':' 
) [virtual]

Adds the set of directories specified by an environment variable, which are aggregated thanks to the specified separator.

For example, addPathsFromEnvironmentVariable( "PATH" ), with PATH = "/bin:/usr/bin:/usr/local/bin:/usr/local" adds the corresponding four directories to this file locator.

Returns:
true iff at least one directory has been added thanks to this call.

Definition at line 152 of file CeylanFileLocator.cc.

References addPaths(), Ceylan::System::getEnvironmentVariable(), and Ceylan::split().

Referenced by FileLocator().

string FileLocator::find ( const std::string &  filename  )  const [virtual]

Finds the specified file in directories listed by the locator, and returns the full path of the first match in the list.

Parameters:
filename the name of the file to look for, be it a regular file or a symbolic link.
Returns:
the full path of the first directory stored in this Locator that contains specified file.
Exceptions:
FileLocatorException if nothing matches, i.e. if this file is not found through recorded directories.

Definition at line 181 of file CeylanFileLocator.cc.

References _paths, Ceylan::System::File::ExistsAsFileOrSymbolicLink(), Ceylan::System::Directory::JoinPath(), and toString().

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

const std::list< std::string > & FileLocator::getPaths (  )  const [virtual]

Returns the internal list of paths managed by the locator.

Definition at line 205 of file CeylanFileLocator.cc.

References _paths.

Referenced by Ceylan::Plugin::Plugin().

FileLocator& Ceylan::System::FileLocator::operator= ( const FileLocator 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.

bool FileLocator::removePath ( const std::string &  pathToRemove  )  [virtual]

Removes specified path from the set of directories of the file locator, if present.

Parameters:
pathToRemove the path to remove.
Returns:
true iff the specified path has been found, and therefore has been removed.

Definition at line 163 of file CeylanFileLocator.cc.

References _paths, generalUtils::false, and generalUtils::true.

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().

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 FileLocator::toString ( Ceylan::VerbosityLevels  level = Ceylan::high  )  const [virtual]

Returns an 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:
Ceylan::TextDisplayable

Implements Ceylan::TextDisplayable.

Definition at line 214 of file CeylanFileLocator.cc.

References _paths, and Ceylan::formatStringList().

Referenced by find().


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::list<std::string> Ceylan::System::FileLocator::_paths [protected]

The internal list of paths of the locator.

Definition at line 222 of file CeylanFileLocator.h.

Referenced by addPath(), find(), getPaths(), removePath(), and toString().


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

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