#include <url.h>
Class to handle Urls.
Urls consist of three parts: a scheme, an authority and a path. The readable text-representation is "scheme://authority/path".
The scheme defines which handler is used, e.g. "http" for web-based connections or "file" for the regular file system.
The authority defines the machine, which can be empty for "localhost", a network drive or a webserver. It can also refer to an embedded file, e.g. a ZIP. To distinguish that case the readable text representation contains brackets: "scheme://[authority]/path". Nesting is possible repeatedly.
Finally the path component defines the unique location of a file or directory on the target machine. In most schemes paths are a combination of the directory path and file path, but the path could also be a network query or database entry. Path components are always separated by a forward slash and the forward slash is a reserved character that cannot be used for names.
Urls are always case-sensitive, independent of the used scheme handler.
Under Windows the backslash is automatically replaced and converted to a forward slash when you use SetPath or SetSystemPath. Note that backslashes passed to SetUrl or Url() will not be converted.
One note about constructing Url paths: if you use Append or + there is a big difference whether you add a String or a Url. If you add a String you can only add a single name component. With a relative Url you can add multiple path components at once (however this must be a relative Url, any other type will fail). E.g. allowed is Url a = Url("file:///HD"_s) + "test"_s + "image.tif"_s; Url b = Url("file:///HD"_s) + Url("test/image.tif"_s); whereas this will fail: Url a = Url("file:///HD"_s) + "test/image.tif"_s; Url a = Url("file:///HD"_s) + Url("file:///test"_s);
Here an overview over different types of Urls:
If the Url class is used, it should always be clear what the object can be - a file, a directory, a path (file or directory) or a relative path. Therefore the naming convention is very strict and refers to RFC1738. The path component of a Url typically consists of a directory and a name. Name is the term for a simple filename like test.abc or picture.png. Its placed at the end of a Url. A directory is a set of strings, split by the forward slash-delimiter, in which other directories are kept, e.g. \/Users/MyUser/Desktop. Path is the combination of directory and name.
Following this convention helps the maintainers and users of a function to keep track of what is accepted. If the Url parameter name of a saving function contains for example path it's always clear that the function needs the directory and a name. If the user is allowed to pass everything to the function (a file or directory) the documentation should clarify that (and if the behavior differs from what is passed it must also be documented). Examples:
Functions starting with "Io" operate directly on the object behind the Url (e.g. a file or directory).
@MAXON_ANNOTATION{reflection}
Public Member Functions | |
MAXON_DEFAULT_REFERENCE_CONSTRUCTORS (Url, Reference) | |
Url (const UrlScheme &scheme) | |
Url (const String &urlString) | |
Url (const CString &urlString) | |
Url (const UrlScheme &scheme, const Url &authority, const String &path) | |
template<typename T = void, typename KEY = void> | |
Result< typename std::conditional< STD_IS_REPLACEMENT(void, T), typename IsFidClass< KEY >::type, T >::type > | Get (KEY &&key) const |
template<typename T , typename KEY > | |
T | Get (KEY &&key, const T &defaultValue) const |
template<typename T , typename KEY > | |
Result< void > | Set (KEY &&key, T &&data, Bool persistent=true) |
UrlScheme constructor.
[in] | scheme | Creates an Url and sets a scheme (e.g. URLSCHEME_FILE or URLSCHEME_HTTP). |
Url constructor from a String. Identical to SetUrl(urlString, true).
[in] | urlString | A valid Url, e.g. "file:///H:/test.txt". If no scheme is specified URLSCHEME_FILESYSTEM will be assumed and the regular file system syntax can be passed. If no scheme is specified and the urlString starts with no drive letter or slash URLSCHEME_RELATIVE will be assumed. |
Url constructor from a CString. Identical to SetUrl(urlString, true).
[in] | urlString | A valid Url, e.g. "file:///H:/test.txt". If no scheme is specified URLSCHEME_FILESYSTEM will be assumed and the regular file system syntax can be passed. If no scheme is specified and the urlString starts with no drive letter or slash URLSCHEME_RELATIVE will be assumed. |
MAXON_DEFAULT_REFERENCE_CONSTRUCTORS | ( | Url | , |
Reference | |||
) |
Result<typename std::conditional<STD_IS_REPLACEMENT(void, T), typename IsFidClass<KEY>::type, T>::type> Get | ( | KEY && | key | ) | const |
Get data stored under a specific key. If the key is not found an error will be returned. This functions offers 2 possible calls. First using an FId "dict.Get(MAXCHINEINFO::COMPUTERNAME)" or second using any type directly together with the result type "dict.Get<String>(Int32(5))". The data type needs to be registered.
[in] | key | Key under which the data is stored. |
T Get | ( | KEY && | key, |
const T & | defaultValue | ||
) | const |
Get data stored under a specific key. If the key is not found the given default value will be returned. This functions offers 2 possible calls. First using an FId "dict.Get(MAXCHINEINFO::COMPUTERNAME, String())" or second using any type directly together with the result type "dict.Get(Int32(5), String())". The data type needs to be registered.
[in] | key | Key under which the data is stored. |
[in] | defaultValue | Default value which should be returned if the key cannot be found. |
Set data under a specific id. this function is template to allow implicit Set calls for each data type. This functions offers 2 possible calls. First using an FId "dict.Set(MAXCHINEINFO::COMPUTERNAME, "data"_s)" or second using any type directly "dict.Set(Int32(5), "data"_s)". The data type needs to be registered. LiteralId data type is not allowed as value type (#data).
[in] | key | Key under which the data is stored. |
[in] | data | Data to be stored in the dictionary. |
[in] | persistent | With the default value of true the attribute value is serialized. Use false for a transient attribute (one which shall not be serialized). |