Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Poco::Path Class Reference

#include <Path.h>

Public Types

enum  Style {
  PATH_UNIX , PATH_URI = PATH_UNIX , PATH_WINDOWS , PATH_VMS ,
  PATH_NATIVE , PATH_GUESS
}
 
typedef std::vector< std::string > StringVec
 

Public Member Functions

 Path ()
 
 Path (bool absolute)
 Creates an empty relative path.
 
 Path (const char *path)
 Creates an empty absolute or relative path.
 
 Path (const char *path, Style style)
 Creates a path from a string.
 
 Path (const std::string &path)
 Creates a path from a string.
 
 Path (const std::string &path, Style style)
 Creates a path from a string.
 
 Path (const Path &path)
 Creates a path from a string.
 
 Path (Path &&path) noexcept
 Copy constructor.
 
 Path (const Path &parent, const std::string &fileName)
 Move constructor.
 
 Path (const Path &parent, const char *fileName)
 
 Path (const Path &parent, const Path &relative)
 
 ~Path ()
 
Pathoperator= (const Path &path)
 Destroys the Path.
 
Pathoperator= (Path &&path) noexcept
 Assignment operator.
 
Pathoperator= (const std::string &path)
 Move assignment.
 
Pathoperator= (const char *path)
 Assigns a string containing a path in native format.
 
void swap (Path &path)
 Assigns a string containing a path in native format.
 
Pathassign (const std::string &path)
 Swaps the path with another one.
 
Pathassign (const std::string &path, Style style)
 Assigns a string containing a path in native format.
 
Pathassign (const Path &path)
 Assigns a string containing a path.
 
Pathassign (const char *path)
 Assigns the given path.
 
std::string toString () const
 Assigns a string containing a path.
 
std::string toString (Style style) const
 Returns a string containing the path in native format.
 
Pathparse (const std::string &path)
 Returns a string containing the path in the given format.
 
Pathparse (const std::string &path, Style style)
 Same as assign().
 
bool tryParse (const std::string &path)
 Assigns a string containing a path.
 
bool tryParse (const std::string &path, Style style)
 
PathparseDirectory (const std::string &path)
 
PathparseDirectory (const std::string &path, Style style)
 
PathmakeDirectory ()
 
PathmakeFile ()
 
PathmakeParent ()
 
PathmakeAbsolute ()
 Makes the path refer to its parent.
 
PathmakeAbsolute (const Path &base)
 
Pathappend (const Path &path)
 
Pathresolve (const Path &path)
 Appends the given path.
 
bool isAbsolute () const
 
bool isRelative () const
 Returns true iff the path is absolute.
 
bool isDirectory () const
 Returns true iff the path is relative.
 
bool isFile () const
 
PathsetNode (const std::string &node)
 
const std::string & getNode () const
 
PathsetDevice (const std::string &device)
 Returns the node name.
 
const std::string & getDevice () const
 
int depth () const
 Returns the device name.
 
const std::string & directory (int n) const
 Returns the number of directories in the directory list.
 
const std::string & operator[] (int n) const
 
PathpushDirectory (const std::string &dir)
 
PathpopDirectory ()
 Adds a directory to the directory list.
 
PathpopFrontDirectory ()
 Removes the last directory from the directory list.
 
PathsetFileName (const std::string &name)
 Removes the first directory from the directory list.
 
const std::string & getFileName () const
 Sets the filename.
 
PathsetBaseName (const std::string &name)
 Returns the filename.
 
std::string getBaseName () const
 
PathsetExtension (const std::string &extension)
 
std::string getExtension () const
 Sets the filename extension.
 
const std::string & version () const
 Returns the filename extension.
 
Pathclear ()
 Returns the file version. VMS only.
 
Path parent () const
 Clears all components.
 
Path absolute () const
 
Path absolute (const Path &base) const
 

Static Public Member Functions

static Path forDirectory (const std::string &path)
 
static Path forDirectory (const std::string &path, Style style)
 Creates a path referring to a directory.
 
static char separator ()
 Creates a path referring to a directory.
 
static char pathSeparator ()
 
static std::string current ()
 
static std::string home ()
 Returns the current working directory.
 
static std::string configHome ()
 Returns the user's home directory.
 
static std::string dataHome ()
 
static std::string tempHome ()
 
static std::string cacheHome ()
 
static std::string temp ()
 
static std::string config ()
 Returns the temporary directory.
 
static std::string null ()
 
static std::string expand (const std::string &path)
 Returns the name of the null device.
 
static void listRoots (std::vector< std::string > &roots)
 
static bool find (StringVec::const_iterator it, StringVec::const_iterator end, const std::string &name, Path &path)
 
static bool find (const std::string &pathList, const std::string &name, Path &path)
 
static std::string transcode (const std::string &path)
 

Protected Member Functions

void parseUnix (const std::string &path)
 
void parseWindows (const std::string &path)
 
void parseVMS (const std::string &path)
 
void parseGuess (const std::string &path)
 
std::string buildUnix () const
 
std::string buildWindows () const
 
std::string buildVMS () const
 

Private Attributes

std::string _node
 
std::string _device
 
std::string _name
 
std::string _version
 
StringVec _dirs
 
bool _absolute
 

Detailed Description

This class represents filesystem paths in a platform-independent manner. Unix, Windows and OpenVMS all use a different syntax for filesystem paths. This class can work with all three formats. A path is made up of an optional node name (only Windows and OpenVMS), an optional device name (also only Windows and OpenVMS), a list of directory names and an optional filename.

Definition at line 28 of file Path.h.

Member Typedef Documentation

◆ StringVec

typedef std::vector<std::string> Poco::Path::StringVec

Definition at line 51 of file Path.h.

Member Enumeration Documentation

◆ Style

Enumerator
PATH_UNIX 
PATH_URI 

Unix-style path.

PATH_WINDOWS 

URI-style path, same as Unix-style.

PATH_VMS 

Windows-style path.

PATH_NATIVE 

VMS-style path.

PATH_GUESS 

The current platform's native style.

Guess the style by examining the path

Definition at line 41 of file Path.h.

Constructor & Destructor Documentation

◆ Path() [1/11]

Poco::Path::Path ( )

◆ Path() [2/11]

Poco::Path::Path ( bool absolute)

Creates an empty relative path.

◆ Path() [3/11]

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

Creates an empty absolute or relative path.

◆ Path() [4/11]

Poco::Path::Path ( const char * path,
Style style )

Creates a path from a string.

◆ Path() [5/11]

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

Creates a path from a string.

◆ Path() [6/11]

Poco::Path::Path ( const std::string & path,
Style style )

Creates a path from a string.

◆ Path() [7/11]

Poco::Path::Path ( const Path & path)

Creates a path from a string.

◆ Path() [8/11]

Poco::Path::Path ( Path && path)
noexcept

Copy constructor.

◆ Path() [9/11]

Poco::Path::Path ( const Path & parent,
const std::string & fileName )

Move constructor.

◆ Path() [10/11]

Poco::Path::Path ( const Path & parent,
const char * fileName )

Creates a path from a parent path and a filename. The parent path is expected to reference a directory.

◆ Path() [11/11]

Poco::Path::Path ( const Path & parent,
const Path & relative )

Creates a path from a parent path and a filename. The parent path is expected to reference a directory.

◆ ~Path()

Poco::Path::~Path ( )

Creates a path from a parent path and a relative path. The parent path is expected to reference a directory. The relative path is appended to the parent path.

Member Function Documentation

◆ absolute() [1/2]

Path Poco::Path::absolute ( ) const

Returns a path referring to the path's directory.

◆ absolute() [2/2]

Path Poco::Path::absolute ( const Path & base) const

Returns an absolute variant of the path, taking the current working directory as base.

◆ append()

Path & Poco::Path::append ( const Path & path)

Makes the path absolute if it is relative. The given path is taken as base.

◆ assign() [1/4]

Path & Poco::Path::assign ( const char * path)

Assigns the given path.

◆ assign() [2/4]

Path & Poco::Path::assign ( const Path & path)

Assigns a string containing a path.

◆ assign() [3/4]

Path & Poco::Path::assign ( const std::string & path)

Swaps the path with another one.

+ Here is the caller graph for this function:

◆ assign() [4/4]

Path & Poco::Path::assign ( const std::string & path,
Style style )

Assigns a string containing a path in native format.

+ Here is the caller graph for this function:

◆ buildUnix()

std::string Poco::Path::buildUnix ( ) const
protected

◆ buildVMS()

std::string Poco::Path::buildVMS ( ) const
protected

◆ buildWindows()

std::string Poco::Path::buildWindows ( ) const
protected

◆ cacheHome()

static std::string Poco::Path::cacheHome ( )
static

Returns the user's temp directory.

On Unix systems, this is the '~/.local/temp/'.

◆ clear()

Path & Poco::Path::clear ( )

Returns the file version. VMS only.

◆ config()

static std::string Poco::Path::config ( )
static

Returns the temporary directory.

◆ configHome()

static std::string Poco::Path::configHome ( )
static

Returns the user's home directory.

◆ current()

static std::string Poco::Path::current ( )
static

Returns the platform's path separator, which separates single paths in a list of paths.

On Unix systems, this is the colon ':'. On Windows systems, this is the semicolon ';'. On OpenVMS systems, this is the comma ','.

◆ dataHome()

static std::string Poco::Path::dataHome ( )
static

Returns the user's config directory.

On Unix systems, this is the '~/.config/'. On Windows systems, this is 'APPDATA'.

◆ depth()

int Poco::Path::depth ( ) const
inline

Returns the device name.

Definition at line 448 of file Path.h.

◆ directory()

const std::string & Poco::Path::directory ( int n) const

Returns the number of directories in the directory list.

◆ expand()

static std::string Poco::Path::expand ( const std::string & path)
static

Returns the name of the null device.

◆ find() [1/2]

static bool Poco::Path::find ( const std::string & pathList,
const std::string & name,
Path & path )
static

Searches the file with the given name in the locations (paths) specified by it and end. A relative path may be given in name.

If the file is found in one of the locations, the complete path of the file is stored in the path given as argument and true is returned. Otherwise false is returned and the path argument remains unchanged.

◆ find() [2/2]

static bool Poco::Path::find ( StringVec::const_iterator it,
StringVec::const_iterator end,
const std::string & name,
Path & path )
static

Fills the vector with all filesystem roots available on the system. On Unix, there is exactly one root, "/". On Windows, the roots are the drive letters. On OpenVMS, the roots are the mounted disks.

◆ forDirectory() [1/2]

Path Poco::Path::forDirectory ( const std::string & path)
inlinestatic

Returns an absolute variant of the path, taking the given path as base.

Definition at line 460 of file Path.h.

+ Here is the call graph for this function:

◆ forDirectory() [2/2]

Path Poco::Path::forDirectory ( const std::string & path,
Style style )
inlinestatic

Creates a path referring to a directory.

Definition at line 467 of file Path.h.

+ Here is the call graph for this function:

◆ getBaseName()

std::string Poco::Path::getBaseName ( ) const

Sets the basename part of the filename and does not change the extension.

◆ getDevice()

const std::string & Poco::Path::getDevice ( ) const
inline

Sets the device name. Setting a non-empty device automatically makes the path an absolute one.

Definition at line 436 of file Path.h.

◆ getExtension()

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

Sets the filename extension.

◆ getFileName()

const std::string & Poco::Path::getFileName ( ) const
inline

Sets the filename.

Definition at line 442 of file Path.h.

◆ getNode()

const std::string & Poco::Path::getNode ( ) const
inline

Sets the node name. Setting a non-empty node automatically makes the path an absolute one.

Definition at line 430 of file Path.h.

◆ home()

static std::string Poco::Path::home ( )
static

Returns the current working directory.

◆ isAbsolute()

bool Poco::Path::isAbsolute ( ) const
inline

Resolves the given path against the current one.

If the given path is absolute, it replaces the current one. Otherwise, the relative path is appended to the current path.

Definition at line 394 of file Path.h.

◆ isDirectory()

bool Poco::Path::isDirectory ( ) const
inline

Returns true iff the path is relative.

Definition at line 406 of file Path.h.

◆ isFile()

bool Poco::Path::isFile ( ) const
inline

Returns true iff the path references a directory (the filename part is empty).

Definition at line 412 of file Path.h.

◆ isRelative()

bool Poco::Path::isRelative ( ) const
inline

Returns true iff the path is absolute.

Definition at line 400 of file Path.h.

◆ listRoots()

static void Poco::Path::listRoots ( std::vector< std::string > & roots)
static

Expands all environment variables contained in the path.

On Unix, a tilde as first character in the path is replaced with the path to user's home directory.

◆ makeAbsolute() [1/2]

Path & Poco::Path::makeAbsolute ( )

Makes the path refer to its parent.

◆ makeAbsolute() [2/2]

Path & Poco::Path::makeAbsolute ( const Path & base)

Makes the path absolute if it is relative. The current working directory is taken as base directory.

◆ makeDirectory()

Path & Poco::Path::makeDirectory ( )

The resulting path always refers to a directory and the filename part is empty.

◆ makeFile()

Path & Poco::Path::makeFile ( )

If the path contains a filename, the filename is appended to the directory list and cleared. Thus the resulting path always refers to a directory.

◆ makeParent()

Path & Poco::Path::makeParent ( )

If the path contains no filename, the last directory becomes the filename.

◆ null()

static std::string Poco::Path::null ( )
static

Returns the systemwide config directory.

On Unix systems, this is the '/etc/'.

◆ operator=() [1/4]

Path & Poco::Path::operator= ( const char * path)

Assigns a string containing a path in native format.

◆ operator=() [2/4]

Path & Poco::Path::operator= ( const Path & path)

Destroys the Path.

◆ operator=() [3/4]

Path & Poco::Path::operator= ( const std::string & path)

Move assignment.

◆ operator=() [4/4]

Path & Poco::Path::operator= ( Path && path)
noexcept

Assignment operator.

◆ operator[]()

const std::string & Poco::Path::operator[] ( int n) const

Returns the n'th directory in the directory list. If n == depth(), returns the filename.

◆ parent()

Path Poco::Path::parent ( ) const

Clears all components.

◆ parse() [1/2]

Path & Poco::Path::parse ( const std::string & path)
inline

Returns a string containing the path in the given format.

Definition at line 418 of file Path.h.

+ Here is the call graph for this function:

◆ parse() [2/2]

Path & Poco::Path::parse ( const std::string & path,
Style style )
inline

Same as assign().

Definition at line 424 of file Path.h.

+ Here is the call graph for this function:

◆ parseDirectory() [1/2]

Path & Poco::Path::parseDirectory ( const std::string & path)

Tries to interpret the given string as a path, according to the given style. If the path is syntactically valid, assigns the path and returns true. Otherwise leaves the object unchanged and returns false.

+ Here is the caller graph for this function:

◆ parseDirectory() [2/2]

Path & Poco::Path::parseDirectory ( const std::string & path,
Style style )

The resulting path always refers to a directory and the filename part is empty.

+ Here is the caller graph for this function:

◆ parseGuess()

void Poco::Path::parseGuess ( const std::string & path)
protected

◆ parseUnix()

void Poco::Path::parseUnix ( const std::string & path)
protected

On Windows, this function converts a string (usually containing a path) encoded in UTF-8 into a string encoded in the current Windows code page.

This function should be used for every string passed as a file name to a string stream or fopen().

On all other platforms, or if POCO has not been compiled with Windows UTF-8 support, this function returns the string unchanged.

◆ parseVMS()

void Poco::Path::parseVMS ( const std::string & path)
protected

◆ parseWindows()

void Poco::Path::parseWindows ( const std::string & path)
protected

◆ pathSeparator()

char Poco::Path::pathSeparator ( )
inlinestatic

Returns the platform's path name separator, which separates the components (names) in a path.

On Unix systems, this is the slash '/'. On Windows systems, this is the backslash '\'. On OpenVMS systems, this is the period '.'.

Definition at line 486 of file Path.h.

◆ popDirectory()

Path & Poco::Path::popDirectory ( )

Adds a directory to the directory list.

◆ popFrontDirectory()

Path & Poco::Path::popFrontDirectory ( )

Removes the last directory from the directory list.

◆ pushDirectory()

Path & Poco::Path::pushDirectory ( const std::string & dir)

Returns the n'th directory in the directory list. If n == depth(), returns the filename.

◆ resolve()

Path & Poco::Path::resolve ( const Path & path)

Appends the given path.

◆ separator()

char Poco::Path::separator ( )
inlinestatic

Creates a path referring to a directory.

Definition at line 474 of file Path.h.

◆ setBaseName()

Path & Poco::Path::setBaseName ( const std::string & name)

Returns the filename.

◆ setDevice()

Path & Poco::Path::setDevice ( const std::string & device)

Returns the node name.

◆ setExtension()

Path & Poco::Path::setExtension ( const std::string & extension)

Returns the basename (the filename sans extension) of the path.

◆ setFileName()

Path & Poco::Path::setFileName ( const std::string & name)

Removes the first directory from the directory list.

◆ setNode()

Path & Poco::Path::setNode ( const std::string & node)

Returns true iff the path references a file (the filename part is not empty).

◆ swap()

void Poco::Path::swap ( Path & path)

Assigns a string containing a path in native format.

+ Here is the caller graph for this function:

◆ temp()

static std::string Poco::Path::temp ( )
static

Returns the user's cache directory.

On Unix systems, this is the '~/.cache/'. On Windows systems, this is 'APPDATA'.

◆ tempHome()

static std::string Poco::Path::tempHome ( )
static

Returns the user's data directory.

On Unix systems, this is the '~/.local/share/'. On Windows systems, this is 'APPDATA'.

◆ toString() [1/2]

std::string Poco::Path::toString ( ) const

Assigns a string containing a path.

◆ toString() [2/2]

std::string Poco::Path::toString ( Style style) const

Returns a string containing the path in native format.

◆ transcode()

static std::string Poco::Path::transcode ( const std::string & path)
static

Searches the file with the given name in the locations (paths) specified in pathList. The paths in pathList must be delimited by the platform's path separator (see pathSeparator()). A relative path may be given in name.

If the file is found in one of the locations, the complete path of the file is stored in the path given as argument and true is returned. Otherwise false is returned and the path argument remains unchanged.

◆ tryParse() [1/2]

bool Poco::Path::tryParse ( const std::string & path)

Assigns a string containing a path.

◆ tryParse() [2/2]

bool Poco::Path::tryParse ( const std::string & path,
Style style )

Tries to interpret the given string as a path in native format. If the path is syntactically valid, assigns the path and returns true. Otherwise leaves the object unchanged and returns false.

◆ version()

const std::string & Poco::Path::version ( ) const
inline

Returns the filename extension.

Definition at line 454 of file Path.h.

Member Data Documentation

◆ _absolute

bool Poco::Path::_absolute
private

Definition at line 387 of file Path.h.

◆ _device

std::string Poco::Path::_device
private

Definition at line 383 of file Path.h.

◆ _dirs

StringVec Poco::Path::_dirs
private

Definition at line 386 of file Path.h.

◆ _name

std::string Poco::Path::_name
private

Definition at line 384 of file Path.h.

◆ _node

std::string Poco::Path::_node
private

Definition at line 382 of file Path.h.

◆ _version

std::string Poco::Path::_version
private

Definition at line 385 of file Path.h.


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