To prevent mixing up local path and remote path parameters when calling the FC++ API, the path and/or filenames are wrapped using the simple fc::Local and fc::Remote classes. More...
#include <FCPath.hpp>
Public Member Functions | |
virtual | ~Name () |
Name (const std::string &n) | |
virtual bool | empty () const |
virtual const char * | c_str () const |
virtual | operator const char * () const |
virtual | operator const std::string & () const |
virtual const std::string & | str () const |
virtual Name & | operator+= (const std::string &rhs) |
Append a filename to an existing Local or Remote object. More... | |
virtual void | setDefaultDir (const std::string &dir) const =0 |
Set the default directory. More... | |
virtual const std::string & | defaultDir () const =0 |
Get the default directory. More... | |
virtual const std::string & | separator () const =0 |
Return the usual path separator, such as slash or backslash. More... | |
virtual bool | isAbsolute () const |
Original name is absolute, such as /tmp/test.txt or C:\Files . More... | |
virtual bool | isRelative () const |
Original name is relative, such as test.txt or ..\test.txt . More... | |
virtual const std::string & | name () const |
The original name specified when this object was first instantiated. More... | |
virtual std::string | create_temporary_filename (const fc::Options &options) const |
Create a temporary filename to use based on the prefix and suffix in the given options. More... | |
virtual const std::string & | parentDir () const |
Get the parent directory if known, or a blank string if unknown. More... | |
virtual const std::string & | filename () const |
Get the last component in full() which normally would be the filename. More... | |
virtual const std::string & | full () const |
Get the full name. More... | |
Protected Member Functions | |
std::string | findSeparator () const |
Logic to extract the directory separator from the default directory or the explicit name. More... | |
virtual Name & | clearCache () |
Clear the mutable cache items. More... | |
Protected Attributes | |
std::string | explicitName |
The name used when the object was instantiated. More... | |
std::string | fileName |
the last component from full() More... | |
std::string | parentDirectory |
the parent directory including the terminating slash More... | |
std::string | fullDirAndName |
the name combined with the default directory More... | |
virtual Name & | simplify () |
Attempt to simplify the path by removing double slashes and things like "../". More... | |
static std::string | simplify (std::string &path) |
Attempt to simplify the path by removing double slashes and things like "../". More... | |
To prevent mixing up local path and remote path parameters when calling the FC++ API, the path and/or filenames are wrapped using the simple fc::Local and fc::Remote classes.
This guarantees at compile-time that the local and remote paths cannot be accidentally inverted.
Consider these 2 similar examples:
In the first example, it isn't immediately obvious if the file output.txt
is being uploaded as readme.txt
, or if it is the other way around. In the second example, not only is it immediately obvious, but if the filename parameters are ever swapped, the code wouldn't compile.
Normally, when provided with a Local or Remote object, the method you'll want to call is fc::Name::full().
|
virtual |
|
explicit |
|
inlinevirtual |
References name().
|
inlinevirtual |
|
inlinevirtual |
|
inlinevirtual |
|
inlinevirtual |
References full().
|
virtual |
Attempt to simplify the path by removing double slashes and things like "../".
|
static |
Attempt to simplify the path by removing double slashes and things like "../".
|
virtual |
|
pure virtual |
Set the default directory.
Will ensure it is terminated by a slash or backslash.
Implemented in fc::Remote, and fc::Local.
|
pure virtual |
Get the default directory.
This is guaranteed to be terminated by a slash or backslash.
Implemented in fc::Remote, and fc::Local.
|
pure virtual |
Return the usual path separator, such as slash or backslash.
Implemented in fc::Remote, and fc::Local.
|
virtual |
Original name
is absolute, such as /tmp/test.txt
or C:\Files
.
|
virtual |
Original name
is relative, such as test.txt
or ..\test.txt
.
|
virtual |
The original name specified when this object was first instantiated.
You probably want to use full() instead.
|
virtual |
Create a temporary filename to use based on the prefix and suffix in the given options.
This is intended for internal use by FC++ to generate a usable temporary name, and likely doesn't need to be called directly.
|
virtual |
Get the parent directory if known, or a blank string if unknown.
The directory name (if not empty) will always be terminated with /
or \
. For example:
Original Name | parentDir() |
---|---|
test.txt | |
../test.txt | ../ |
/tmp/foo/bar/name.txt | /tmp/foo/bar/ |
/testing/123/ | /testing/ |
/ | / |
|
virtual |
Get the last component in full() which normally would be the filename.
|
virtual |
Get the full name.
Most of the time, this is the method you'll want to call to generate a path or filename.
|
protected |
Logic to extract the directory separator from the default directory or the explicit name.
|
protectedvirtual |
Clear the mutable cache items.
|
protected |
The name used when the object was instantiated.
|
mutableprotected |
the last component from full()
|
mutableprotected |
the parent directory including the terminating slash
|
mutableprotected |
the name combined with the default directory