libcommonc++  0.7
SearchPath Class Reference

A file search path. More...

#include <SearchPath.h++>

Collaboration diagram for SearchPath:

Public Member Functions

 SearchPath (const String &path="")
 Construct a new SearchPath for the given path string. More...
 
 SearchPath (const SearchPath &other)
 Copy constructor. More...
 
 ~SearchPath ()
 Destructor. More...
 
SearchPathoperator= (const SearchPath &other)
 Assignment operator. More...
 
void append (const String &dir)
 Append a directory to the end of the path. More...
 
void prepend (const String &dir)
 Prepend a directory to the beginning of the path. More...
 
void remove (const String &dir)
 Remove a directory from the path. More...
 
void clear ()
 Clear the path. More...
 
bool contains (const String &dir) const
 Determine if the path contains a directory. More...
 
bool find (FileName &file) const
 Search the path for a file. More...
 
bool isEmpty () const
 Test if the path is empty. More...
 
size_t getDirectoryCount () const
 Get the number of directories in the search path. More...
 
size_t length () const
 Get the number of directories in the search path. More...
 
String getDirectory (int index) const
 Get the directory at the specified index in the search path. More...
 
String operator[] (int index) const
 Get the directory at the specified index in the search path. More...
 
String getPath () const
 Get the path as a String. More...
 
void fromString (const String &path)
 Parse a SearchPath from a String representation. More...
 
String toString () const
 Get a String representation of the SearchPath. More...
 

Static Public Attributes

static const SearchPath empty
 An empty SearchPath. More...
 
static const char * separator = PS
 The host platform's path separator. More...
 

Detailed Description

A file search path.

A search path is a series of directories (typically specified as absolute paths) that may be searched to locate a file given its filename.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ SearchPath() [1/2]

SearchPath ( const String path = "")

Construct a new SearchPath for the given path string.

Parameters
pathThe path.

◆ SearchPath() [2/2]

SearchPath ( const SearchPath other)

Copy constructor.

◆ ~SearchPath()

~SearchPath ( )

Destructor.

Member Function Documentation

◆ append()

void append ( const String dir)

Append a directory to the end of the path.

If the directory is already in the path, the path will be unchanged.

Parameters
dirThe directory.

◆ clear()

void clear ( )

Clear the path.

Removes all directories from the path.

◆ contains()

bool contains ( const String dir) const

Determine if the path contains a directory.

Parameters
dirThe directory to search for.
Returns
true if the directory is found in the path, false otherwise.

◆ find()

bool find ( FileName file) const

Search the path for a file.

Parameters
fileThe name of the file to search for.
Returns
true if the file was found in one of the directories in the search path, false otherwise. If the file was found, the directory component of the FileName object is updated to reflect the location of the file.

◆ fromString()

void fromString ( const String path)

Parse a SearchPath from a String representation.

◆ getDirectory()

String getDirectory ( int  index) const

Get the directory at the specified index in the search path.

Exceptions
OutOfBoundsExceptionIf the index is invalid.

◆ getDirectoryCount()

size_t getDirectoryCount ( ) const
inline

Get the number of directories in the search path.

Equivalent to length().

◆ getPath()

String getPath ( ) const

Get the path as a String.

Returns
The platform-specific representation of the path.

◆ isEmpty()

bool isEmpty ( ) const
inline

Test if the path is empty.

◆ length()

size_t length ( ) const
inline

Get the number of directories in the search path.

◆ operator=()

SearchPath & operator= ( const SearchPath other)

Assignment operator.

◆ operator[]()

String operator[] ( int  index) const
inline

Get the directory at the specified index in the search path.

Exceptions
OutOfBoundsExceptionIf the index is invalid.

◆ prepend()

void prepend ( const String dir)

Prepend a directory to the beginning of the path.

If the directory is already in the path, the path will be unchanged.

Parameters
dirThe directory.

◆ remove()

void remove ( const String dir)

Remove a directory from the path.

If the directory is not in the path, the method does nothing.

◆ toString()

String toString ( ) const
inline

Get a String representation of the SearchPath.

Equivalent to getPath().

Member Data Documentation

◆ empty

const SearchPath empty
static

An empty SearchPath.

◆ separator

const char * separator = PS
static

The host platform's path separator.


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