libcamgm
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | List of all members
ca_mgm::path::PathName Class Reference

PathName manipulation class. More...

#include <PathName.hpp>

Public Types

typedef std::list< std::string > List
 

Public Member Functions

 PathName ()
 Create an empty PathName object. More...
 
 PathName (const PathName &path)
 Create a Copy of a PathName object. More...
 
 PathName (const PathName::List &list)
 Create a new PathName object from a PathName::List. More...
 
 PathName (const std::string &name)
 Create a new PathName object from a std::string. More...
 
 PathName (const char *name)
 Create a new PathName object from a c string. More...
 
virtual ~PathName ()
 
PathNameoperator= (const PathName &path)
 Assigns path to this PathName object and returns a reference to it. More...
 
PathNameoperator+= (const PathName &path)
 Appends path to this PathName object and a reference to it. More...
 
std::string toString () const
 Returns the complete path this PathName object holds. More...
 
std::string asString () const
 
PathName::List toList () const
 Returns the path this PathName object holds, as a PathName::List. The first element of that list is either the prefix, or, if there is no drive prefix it's an empty string. More...
 
std::string prefix () const
 Returns the path prefix if existent, otherwise "". More...
 
bool empty () const
 Returns true if this PathName object holds an empty path. More...
 
bool absolute () const
 Returns true if this PathName object holds an absolute Path. More...
 
bool relative () const
 Returns true if this PathName object holds an relative path. More...
 
PathName dirName () const
 Returns the directory part of the path string. More...
 
std::string baseName () const
 Returns the base name part of the path string. More...
 
PathName absoluteName () const
 Returns the absolute name of the path string this object holds. More...
 
PathName relativeName () const
 Returns the relative name of the path string this object holds. More...
 
PathName cat (const PathName &add) const
 Create a new PathName object from the concatenation of this and add. More...
 
PathName extend (const std::string &ext) const
 Create a new PathName object by extending this PathName object by ext. More...
 
bool equal (const PathName &rpath) const
 Test for equality of this and rpath. More...
 

Static Public Member Functions

static PathName dirName (const PathName &path)
 Returns the directory part of path More...
 
static std::string baseName (const PathName &path)
 Returns the base name part of path More...
 
static PathName absoluteName (const PathName &path)
 Returns the absolute name of path. More...
 
static PathName relativeName (const PathName &path)
 Returns the relative name of path. More...
 
static PathName cat (const PathName &path, const PathName &add)
 Create a new PathName object by concatenating two existing ones. More...
 
static PathName extend (const PathName &path, const std::string &ext)
 Create a new PathName object by extending path by ext. More...
 
static bool equal (const PathName &lpath, const PathName &rpath)
 Static function to test for equality of two PathName objects. More...
 

Protected Member Functions

void assign (const std::string &path)
 Assigns path to this PathName objects m_name string. More...
 
void assign (const PathName::List &list)
 Assigns list to this PathName objects m_name string. More...
 

Private Attributes

size_t m_prefix
 holds index of first character in the path string after an (optional) drive letter. More...
 
std::string m_name
 

Detailed Description

PathName manipulation class.

This class is intended for internal usage inside of LiMaL pluglibs and should never appear in the pluglib interface.

Member Typedef Documentation

typedef std::list<std::string> ca_mgm::path::PathName::List

Constructor & Destructor Documentation

ca_mgm::path::PathName::PathName ( )

Create an empty PathName object.

ca_mgm::path::PathName::PathName ( const PathName path)

Create a Copy of a PathName object.

Parameters
pathThe PathName object to be copied.
ca_mgm::path::PathName::PathName ( const PathName::List list)

Create a new PathName object from a PathName::List.

Parameters
listThe PathName::List from which the new PathName object shall be created. The first element of this List has to be a prefix, or if there is no prefix an empty string.
Exceptions
ca_mgm::ValueException
ca_mgm::path::PathName::PathName ( const std::string &  name)

Create a new PathName object from a std::string.

Parameters
nameThe string from which the new PathName object shall be created.
Exceptions
ca_mgm::ValueException
ca_mgm::path::PathName::PathName ( const char *  name)

Create a new PathName object from a c string.

Parameters
nameThe character pointer to the c string from which the new PathName object shall be created.
Exceptions
ca_mgm::ValueException
virtual ca_mgm::path::PathName::~PathName ( )
virtual

Destructor

Member Function Documentation

bool ca_mgm::path::PathName::absolute ( ) const

Returns true if this PathName object holds an absolute Path.

Returns
True if this PathName object holds an absolute path (like '/foo/bar').
PathName ca_mgm::path::PathName::absoluteName ( ) const

Returns the absolute name of the path string this object holds.

PathName p1("foo/bar/some_file");
std::cout << p1.absoluteName(); // == "/foo/bar/some_file"
Returns
The absolute name form of the path string.
static PathName ca_mgm::path::PathName::absoluteName ( const PathName path)
static

Returns the absolute name of path.

PathName p1("foo/bar/some_file");
std::cout << absoluteName( p1 ); // == "/foo/bar/some_file"
Returns
The absolute name form of path.
void ca_mgm::path::PathName::assign ( const std::string &  path)
protected

Assigns path to this PathName objects m_name string.

Takes the given path string, cleans it (i.e.: removing redundant parts from it like './foo/../bar/some_file" -> './bar/some_file') sets m_prefix and assigns the cleansed path string to m_path.

Parameters
pathpath string that is to be assigned to this object.
Exceptions
ca_mgm::ValueException
void ca_mgm::path::PathName::assign ( const PathName::List list)
protected

Assigns list to this PathName objects m_name string.

Takes the given path list, cleans it (i.e.: removing redundant parts from it like './foo/../bar/some_file" -> './bar/some_file') sets m_prefix and assigns the cleansed path string to m_path.

Parameters
pathpath string that is to be assigned to this object.
Exceptions
ca_mgm::ValueException
std::string ca_mgm::path::PathName::asString ( ) const
inline
std::string ca_mgm::path::PathName::baseName ( ) const

Returns the base name part of the path string.

Returns the base name (i.e. the file name) of the path string. For example:

std::cout << PathName("/foo/bar/some_file").baseName(); // == "some_file"
Returns
the file name part of the path string
static std::string ca_mgm::path::PathName::baseName ( const PathName path)
static

Returns the base name part of path

Returns the base name (i.e. the file name) of the path string. For example:

PathName p1("/foo/bar/some_file");
std::cout << PathName::baseName( p1 ); // == "some_file"
Parameters
pathThe PathName object you want to inspect
Returns
The file name part of the path string
PathName ca_mgm::path::PathName::cat ( const PathName add) const

Create a new PathName object from the concatenation of this and add.

Creates a new PathName object consisting of the concatenation of this PathName object and add and returns it. For example:

PathName p1("/foo");
PathName p2("bar/some_file");
std::cout << p1.cat( p2 ); // == "/foo/bar/some_file"
Parameters
addReference to the PathName object to be added to this object.
Returns
A new PathName object consisting of the concatenation of this object and add.
static PathName ca_mgm::path::PathName::cat ( const PathName path,
const PathName add 
)
static

Create a new PathName object by concatenating two existing ones.

Static function for concatenating two PathName objects. For example:

PathName p1("/foo");
PathName p2("bar/some_file");
std::cout << PathName::cat( p1, p2 ); // == "/foo/bar/some_file"
Parameters
pathThe front part of the resulting path.
addThe part that is to be added.
Returns
A PathName object that consists of the concatenation of the two arguments.
PathName ca_mgm::path::PathName::dirName ( ) const

Returns the directory part of the path string.

Returns the directory part of the path string this PathName object holds. For example:

std::cout << PathName("/foo/bar/some_file").dirName(); // == "/foo/bar"
Returns
The substring of the path up to the file name (without prefix)
static PathName ca_mgm::path::PathName::dirName ( const PathName path)
static

Returns the directory part of path

Static function to aquire the directory part of a PathName object. For example:

PathName p1("/foo/bar/some_file");
std::cout << PathName::dirName(p1); // == "/foo/bar"
Parameters
pathThe PathName object you want to inspect
Returns
The substring of the path up to the file name (without prefix)
bool ca_mgm::path::PathName::empty ( ) const

Returns true if this PathName object holds an empty path.

Returns
True if this PathName object holds an empty path.
bool ca_mgm::path::PathName::equal ( const PathName rpath) const

Test for equality of this and rpath.

Parameters
rpathReference to the PathName object that is to be compared to this object.
Returns
True if path string of rpath equals the path string this object holds.
static bool ca_mgm::path::PathName::equal ( const PathName lpath,
const PathName rpath 
)
static

Static function to test for equality of two PathName objects.

Parameters
lpathReference to PathName object one.
rpathReference to PathName object two.
Returns
True if lpath equals rpath.
PathName ca_mgm::path::PathName::extend ( const std::string &  ext) const

Create a new PathName object by extending this PathName object by ext.

Use this function to create a new PathName object that consists of this PathName object extended by the string ext. Basically it just glues the two strings together and calls PathName( const std::string ) For Example:

PathName p1("/foo");
std::string strExt(".old");
std::cout << p1.extend( strExt ); // == "/foo.old"
Parameters
extReference to a std::string containing the extension.
Returns
A new PathName object that consists of path extended by ext.
static PathName ca_mgm::path::PathName::extend ( const PathName path,
const std::string &  ext 
)
static

Create a new PathName object by extending path by ext.

Static function to create a new PathName object that consists of path extended by the string ext. Basically it just glues the two strings together and calls PathName( const std::string ) For Example:

PathName p1("/foo");
std::string strExt(".old");
std::cout << PathName::extend(p1, strExt ); // == "/foo.old"
Parameters
pathReference to a PathName object that is to be extended.
extReference to a std::string containing the extension.
Returns
A new PathName object that consists of path extended by ext.
PathName& ca_mgm::path::PathName::operator+= ( const PathName path)

Appends path to this PathName object and a reference to it.

Parameters
pathThe PathName object that is to be appended.
Returns
A reference to this PathName object.
PathName& ca_mgm::path::PathName::operator= ( const PathName path)

Assigns path to this PathName object and returns a reference to it.

Parameters
pathThe PathName object to assign.
Returns
A reference to this PathName object.
std::string ca_mgm::path::PathName::prefix ( ) const

Returns the path prefix if existent, otherwise "".

Returns the path prefix (i.e. drive letter), if the path this PathName object holds contains one (like in 'c:/foo/bar'), otherwise the empty string will be returned.

Returns
prefix/drive letter or the empty string
bool ca_mgm::path::PathName::relative ( ) const

Returns true if this PathName object holds an relative path.

Returns
True if this PathName object holds an relative path (like './foo/bar').
PathName ca_mgm::path::PathName::relativeName ( ) const

Returns the relative name of the path string this object holds.

PathName p1("/foo/bar/some_file");
std::cout << p1.relativeName(); // == "./foo/bar/some_file"
Returns
The absolute name form of the path string.
static PathName ca_mgm::path::PathName::relativeName ( const PathName path)
static

Returns the relative name of path.

PathName p1("/foo/bar/some_file");
std::cout << relativeName( p1 ); // == "./foo/bar/some_file"
Returns
The relative name form of path.
PathName::List ca_mgm::path::PathName::toList ( ) const

Returns the path this PathName object holds, as a PathName::List. The first element of that list is either the prefix, or, if there is no drive prefix it's an empty string.

Returns
The complete path this PathName object holds, as a PathName::List.
Exceptions
ca_mgm::ValueException
std::string ca_mgm::path::PathName::toString ( ) const

Returns the complete path this PathName object holds.

Returns
The complete path this PathName object holds.

Member Data Documentation

std::string ca_mgm::path::PathName::m_name
private
size_t ca_mgm::path::PathName::m_prefix
private

holds index of first character in the path string after an (optional) drive letter.


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