AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AUrl.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14#include "AUI/Common/AString.h"
15#include "AUI/Common/SharedPtr.h"
16#include "AUI/IO/IInputStream.h"
17#include <AUI/Common/AMap.h>
18
19#include <utility>
20
31class API_AUI_CORE AUrl {
32public:
33 using Resolver = std::function<_unique<IInputStream>(const AUrl&)>;
34
35 AUrl(AString full);
36
37 inline AUrl(const char* full) : AUrl(AString(full)) {}
38
39 AUrl(AString schema, AString path) : mSchema(std::move(schema)), mPath(std::move(path)) {}
40
41 static AUrl file(const AString& file) {
42 return {"file", file};
43 }
44
45 [[nodiscard]]
46 _unique<IInputStream> open() const;
47
48 [[nodiscard]]
49 const AString& path() const noexcept {
50 return mPath;
51 }
52
53 [[nodiscard]]
54 const AString& schema() const noexcept {
55 return mSchema;
56 }
57
58 [[nodiscard]]
59 AString full() const {
60 return mSchema + "://" + mPath;
61 }
62
63 bool operator<(const AUrl& u) const {
64 return full() < u.full();
65 }
66
67 static void registerResolver(const AString& protocol, Resolver resolver);
68
69private:
70 AString mSchema;
71 AString mPath;
72
73 static AMap<AString, AVector<AUrl::Resolver>>& resolvers();
74};
75
76
77inline AUrl operator""_url(const char* input, size_t s) {
78 return AUrl(std::string{input, input + s});
79}
A std::map with AUI extensions.
Definition: AMap.h:218
Represents a Unicode character string.
Definition: AString.h:37
Uniform Resource Locator implementation.
Definition: AUrl.h:31