Public Member Functions | Static Public Member Functions | List of all members
G::Path Class Reference

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

#include <gpath.h>

Public Member Functions

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

Static Public Member Functions

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

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.

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 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 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

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 G::FileSystem::slash().

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

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.

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.

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

bool G::Path::isAbsolute ( ) const

Returns !isRelative().

Definition at line 150 of file gpath.cpp.

References G::FileSystem::slash().

Referenced by GSmtp::FactoryParser::check().

bool G::Path::isRelative ( ) const

Returns true if the path is a relative path.

Definition at line 145 of file gpath.cpp.

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

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 pathAppend(), and split().

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

Comparison operator.

Definition at line 375 of file gpath.cpp.

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

Assignment operator.

Definition at line 380 of file gpath.cpp.

References str().

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

Comparison operator.

Definition at line 368 of file gpath.cpp.

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.

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

void G::Path::removeExtension ( )

Modifies the path by removing any extension.

Definition at line 291 of file gpath.cpp.

Referenced by GSmtp::StoredFile::unfail().

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.

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

Referenced by join().

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

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