G::Path Class Reference

A Path object represents a file system path. More...

#include <gpath.h>

List of all members.

Public Member Functions

 Path ()
 Default constructor.
 Path (const std::string &path)
 Implicit constructor.
 Path (const char *path)
 Implicit constructor.
 Path (const Path &path, const std::string &tail)
 Constructor with an implicit pathAppend().
 Path (const Path &path, const std::string &tail_1, const std::string &tail_2)
 Constructor with two implicit pathAppend()s.
 Path (const Path &other)
 Copy constructor.
 ~Path ()
 Destructor.
bool simple () const
 Returns true if the path is just a file/directory name without any separators.
std::string str () const
 Returns the path string.
std::string basename () const
 Returns the path, excluding drive/directory parts.
Path dirname () const
 Returns the drive/directory parts of the path.
std::string extension () const
 Returns the path's filename extension.
void removeExtension ()
 Modifies the path by removing any extension.
bool isAbsolute () const
 Returns !isRelative().
bool isRelative () const
 Returns true if the path is a relative path.
bool hasDriveLetter () const
 Returns true if the path has a leading drive letter (and the operating system uses drive letters).
Pathoperator= (const Path &other)
 Assignment operator.
void pathAppend (const std::string &tail)
 Appends a filename to the path.
Strings split (bool no_dot=true) const
 Spits the path into a list of component parts.
bool operator== (const Path &path) const
 Comparison operator.
bool operator!= (const Path &path) const
 Comparison operator.

Static Public Member Functions

static G::Path join (const G::Path &p1, const G::Path &p2)
 Joins two paths together.


Detailed Description

A Path object represents a file system path.

The class is concerned with path syntax, not file system i/o. This class is necessary because of the mess Microsoft made with drive letters (like having a cwd associated with each drive).

See also:
G::File, G::Directory, G::FileSystem

Definition at line 44 of file gpath.h.


Constructor & Destructor Documentation

G::Path::Path (  ) 

Default constructor.

Creates a zero-length path.

Definition at line 30 of file gpath.cpp.

Referenced by dirname(), join(), and split().

G::Path::Path ( const std::string &  path  ) 

Implicit constructor.

Definition at line 39 of file gpath.cpp.

G::Path::Path ( const char *  path  ) 

Implicit constructor.

Definition at line 44 of file gpath.cpp.

References G_ASSERT.

G::Path::Path ( const Path path,
const std::string &  tail 
)

Constructor with an implicit pathAppend().

Definition at line 50 of file gpath.cpp.

References pathAppend(), and str().

G::Path::Path ( const Path path,
const std::string &  tail_1,
const std::string &  tail_2 
)

Constructor with two implicit pathAppend()s.

Definition at line 56 of file gpath.cpp.

References pathAppend(), and str().

G::Path::Path ( const Path other  ) 

Copy constructor.

Definition at line 63 of file gpath.cpp.

References str().

G::Path::~Path (  ) 

Destructor.

Definition at line 35 of file gpath.cpp.


Member Function Documentation

bool G::Path::simple (  )  const

Returns true if the path is just a file/directory name without any separators.

Note that if the path is simple() then dirname() will return the empty string.

Definition at line 140 of file gpath.cpp.

std::string G::Path::str (  )  const

std::string G::Path::basename (  )  const

Returns the path, excluding drive/directory parts.

Does nothing with the extension (cf. basename(1)).

Definition at line 162 of file gpath.cpp.

References result, and G::FileSystem::slash().

Referenced by GSmtp::StoredFile::destroy(), GSmtp::StoredFile::fail(), filter_run(), GSmtp::StoredFile::lock(), GSmtp::StoredFile::openContent(), split(), and GSmtp::StoredFile::StoredFile().

G::Path G::Path::dirname (  )  const

Returns the drive/directory parts of the path.

If this path is the top of the tree then the null path is returned.

eg. "c:foo\bar.exe" -> "c:foo" eg. "c:\foo\bar.exe" -> "c:\foo" eg. "c:bar.exe" -> "c:" eg. "c:\file" -> "c:\" . eg. "c:\" -> "" eg. "c:" -> "" eg. "\foo\bar.exe" -> "\foo" eg. "\" -> "" eg. "foo\bar\bletch" -> "foo\bar" eg. "foo\bar" -> "foo" eg. "bar.exe" -> "" eg. "\\machine\drive\dir\file.cc" -> "\\machine\drive\dir" eg. "\\machine\drive\file" -> "\\machine\drive" eg. "\\machine\drive" -> ""

Definition at line 182 of file gpath.cpp.

References Path().

Referenced by filter_run(), and G::File::mkdirs().

std::string G::Path::extension (  )  const

Returns the path's filename extension.

Returns the zero-length string if there is none.

Definition at line 320 of file gpath.cpp.

void G::Path::removeExtension (  ) 

Modifies the path by removing any extension.

Definition at line 291 of file gpath.cpp.

bool G::Path::isAbsolute (  )  const

Returns !isRelative().

Definition at line 150 of file gpath.cpp.

References hasDriveLetter(), G::FileSystem::slash(), and str().

Referenced by G::PidFile::check(), and isRelative().

bool G::Path::isRelative (  )  const

Returns true if the path is a relative path.

Definition at line 145 of file gpath.cpp.

References isAbsolute().

Referenced by Main::CommandLineImp::semanticError(), and G::NewProcess::spawn().

bool G::Path::hasDriveLetter (  )  const

Returns true if the path has a leading drive letter (and the operating system uses drive letters).

Definition at line 267 of file gpath.cpp.

References G::FileSystem::usesDriveLetters().

Referenced by isAbsolute(), and pathAppend().

G::Path & G::Path::operator= ( const Path other  ) 

Assignment operator.

Definition at line 380 of file gpath.cpp.

References str().

void G::Path::pathAppend ( const std::string &  tail  ) 

Appends a filename to the path.

A path separator is added if necessary.

Definition at line 301 of file gpath.cpp.

References hasDriveLetter().

Referenced by GPop::Secrets::defaultPath(), join(), GPop::StoreLock::lock(), G::operator+(), G::operator+=(), Path(), and G::Directory::writeable().

G::Path G::Path::join ( const G::Path p1,
const G::Path p2 
) [static]

Joins two paths together.

The second should normally be a relative path, although absolute paths are allowed.

Definition at line 325 of file gpath.cpp.

References Path(), pathAppend(), result, and split().

G::Strings G::Path::split ( bool  no_dot = true  )  const

Spits the path into a list of component parts.

Eliminates "/./" parts if the optional parameter is true.

Definition at line 345 of file gpath.cpp.

References basename(), dirnameImp(), and Path().

Referenced by join().

bool G::Path::operator== ( const Path path  )  const

Comparison operator.

Definition at line 368 of file gpath.cpp.

References m_str.

bool G::Path::operator!= ( const Path path  )  const

Comparison operator.

Definition at line 375 of file gpath.cpp.

References m_str.


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

Generated on Fri Apr 18 15:56:13 2008 for E-MailRelay by  doxygen 1.5.5