Difference between revisions of "CXFilePath"

From cxwiki

(Created page with "<div class="mw-parser-output">The CXFilePath class provides an platform-neutral file path representation. The file paths are encoded in UTF8 with forward slash ("/") separator...")
 
Line 1: Line 1:
<div class="mw-parser-output">The CXFilePath class provides an platform-neutral file path representation. The file paths are encoded in UTF8 with forward slash ("/") separators. A leading slash indicates an absolute path, otherwise the path is considered relative. The "/./" and "/../" constructs are supported for referring to the current directory and parent directory respectively.&nbsp;No other characters are reserved or prevented. CXFilePath objects are considered case sensitive, regardless of whether the underlying file system is or is not case sensitive.</div> <div class="mw-parser-output">&nbsp;</div> <div class="mw-parser-output">The underlying ''CXFilePathBase'' templated&nbsp;class allows selection of a string container. ''CXFilePath'' is implemented as&nbsp;''CXFilePathBase<CXString>''. As an alternative, the application can use&nbsp;''CXFilePathBase<CXStringEdit>'' instead of ''CXFilePath''&nbsp;if high-performance editing is required.</div> <div class="mw-parser-output">&nbsp;</div>  
+
<div class="mw-parser-output"><div class="mw-parser-output">The CXFilePath class provides an platform-neutral file path representation. The file paths are encoded in UTF8 with forward slash ("/") separators. A leading slash indicates an absolute path, otherwise the path is considered relative. The "/./" and "/../" constructs are supported for referring to the current directory and parent directory respectively.&nbsp;No other characters are reserved or prevented. CXFilePath objects are considered case sensitive, regardless of whether the underlying file system is or is not case sensitive.</div> <div class="mw-parser-output">&nbsp;</div> <div class="mw-parser-output">The underlying ''CXFilePathBase'' templated&nbsp;class allows selection of a string container. ''CXFilePath'' is implemented as&nbsp;''CXFilePathBase<CXString>''. As an alternative, the application can use&nbsp;''CXFilePathBase<CXStringEdit>'' instead of ''CXFilePath''&nbsp;if high-performance editing is required.</div> <div class="mw-parser-output">&nbsp;</div>  
 
= Native Encodings =
 
= Native Encodings =
 
<div class="mw-parser-output">Where the host platform differs from these details, transformation between CXFilePath encoding and the native encoding occurs at the lowest possible level. The application should never need to deal with native encoding except where it is directly accessing native functions (bypassing the cxsource framework).</div> <div class="mw-parser-output">&nbsp;</div>  
 
<div class="mw-parser-output">Where the host platform differs from these details, transformation between CXFilePath encoding and the native encoding occurs at the lowest possible level. The application should never need to deal with native encoding except where it is directly accessing native functions (bypassing the cxsource framework).</div> <div class="mw-parser-output">&nbsp;</div>  
Line 6: Line 6:
 
== Posix ==
 
== Posix ==
 
<div class="mw-parser-output">CXFilePath directly adopts posix filepath format&nbsp;and no significant transformations are required to convert between a posix file path and a CXFilePath. If the underlying APIs do not accept UTF-8 input, then a string codepage transformation&nbsp;may be required.</div> <div class="mw-parser-output">&nbsp;</div>  
 
<div class="mw-parser-output">CXFilePath directly adopts posix filepath format&nbsp;and no significant transformations are required to convert between a posix file path and a CXFilePath. If the underlying APIs do not accept UTF-8 input, then a string codepage transformation&nbsp;may be required.</div> <div class="mw-parser-output">&nbsp;</div>  
= Methods =
+
= Construction =
<div class="mw-parser-output">&nbsp;</div> <div class="mw-parser-output">&nbsp;</div> <div class="mw-parser-output">&nbsp;</div> <div class="mw-parser-output">&nbsp;</div>
+
<div class="mw-parser-output">
 +
Various constructors are available to allow a CXFilePath to be build from a C String, string classes, etc.
 +
<syntaxhighlight lang="c++">//
 +
CXFilePath(void);
 +
 
 +
//
 +
CXFilePath(const char* __nullable path);
 +
CXFilePath(const CXString& path);
 +
CXFilePath(const CXStringEdit& path);
 +
template <class OP> inline CXFilePath(const CXFilePathBase<OP>& other);</syntaxhighlight>
 +
 
 +
&nbsp;
 +
 
 +
= Nullness =
 +
 
 +
CXFilePath does not distinguish between null and empty states. An empty filepath cannot be used to reference a file (although it can be appended as a relative filepath, to no effect) and so it is typically treated as a sentinel for a null / invalid / unset&nbsp;value.
 +
</div> <div class="mw-parser-output"><syntaxhighlight lang="c++">// Returns true if this CXFilePath object has a non-zero length.
 +
operator bool(void) const;
 +
 
 +
// Returns true if this CXFilePath is empty.
 +
bool operator !(void) const;</syntaxhighlight>
 +
 
 +
&nbsp;
 +
 
 +
= Path Operations =
 +
</div> <div class="mw-parser-output">Various methods are available for working with path components. <syntaxhighlight lang="c++">// Returns the filename portion of this path.
 +
CXString GetFilename(void) const;
 +
  
 +
// Removes and returns the leftmost path element (root).
 +
CXString StripLeftElement(bool bShouldStripFilenameElement = true);
 +
 
 +
// Remove and return the rightmost path element (filename).
 +
CXString StripRightElement(void);
 +
 
 +
// Returns the path minus its rightmost path element.
 +
CXString GetParentPath(void) const;
 +
 
 +
// Returns true if this object represents an absolute path.
 +
// TBD.
 +
bool IsAbsolutePath(void) const;
 +
 
 +
// Returns true if this object represents the filesystem root.
 +
// TBD.
 +
bool IsRoot(void) const;
 +
 
 +
// Returns true if this object contains a file name but no path separators.
 +
bool IsFilenameOnly(void) const;
 +
 
 +
// Attempt to resolve any './' and '../' references, symlinks, etc.
 +
// TBD.
 +
bool Resolve(void);</syntaxhighlight>
 +
 
 +
&nbsp;
 +
 
 +
&nbsp;
 +
 
 +
= Helper Methods =
 +
 
 +
&nbsp;
 +
</div> <div class="mw-parser-output">&nbsp;</div> </div>

Revision as of 20:33, 25 February 2018

The CXFilePath class provides an platform-neutral file path representation. The file paths are encoded in UTF8 with forward slash ("/") separators. A leading slash indicates an absolute path, otherwise the path is considered relative. The "/./" and "/../" constructs are supported for referring to the current directory and parent directory respectively. No other characters are reserved or prevented. CXFilePath objects are considered case sensitive, regardless of whether the underlying file system is or is not case sensitive.
 
The underlying CXFilePathBase templated class allows selection of a string container. CXFilePath is implemented as CXFilePathBase<CXString>. As an alternative, the application can use CXFilePathBase<CXStringEdit> instead of CXFilePath if high-performance editing is required.
 

Native Encodings

Where the host platform differs from these details, transformation between CXFilePath encoding and the native encoding occurs at the lowest possible level. The application should never need to deal with native encoding except where it is directly accessing native functions (bypassing the cxsource framework).
 

Windows

TBD.
C:\foo\bah.txt
C:\foo/bah.txt
\\machine\share\foo\bah.txt
\\?..
 

Posix

CXFilePath directly adopts posix filepath format and no significant transformations are required to convert between a posix file path and a CXFilePath. If the underlying APIs do not accept UTF-8 input, then a string codepage transformation may be required.
 

Construction

Various constructors are available to allow a CXFilePath to be build from a C String, string classes, etc.

//
CXFilePath(void);

//
CXFilePath(const char* __nullable path);
CXFilePath(const CXString& path);
CXFilePath(const CXStringEdit& path);
template <class OP> inline CXFilePath(const CXFilePathBase<OP>& other);

 

Nullness

CXFilePath does not distinguish between null and empty states. An empty filepath cannot be used to reference a file (although it can be appended as a relative filepath, to no effect) and so it is typically treated as a sentinel for a null / invalid / unset value.

// Returns true if this CXFilePath object has a non-zero length.
operator bool(void) const;

// Returns true if this CXFilePath is empty.
bool operator !(void) const;

 

Path Operations

Various methods are available for working with path components.
// Returns the filename portion of this path.
CXString GetFilename(void) const;
  
// Removes and returns the leftmost path element (root).
CXString StripLeftElement(bool bShouldStripFilenameElement = true);

// Remove and return the rightmost path element (filename).
CXString StripRightElement(void);

// Returns the path minus its rightmost path element.
CXString GetParentPath(void) const;

// Returns true if this object represents an absolute path.
// TBD.
bool IsAbsolutePath(void) const;

// Returns true if this object represents the filesystem root.
// TBD.
bool IsRoot(void) const;

// Returns true if this object contains a file name but no path separators.
bool IsFilenameOnly(void) const;

// Attempt to resolve any './' and '../' references, symlinks, etc.
// TBD.
bool Resolve(void);

 

 

Helper Methods