Path Class Reference

Extension to the STL string class that allows for easy manipulation of paths. More...

#include <Path.h>

List of all members.

Public Member Functions

 Path ()
 Create a root path.
 Path (const char *path)
 Path (const std::string &path)
 Path (const std::vector< std::string > &compV)
 Create a path built from the strings in compV, by concatenating them with a path separator between each pair.
void appendComponent (const std::string &comp)
 Append comp, preceded if necessary by a path separator.
void appendExtension (const std::string &ext)
 Append ext, preceded if necessary by a dot.
void deleteLastComponent ()
 Delete the last path component from the object, along with any final path separator.
void deleteExtension ()
 Delete the extension (if any, and only the last).
void expandTilde ()
 Expand the initial component, if it begins with '~' or '~user', to its full path value.
void abbreviateWithTilde ()
 Abbreviate the initial component so that it becomes a path, with a tilde, '~', substituted for the full path to the current user's home directory, or '~user' for a user other than the current user.
const bool isAbsolute () const
 Check if this in an absolute path (originating at the root).
const std::vector< std::string > getComponents () const
 Return a vector of strings containing, in order, each path component of the path.
const std::string getLastComponent () const
 Returns the last path component of the path.
const std::string getExtension () const
 Return the path's extension, if any (not including the extension divider).

Static Public Attributes

static const char PATH_DELIM
 Token used to separate path components, '/' on UNIX.


Detailed Description

Extension to the STL string class that allows for easy manipulation of paths.

Author:
Daniel Aarno


Constructor & Destructor Documentation

Path::Path (  )  [inline]

Create a root path.

Path::Path ( const char *  path  )  [inline]

Path::Path ( const std::string &  path  )  [inline]

Path::Path ( const std::vector< std::string > &  compV  ) 

Create a path built from the strings in compV, by concatenating them with a path separator between each pair.

To create an absolute path, use a path delimiter as the first component. To include a trailing path divider, use an empty string as the last component.


Member Function Documentation

void Path::abbreviateWithTilde (  ) 

Abbreviate the initial component so that it becomes a path, with a tilde, '~', substituted for the full path to the current user's home directory, or '~user' for a user other than the current user.

Unaltered if it doesn't begin with the user?s home directory.

Note:
Currently only '~' and not '~user' is abbreviated

void Path::appendComponent ( const std::string &  comp  ) 

Append comp, preceded if necessary by a path separator.

void Path::appendExtension ( const std::string &  ext  ) 

Append ext, preceded if necessary by a dot.

void Path::deleteExtension (  ) 

Delete the extension (if any, and only the last).

Strips any trailing path separator before checking for an extension. If the path represents the root path, however, it is unaltered.

void Path::deleteLastComponent (  ) 

Delete the last path component from the object, along with any final path separator.

If the path represents the root path, however, it is unaltered.

void Path::expandTilde (  ) 

Expand the initial component, if it begins with '~' or '~user', to its full path value.

The path remains unaltered if that component cannot be expanded.

Note:
Currently only '~' and not '~user' is expanded

const std::vector<std::string> Path::getComponents (  )  const

Return a vector of strings containing, in order, each path component of the path.

The strings in the vector appear in the order they did in the path. If the path begins or ends with the path separator, then the first or last component, respectively, will contain the separator. Empty components (caused by consecutive path separators) are deleted.

Returns:
A vector of strings containing, in order, each path component of the path.

const std::string Path::getExtension (  )  const

Return the path's extension, if any (not including the extension divider).

const std::string Path::getLastComponent (  )  const

Returns the last path component of the path.

const bool Path::isAbsolute (  )  const [inline]

Check if this in an absolute path (originating at the root).

Returns:
true if this is an absolute path and false if it is a relative path.


Member Data Documentation

const char Path::PATH_DELIM [static]

Token used to separate path components, '/' on UNIX.


The documentation for this class was generated from the following file:
Generated on Sun Mar 11 15:33:26 2007 for MetalWarriors by  doxygen 1.4.7