CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
URLSession.ZIP.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "URLSession.hpp"
11#include "ZIP.hpp"
12
14
15#if defined(libzip_FOUND)
16
17namespace CeresEngine {
18
20 class ZIPURLProtocol : public TURLProtocol<ZIPURLProtocol, "ZIP"> {
21 private:
22 struct Pimpl;
23 const UPtr<Pimpl> m;
24
25 public:
26 struct Archive;
27
29 class Request : public IURLRequest {
30 public:
32 explicit Request(const IURLRequest& other) : IURLRequest(other) {}
33
35 explicit Request(const URL& url, const CachePolicy& cachePolicy) : IURLRequest(url, cachePolicy) {}
36
38 ~Request() noexcept override;
39 };
40 static_assert(URLRequest::isSmall<Request>);
41
43 class Response : public IURLResponse {
44 private:
45 const SPtr<Archive> mArchive;
46 ZIPArchive::Entry mEntry;
47
48 public:
50 explicit Response(const URLRequest& request, const SPtr<Archive>& archive, ZIPArchive::Entry entry);
51
53 ~Response() noexcept override;
54
55 public:
57 [[nodiscard]] URLInputStream openInputStream() override;
58
59 [[nodiscard]] const URLResponse& getUnderlyingResponse() const;
60 };
61
62 private:
64 HashMap<UUID, WPtr<Archive>> mActiveArchives;
65
66 public:
67 ZIPURLProtocol(URLSession& session);
68
70 ~ZIPURLProtocol() noexcept override;
71
72 public:
74 [[nodiscard]] bool isRequestSupported(const URLRequest& request) final;
75
77 [[nodiscard]] Async<URLResponse> execute(Task& connection) final;
78
79 private:
80 void notifyArchiveDestroyed(Archive* archive);
81 };
82
84 using ZIPURLRequest = ZIPURLProtocol::Request;
85
87 using ZIPURLResponse = ZIPURLProtocol::Response;
88
89} // namespace CeresEngine
90
91#endif
Definition Application.hpp:19
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25