libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | List of all members
crn::Path Class Reference

A convenience class for file paths. More...

#include <CRNPath.h>

+ Inheritance diagram for crn::Path:
+ Collaboration diagram for crn::Path:

Public Types

enum  Format {
  Format::AUTO = 0, Format::URI = 1, Format::UNIX = 2, Format::WINDOWS = 3,
  Format::LOCAL = 2
}
 

Public Member Functions

 Path (Format fmt=Format::LOCAL)
 Default constructor (empty string) More...
 
 Path (const std::string &s, Format fmt=Format::LOCAL)
 Constructor from a std string. More...
 
 Path (std::string &s, Format fmt=Format::LOCAL)
 Constructor from a std string. More...
 
 Path (char *s, Format fmt=Format::LOCAL)
 Constructor from a cstring. More...
 
 Path (const char *s, Format fmt=Format::LOCAL)
 Constructor from a cstring. More...
 
 Path (const Path &s, Format fmt=Format::AUTO)
 Copy constructor. More...
 
 Path (Path &&)=default
 
 Path (const StringUTF8 &s, Format fmt=Format::LOCAL)
 Constructor from a UTF8 string. More...
 
 Path (const String &s, Format fmt=Format::LOCAL)
 Constructor from a UTF32 string. More...
 
 Path (char c, size_t n=1, Format fmt=Format::LOCAL)
 Constructor from a char. More...
 
 Path (int i, Format fmt=Format::LOCAL)
 Constructor from an int. More...
 
 Path (xml::Element &el)
 Constructor from an xml element. More...
 
virtual ~Path () override=default
 
Pathoperator= (const Path &)=default
 
Pathoperator= (Path &&)=default
 
std::vector< PathSplit (const StringUTF8 &sep) const
 Splits the string in multiple strings delimited by a set of separators. More...
 
Format GetFormat () const
 Returns the format. More...
 
bool IsURI () const
 Is the path a URI? More...
 
bool IsUnix () const
 Is the path in Unix format? More...
 
bool IsWindows () const
 Is the path in Windows format? More...
 
PathConvertTo (Format fmt)
 Converts to a specific format. More...
 
const Pathoperator+= (const Path &s)
 Appends a string. More...
 
const Pathoperator/= (const Path &s)
 Appends a string after adding directory separator if needed. More...
 
bool IsAbsolute () const
 Is the path absolute? More...
 
bool IsRelative () const
 Is the path relative? More...
 
Path GetFilename () const
 Returns the filename. More...
 
Path GetBase () const
 Returns the base of the filename. More...
 
Path GetExtension () const
 Returns the extension. More...
 
Path GetDirectory () const
 Returns the full directory path. More...
 
void Swap (Path &str) noexcept
 Swaps two strings. More...
 
StringUTF8 GetScheme () const
 Returns the scheme of the URI. More...
 
PathToURI ()
 Converts the path to URI. More...
 
PathDecode ()
 Replaces % codes with the corresponding character. More...
 
PathToUnix ()
 Converts the path to Unix format. More...
 
char GetDrive () const
 Gets the drive letter. More...
 
PathToWindows ()
 Converts the path to Windows format. More...
 
PathToLocal ()
 Converts the path to the local format. More...
 
virtual void Deserialize (xml::Element &el) override
 Initializes the object from an XML element. More...
 
virtual xml::Element Serialize (xml::Element &parent) const override
 Dumps the object to an XML element. More...
 
- Public Member Functions inherited from crn::StringUTF8
 StringUTF8 ()=default
 Default constructor (empty string) More...
 
virtual ~StringUTF8 () override=default
 
 StringUTF8 (const std::string &s)
 Constructor from a std string. More...
 
 StringUTF8 (std::string &&s) noexcept
 Constructor from a std string. More...
 
 StringUTF8 (char *s)
 Constructor from a cstring. More...
 
 StringUTF8 (const char *s)
 Constructor from a cstring. More...
 
 StringUTF8 (const StringUTF8 &s)
 Copy constructor. More...
 
 StringUTF8 (const String &s)
 Constructor from a UTF32 string. More...
 
 StringUTF8 (const Prop3 &p)
 Constructor from a Prop3. More...
 
 StringUTF8 (char c, size_t n=1)
 Constructor from a char. More...
 
 StringUTF8 (int i)
 Constructor from an int. More...
 
 StringUTF8 (unsigned int i)
 Constructor from an unsigned int. More...
 
 StringUTF8 (long i)
 Constructor from a long. More...
 
 StringUTF8 (unsigned long i)
 Constructor from an unsigned long. More...
 
 StringUTF8 (float f)
 Constructor from a float. More...
 
 StringUTF8 (double d)
 Constructor from a double. More...
 
 StringUTF8 (long double d)
 Constructor from a long double. More...
 
 StringUTF8 (long long i)
 Constructor from an long. More...
 
 StringUTF8 (unsigned long long i)
 Constructor from an unsigned long. More...
 
template<typename T >
 StringUTF8 (const std::complex< T > &c)
 Constructor from a complex. More...
 
 StringUTF8 (StringUTF8 &&)=default
 
StringUTF8operator= (StringUTF8 &&)=default
 
std::string & Std ()&noexcept
 Conversion to std string. More...
 
const std::string & Std () const &noexcept
 Conversion to std string. More...
 
std::string Std ()&&
 Conversion to std string. More...
 
const char * CStr () const noexcept
 Conversion to UTF8 cstring. More...
 
Prop3 ToProp3 () const
 Conversion to Prop3. More...
 
int ToInt () const
 Conversion to int. More...
 
unsigned int ToUInt () const
 Conversion to unsigned int. More...
 
long ToLong () const
 Conversion to long. More...
 
unsigned long ToULong () const
 Conversion to unsigned long. More...
 
float ToFloat () const
 Conversion to float. More...
 
double ToDouble () const
 Conversion to double. More...
 
long double ToLongDouble () const
 Conversion to long double. More...
 
long long ToLongLong () const
 Conversion to long long. More...
 
unsigned long long ToULongLong () const
 Conversion to unsigned long long. More...
 
int64_t ToInt64 () const
 Conversion to int64_t. More...
 
uint64_t ToUInt64 () const
 Conversion to uint64_t. More...
 
size_t Size () const noexcept
 Returns the number of bytes in the string. More...
 
size_t Length () const noexcept
 Returns the number of characters the string. More...
 
bool operator! () const noexcept
 Checks if the string is empty. More...
 
bool IsEmpty () const noexcept
 Checks if the string is empty. More...
 
bool IsNotEmpty () const noexcept
 Checks if the string is not empty. More...
 
char & operator[] (size_t index)
 Access to a character. More...
 
const char & operator[] (size_t index) const
 Access to a character. More...
 
StringUTF8operator= (const StringUTF8 &s)
 Copies from another string. More...
 
StringUTF8operator+= (const StringUTF8 &s)
 Appends a string. More...
 
StringUTF8Insert (size_t pos, const StringUTF8 &s)
 Inserts a string. More...
 
StringUTF8Crop (size_t pos, size_t n=0)
 Crops the string. More...
 
StringUTF8Erase (size_t pos, size_t n=0)
 Erases a part of the string. More...
 
StringUTF8Replace (const StringUTF8 &s, size_t pos, size_t n=0)
 Replaces a part of the string. More...
 
StringUTF8Replace (char from, char to)
 Replaces all occurrences of a character with another. More...
 
StringUTF8ToUpper ()
 Converts the string to uppercase. More...
 
StringUTF8FirstCharacterToUpper ()
 Converts the first character of string to uppercase. More...
 
StringUTF8ToLower ()
 Converts the string to lowercase. More...
 
StringUTF8 SubString (size_t pos, size_t n=0) const
 Extracts a part of the string. More...
 
bool StartsWith (const StringUTF8 &s) const
 Check if string has a given prefix. More...
 
bool EndsWith (const StringUTF8 &s) const
 Check if string has a given suffix. More...
 
size_t Find (const StringUTF8 &s, size_t from_pos=0) const
 Finds the first occurrence of a string. More...
 
size_t FindAnyOf (const StringUTF8 &s, size_t from_pos=0) const
 Finds the first occurrence of character in a list. More...
 
size_t FindNotOf (const StringUTF8 &s, size_t from_pos=0) const
 Finds the first occurrence of character not in a list. More...
 
size_t BackwardFind (const StringUTF8 &s, size_t last_pos=NPos()) const
 Finds the last occurrence of a string. More...
 
size_t BackwardFindAnyOf (const StringUTF8 &s, size_t from_pos=NPos()) const
 Finds the last occurrence of character in a list. More...
 
size_t BackwardFindNotOf (const StringUTF8 &s, size_t from_pos=NPos()) const
 Finds the last occurrence of character not in a list. More...
 
StringUTF8ReplaceSuffix (const StringUTF8 &old_suffix, const StringUTF8 &new_suffix)
 Replaces suffix by another pattern if present. More...
 
std::vector< StringUTF8Split (const StringUTF8 &sep) const
 Splits the string in multiple strings delimited by a set of separators. More...
 
void ShrinkToFit ()
 Optimizes the memory usage. More...
 
void Swap (StringUTF8 &str) noexcept
 Swaps two strings. More...
 
- Public Member Functions inherited from crn::Object
virtual ~Object ()=default
 

Static Public Member Functions

static char Separator () noexcept
 Local directory separator. More...
 
static char NoDrive ()
 Invalid drive or no drive found. More...
 
- Static Public Member Functions inherited from crn::StringUTF8
static int & Precision () noexcept
 Precision of the floating point conversion. More...
 
static size_t NPos () noexcept
 Last position in a string. More...
 
static crn::StringUTF8 CreateUniqueId (size_t len=8)
 Generates an almost unique id. More...
 

Detailed Description

A convenience class for file paths.

A class to store a file or directory path

Date
Jul. 2010
Author
Yann LEYDIER
Version
0.1

Definition at line 39 of file CRNPath.h.

Member Enumeration Documentation

enum crn::Path::Format
strong
Enumerator
AUTO 
URI 
UNIX 
WINDOWS 
LOCAL 

Definition at line 42 of file CRNPath.h.

Constructor & Destructor Documentation

crn::Path::Path ( Format  fmt = Format::LOCAL)
inline

Default constructor (empty string)

Definition at line 56 of file CRNPath.h.

crn::Path::Path ( const std::string &  s,
Format  fmt = Format::LOCAL 
)
inline

Constructor from a std string.

Definition at line 58 of file CRNPath.h.

crn::Path::Path ( std::string &  s,
Format  fmt = Format::LOCAL 
)
inline

Constructor from a std string.

Definition at line 60 of file CRNPath.h.

crn::Path::Path ( char *  s,
Format  fmt = Format::LOCAL 
)
inline

Constructor from a cstring.

Definition at line 62 of file CRNPath.h.

crn::Path::Path ( const char *  s,
Format  fmt = Format::LOCAL 
)
inline

Constructor from a cstring.

Definition at line 64 of file CRNPath.h.

crn::Path::Path ( const Path s,
Format  fmt = Format::AUTO 
)
inline

Copy constructor.

Definition at line 66 of file CRNPath.h.

crn::Path::Path ( Path &&  )
default
crn::Path::Path ( const StringUTF8 s,
Format  fmt = Format::LOCAL 
)
inline

Constructor from a UTF8 string.

Definition at line 69 of file CRNPath.h.

crn::Path::Path ( const String s,
Format  fmt = Format::LOCAL 
)
inlineexplicit

Constructor from a UTF32 string.

Definition at line 71 of file CRNPath.h.

crn::Path::Path ( char  c,
size_t  n = 1,
Format  fmt = Format::LOCAL 
)
inline

Constructor from a char.

Definition at line 73 of file CRNPath.h.

crn::Path::Path ( int  i,
Format  fmt = Format::LOCAL 
)
inline

Constructor from an int.

Definition at line 75 of file CRNPath.h.

crn::Path::Path ( xml::Element el)
inline

Constructor from an xml element.

Definition at line 77 of file CRNPath.h.

virtual crn::Path::~Path ( )
overridevirtualdefault

Member Function Documentation

Path & Path::ConvertTo ( Path::Format  fmt)

Converts to a specific format.

Converts to a specific format

Parameters
[in]fmtthe destination format
Returns
the updated path

Definition at line 146 of file CRNPath.cpp.

Path & Path::Decode ( )

Replaces % codes with the corresponding character.

Replaces % codes with the corresponding character

Returns
a reference to the modified string

Definition at line 490 of file CRNPath.cpp.

void Path::Deserialize ( xml::Element el)
overridevirtual

Initializes the object from an XML element.

Initializes the object from an XML element. Unsafe.

Exceptions
ExceptionInvalidArgumentnot a StringUTF8
ExceptionDomainno CDATA found
Parameters
[in]elthe XML element to read

Reimplemented from crn::StringUTF8.

Definition at line 562 of file CRNPath.cpp.

Path Path::GetBase ( ) const

Returns the base of the filename.

Returns the base of the filename

Exceptions
ExceptionLogicpath does not contain a filename
Returns
the filename's base (i.e.: filename minus extension)

Definition at line 235 of file CRNPath.cpp.

Path Path::GetDirectory ( ) const

Returns the full directory path.

Returns the full directory path

Returns
the directory path

Definition at line 267 of file CRNPath.cpp.

char Path::GetDrive ( ) const

Gets the drive letter.

Gets the drive letter

Returns
the drive letter or NoDrive if not applicable

Definition at line 477 of file CRNPath.cpp.

Path Path::GetExtension ( ) const

Returns the extension.

Returns the extension

Exceptions
ExceptionLogicpath does not contain a filename
Returns
the filename's extension

Definition at line 252 of file CRNPath.cpp.

Path Path::GetFilename ( ) const

Returns the filename.

Returns the filename

Returns
the filename

Definition at line 205 of file CRNPath.cpp.

Path::Format Path::GetFormat ( ) const

Returns the format.

Returns the format

Returns
URI, WINDOWS or UNIX

Definition at line 105 of file CRNPath.cpp.

StringUTF8 Path::GetScheme ( ) const

Returns the scheme of the URI.

Returns the scheme of the URI

Returns
the scheme of the URI

Definition at line 303 of file CRNPath.cpp.

bool Path::IsAbsolute ( ) const

Is the path absolute?

Is the path absolute?

Returns
true if the path is absolute

Definition at line 173 of file CRNPath.cpp.

bool crn::Path::IsRelative ( ) const
inline

Is the path relative?

Definition at line 112 of file CRNPath.h.

bool Path::IsUnix ( ) const

Is the path in Unix format?

Is the path in Unix format?

Returns
true if the path is in Unix format

Definition at line 127 of file CRNPath.cpp.

bool Path::IsURI ( ) const

Is the path a URI?

Is the path a URI?

Returns
true if the path is a URI

Definition at line 119 of file CRNPath.cpp.

bool Path::IsWindows ( ) const

Is the path in Windows format?

Is the path in Windows format?

Returns
true if the path is in Windows format

Definition at line 135 of file CRNPath.cpp.

char Path::NoDrive ( )
static

Invalid drive or no drive found.

Invalid drive or no drive found

Returns
a character for an invalid drive (win32)

Definition at line 34 of file CRNPath.cpp.

const Path & Path::operator+= ( const Path s)

Appends a string.

Appends a path with conversion to the local format

Parameters
[in]sthe string to convert and append
Returns
the modified string

Definition at line 56 of file CRNPath.cpp.

const Path & Path::operator/= ( const Path s)

Appends a string after adding directory separator if needed.

Appends a string after adding directory separator if needed

Parameters
[in]sthe string to convert and append
Returns
the modified string

Definition at line 80 of file CRNPath.cpp.

Path& crn::Path::operator= ( const Path )
default
Path& crn::Path::operator= ( Path &&  )
default
char Path::Separator ( )
staticnoexcept

Local directory separator.

Local directory separator

Returns
the character used to separate directories on the host OS

Definition at line 42 of file CRNPath.cpp.

xml::Element Path::Serialize ( xml::Element parent) const
overridevirtual

Dumps the object to an XML element.

Dumps the object to an XML element. Unsafe.

Parameters
[in]parentthe parent element to which we will add the new element
Returns
The newly created element, nullptr if failed.

Reimplemented from crn::StringUTF8.

Definition at line 583 of file CRNPath.cpp.

std::vector< Path > Path::Split ( const StringUTF8 sep) const

Splits the string in multiple strings delimited by a set of separators.

Splits the string in multiple strings delimited by a set of separators

Parameters
[in]sepa list of separators
Returns
a list of substrings

Definition at line 545 of file CRNPath.cpp.

void crn::Path::Swap ( Path str)
inlinenoexcept

Swaps two strings.

Definition at line 126 of file CRNPath.h.

Path & Path::ToLocal ( )

Converts the path to the local format.

Definition at line 534 of file CRNPath.cpp.

Path & Path::ToUnix ( )

Converts the path to Unix format.

Converts the path to Unix format

Returns
a reference to the modified path

Definition at line 366 of file CRNPath.cpp.

Path & Path::ToURI ( )

Converts the path to URI.

Converts the path to URI

Returns
a reference to the modified path

Definition at line 315 of file CRNPath.cpp.

Path & Path::ToWindows ( )

Converts the path to Windows format.

Converts the path to Windows format

Returns
a reference to the modified path

Definition at line 410 of file CRNPath.cpp.


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