DCMTK  Version 3.6.7
OFFIS DICOM Toolkit
Public Types | Public Member Functions | Static Public Attributes | Related Definitions | List of all members
OFpath Class Reference

A class representing paths on a filesystem. More...

Public Types

enum  format { native_format , generic_format , auto_format }
 Determines how string representations of pathnames are interpreted by the constructors of OFpath. More...
 

Public Member Functions

 OFpath ()
 Construct an empty path. More...
 
 OFpath (const OFpath &rhs)
 Copy construct a path. More...
 
 OFpath (OFrvalue_ref(OFpath) rhs)
 Move construct a path. More...
 
 OFpath (const char *const cstr, format fmt=auto_format)
 Construct an OFpath from a const char*. More...
 
 OFpath (const OFString &string, format fmt=auto_format)
 Constructs an OFpath from an OFString. More...
 
OFpathoperator= (const OFpath &rhs)
 Copy-assign another OFpath to this one. More...
 
OFpathoperator= (OFrvalue_ref(OFpath) rhs)
 Move-assign another OFpath to this one. More...
 
OFBool empty () const
 Test whether the path is empty. More...
 
OFBool is_absolute () const
 Test whether the path is absolute, i.e. refers to a certain location unaffected by which directory is set as the current working directory. More...
 
OFBool is_relative () const
 Test whether the path is relative, e.g. needs to be concatenated to another path before it refers to a filesystem location. More...
 
OFBool has_root_name () const
 Test whether the path contains a root name. More...
 
OFBool has_root_directory () const
 Test whether the path contains a root directory. More...
 
OFBool has_filename () const
 Test whether the path contains a filename. More...
 
OFBool has_extension () const
 Test whether the path contains a filename extension. More...
 
const OFStringnative () const
 Retrieve the underlying native string. More...
 
const char * c_str () const
 Retrieve a native character pointer. More...
 
OFrvalue< OFpathroot_name () const
 Return the root name contained in the path (if any) or an empty path. More...
 
OFrvalue< OFpathfilename () const
 Return the filename contained in the path (if any) or an empty path. More...
 
OFrvalue< OFpathextension () const
 Return the filename extension contained in the path (if any) or an empty path. More...
 
OFpathoperator/= (const OFpath &rhs)
 Append another path to this one, handling various special cases. More...
 

Static Public Attributes

static const char preferred_separator = PATH_SEPARATOR
 The path separator used in the native path syntax, i.e. '\' on Windows and '/' everywhere else.
 

Related Definitions

Global types, methods and objects that are somehow related

OFrvalue< OFpathoperator/ (const OFpath &lhs, const OFpath &rhs)
 Append two paths. More...
 
STD_NAMESPACE ostream & operator<< (STD_NAMESPACE ostream &out, const OFpath &rhs)
 Print a path to an output stream. More...
 
OFBool operator< (const OFpath &lhs, const OFpath &rhs)
 Lexicographically compare two paths. More...
 
OFBool operator> (const OFpath &lhs, const OFpath &rhs)
 Lexicographically compare two paths. More...
 
OFBool operator<= (const OFpath &lhs, const OFpath &rhs)
 Lexicographically compare two paths. More...
 
OFBool operator>= (const OFpath &lhs, const OFpath &rhs)
 Lexicographically compare two paths. More...
 
OFBool operator== (const OFpath &lhs, const OFpath &rhs)
 Lexicographically compare two paths. More...
 
OFBool operator!= (const OFpath &lhs, const OFpath &rhs)
 Lexicographically compare two paths. More...
 

Detailed Description

A class representing paths on a filesystem.

OFpath implements a subset of the functionality described as std::filesystem::path, see http://en.cppreference.com/w/cpp/filesystem/path for more information.

Warning
One major difference of the current OFpath implementation and the real std::filesystem::path is that std::filesystem::path native string type is expected to be std::wstring on Windows, whereas OFpath currently always uses OFString, since something like OFWString does currently not exist. This will be addressed before making OFpath interchangeable with std::filesystem::path.

Member Enumeration Documentation

◆ format

Determines how string representations of pathnames are interpreted by the constructors of OFpath.

Note
Since native_format and generic_format are the same on Unix like systems, using auto_format will have no effect on them, i.e. the path is expected to use slash ('/') as the separator on Unix like systems.
Enumerator
native_format 

Native pathname format.

generic_format 

Generic pathname format.

auto_format 

Implementation-defined pathname format, auto-detected where possible.

Constructor & Destructor Documentation

◆ OFpath() [1/5]

OFpath::OFpath ( )

Construct an empty path.

An empty path refers to the same location as the path "." on most systems.

◆ OFpath() [2/5]

OFpath::OFpath ( const OFpath rhs)

Copy construct a path.

Parameters
rhsanother OFpath object that this one will be constructed from.

◆ OFpath() [3/5]

OFpath::OFpath ( OFrvalue_ref(OFpath rhs)

Move construct a path.

Parameters
rhsanother OFpath object that this one will be constructed from.
Remarks
The current implementation constructs an empty path and swaps it with the one provided as rhs in constant time.

◆ OFpath() [4/5]

OFpath::OFpath ( const char *const  cstr,
format  fmt = auto_format 
)

Construct an OFpath from a const char*.

Parameters
cstra plain old C character string.
fmtspecifies how cstr is to be interpreted, e.g. what character to expect as the separator or whether to auto detect it.
Warning
This constructor does not exists in the real std::filesystem::path, where various character strings (e.g. char* and wchar_t*) are handled uniformly by one of the template constructors.

◆ OFpath() [5/5]

OFpath::OFpath ( const OFString string,
format  fmt = auto_format 
)

Constructs an OFpath from an OFString.

Parameters
stringan OFString.
fmtspecifies how the string is to be interpreted, e.g. what character to expect as the separator or whether to auto detect it.

Member Function Documentation

◆ c_str()

const char* OFpath::c_str ( ) const

Retrieve a native character pointer.

Returns
effectively: native().c_str().

◆ empty()

OFBool OFpath::empty ( ) const

Test whether the path is empty.

Returns
effectively: native().empty().

◆ extension()

OFrvalue<OFpath> OFpath::extension ( ) const

Return the filename extension contained in the path (if any) or an empty path.

The filename extension is the part of the filename beginning at (and containing) the last '.', e.g. ".txt" for a file named "readme.txt". Special filenames like ".", ".." and hidden files like ".hidden" will be handled in a special way. The names ".", ".." and ".hidden" will give an empty string result, whereas ".hidden.txt" will give ".txt".

Returns
an OFpath containing only the extension part of the filename.

◆ filename()

OFrvalue<OFpath> OFpath::filename ( ) const

Return the filename contained in the path (if any) or an empty path.

The filename is the substring after the last path separator, and, for multi root filesystems also after the root name.

Returns
an OFpath containing only the filename, e.g. "file" given a "/path/to/file" or resp. "C:\path\to\file".
Note
OFpath( "C:" ).filename() is "" on Windows and "C:" everywhere else.

◆ has_extension()

OFBool OFpath::has_extension ( ) const

Test whether the path contains a filename extension.

Returns
effectively: !extension().empty().

◆ has_filename()

OFBool OFpath::has_filename ( ) const

Test whether the path contains a filename.

Returns
effectively: !filename().empty().

◆ has_root_directory()

OFBool OFpath::has_root_directory ( ) const

Test whether the path contains a root directory.

Returns
effectively: !root_directory().empty().

◆ has_root_name()

OFBool OFpath::has_root_name ( ) const

Test whether the path contains a root name.

Returns
effectively: !root_name().empty().

◆ is_absolute()

OFBool OFpath::is_absolute ( ) const

Test whether the path is absolute, i.e. refers to a certain location unaffected by which directory is set as the current working directory.

Returns
OFTrue if the path is absolute, OFFalse otherwise.

◆ is_relative()

OFBool OFpath::is_relative ( ) const

Test whether the path is relative, e.g. needs to be concatenated to another path before it refers to a filesystem location.

Returns
effectively: !is_absolute().

◆ native()

const OFString& OFpath::native ( ) const

Retrieve the underlying native string.

Returns
a const reference to the underlying OFString.

Referenced by operator!=(), operator<(), operator<<(), operator<=(), operator==(), operator>(), and operator>=().

◆ operator/=()

OFpath& OFpath::operator/= ( const OFpath rhs)

Append another path to this one, handling various special cases.

Parameters
rhsanother OFpath object to append to this one.
Returns
*this

This operator will append another path to the existing one, always doing the right thing. There are many special cases it accounts for, for details see (http://en.cppreference.com/w/cpp/filesystem/path/append) In short: you can trust it to turn "path" / "file" into "path\file" on Windows and "path/file" everywhere else, while also ensuring "path/" / "file" will become "path/file" and not "path//file" and many more.

◆ operator=() [1/2]

OFpath& OFpath::operator= ( const OFpath rhs)

Copy-assign another OFpath to this one.

Effectively: this->native() = rhs.native().

Parameters
rhsanother OFpath object.
Returns
*this

◆ operator=() [2/2]

OFpath& OFpath::operator= ( OFrvalue_ref(OFpath rhs)

Move-assign another OFpath to this one.

Parameters
rhsanother OFpath object.
Returns
*this
Remarks
The current implementation clears the path and then swaps it with the one provided as rhs in constant time.

◆ root_name()

OFrvalue<OFpath> OFpath::root_name ( ) const

Return the root name contained in the path (if any) or an empty path.

The root name is a concept used in multi root filesystems (Windows) to identify the root (e.g. C:).

Returns
an OFpath containing only the root name, e.g given the path "C:\" it will return "C:" on Windows and "" everywhere else.

Related Definitions

◆ operator!=()

OFBool operator!= ( const OFpath lhs,
const OFpath rhs 
)
related

Lexicographically compare two paths.

Parameters
lhsthe left hand side path for the operation.
rhsthe right hand side path for the operation.
Returns
effectively: lhs.native() != rhs.native()
Note
the comparison is purely lexicographic, i.e. the paths will not be normalized in any way prior to comparing their native strings.

References native().

◆ operator/()

OFrvalue< OFpath > operator/ ( const OFpath lhs,
const OFpath rhs 
)
related

Append two paths.

Parameters
lhsthe left hand side path for the operation.
rhsthe right hand side path for the operation.
Returns
effectively: OFpath( lhs ) / rhs.

◆ operator<()

OFBool operator< ( const OFpath lhs,
const OFpath rhs 
)
related

Lexicographically compare two paths.

Parameters
lhsthe left hand side path for the operation.
rhsthe right hand side path for the operation.
Returns
effectively: lhs.native() < rhs.native()
Note
the comparison is purely lexicographic, i.e. the paths will not be normalized in any way prior to comparing their native strings.

References native().

◆ operator<<()

STD_NAMESPACE ostream & operator<< ( STD_NAMESPACE ostream &  out,
const OFpath rhs 
)
related

Print a path to an output stream.

The parameters and return value are as usual for the output stream operator, the only thing worth mentioning is that the path will be put into double quotes, i.e. it will print "rhs.native()".

Parameters
outthe stream.
rhsthe path
Returns
out

References native().

◆ operator<=()

OFBool operator<= ( const OFpath lhs,
const OFpath rhs 
)
related

Lexicographically compare two paths.

Parameters
lhsthe left hand side path for the operation.
rhsthe right hand side path for the operation.
Returns
effectively: lhs.native() <= rhs.native()
Note
the comparison is purely lexicographic, i.e. the paths will not be normalized in any way prior to comparing their native strings.

References native().

◆ operator==()

OFBool operator== ( const OFpath lhs,
const OFpath rhs 
)
related

Lexicographically compare two paths.

Parameters
lhsthe left hand side path for the operation.
rhsthe right hand side path for the operation.
Returns
effectively: lhs.native() == rhs.native()
Note
the comparison is purely lexicographic, i.e. the paths will not be normalized in any way prior to comparing their native strings.

References native().

◆ operator>()

OFBool operator> ( const OFpath lhs,
const OFpath rhs 
)
related

Lexicographically compare two paths.

Parameters
lhsthe left hand side path for the operation.
rhsthe right hand side path for the operation.
Returns
effectively: lhs.native() > rhs.native()
Note
the comparison is purely lexicographic, i.e. the paths will not be normalized in any way prior to comparing their native strings.

References native().

◆ operator>=()

OFBool operator>= ( const OFpath lhs,
const OFpath rhs 
)
related

Lexicographically compare two paths.

Parameters
lhsthe left hand side path for the operation.
rhsthe right hand side path for the operation.
Returns
effectively: lhs.native() >= rhs.native()
Note
the comparison is purely lexicographic, i.e. the paths will not be normalized in any way prior to comparing their native strings.

References native().


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


Generated on Thu Apr 28 2022 for DCMTK Version 3.6.7 by Doxygen 1.9.1