CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
ResourceImporter.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
11
13
18
20
21namespace CeresEngine {
22
23 class URLSession;
24
62
69
71 ImportedResources() = default;
72
76
80
84
87 CE_EXPLICIT(false) ImportedResources(ResourcePtr resource, const UUID suggestedUUID = {}, String suggestedName = {})
88 : resources({ImportedResource(std::move(resource), suggestedUUID, std::move(suggestedName))}) {}
89
92 template<typename T>
93 CE_EXPLICIT(false) ImportedResources(SPtr<T> resource, UUID suggestedUUID = {}, String suggestedName = {})
94 : resources({ImportedResource(std::move(resource), suggestedUUID, std::move(suggestedName))}) {}
95
98 CE_EXPLICIT(false) ImportedResources(HResource resource, const UUID suggestedUUID = {}, String suggestedName = {})
99 : resources({ImportedResource(std::move(resource), suggestedUUID, std::move(suggestedName))}) {}
100
103 template<typename T>
104 CE_EXPLICIT(false) ImportedResources(ResourceHandle<T> resource, UUID suggestedUUID = {}, String suggestedName = {})
105 : resources({ImportedResource(std::move(resource), suggestedUUID, std::move(suggestedName))}) {}
106 };
107
112
129
134
161
163 protected:
167
170
173
174 public:
177 explicit ResourceImporter2(ResourceManager& resourceManager);
178
180 virtual ~ResourceImporter2() = default;
181
182 public:
187
192 };
193
197 protected:
201
204
207
208 public:
211 explicit ResourceImporter(ResourceManager& resourceManager);
212
214 virtual ~ResourceImporter() = default;
215
216 public:
222 [[nodiscard]] virtual Async<ImportedResources> import(const ResourceURL& url, const ResourceImportOptions& options) = 0;
223
225 enum class SupportStatus {
227 Supported,
228
232 Generic,
233
237 };
238
245 };
246
248 template<typename T, typename O = ResourceImportOptions> class TResourceImporter : public ResourceImporter {
249 public:
251
252 public:
254 [[nodiscard]] Async<ImportedResources> import(const ResourceURL& url, const ResourceImportOptions& options) final {
255// const O* castedOptions = dynamic_cast<const O*>(&options);
256// if(castedOptions == nullptr) {
257 static const O defaultOptions;
258// castedOptions = &defaultOptions;
259// }
260 return import(url, defaultOptions);
261 }
262
264 [[nodiscard]] virtual Async<ImportedResources> import(const ResourceURL& url, const O& options) = 0;
265 };
266
268 template<typename T> class TResourceImporter<T, ResourceImportOptions> : public ResourceImporter {
269 public:
271 };
272
273} // namespace CeresEngine
#define CE_EXPLICIT(EXPR)
Definition Macros.hpp:413
A context for function object execution.
Definition ExecutionContext.hpp:90
A stream that provides read-only stream functionality.
Definition Stream.hpp:210
Definition ResourceHandle.hpp:166
Definition ResourceImporter.hpp:162
virtual ~ResourceImporter2()=default
Destroys the resource importer.
URLSession & mURLSession
The URL session to be used to load resources.
Definition ResourceImporter.hpp:169
virtual Async< Optional< ResourceImporterPeekResponse > > peek(const ResourceURL &url, const ResourceImporterPeekSession &session)=0
Peeks the resource.
ResourceImporter2(ResourceManager &resourceManager)
Creates a new resource importer.
ResourceManager & mResourceManager
The owning resource manager.
Definition ResourceImporter.hpp:166
virtual Async< ImportedResources > importResource(const ResourceURL &url, ResourceImporterSession &session)=0
Peeks the resource.
ExecutionContext & mExecutionContext
The execution context to perform asynchronous resource operations on.
Definition ResourceImporter.hpp:172
Primary class used to implement parsers and imports for common file formats to engine resources.
Definition ResourceImporter.hpp:196
ResourceImporter(ResourceManager &resourceManager)
Creates a new resource importer.
ResourceManager & mResourceManager
The owning resource manager.
Definition ResourceImporter.hpp:200
ExecutionContext & mExecutionContext
The execution context to perform asynchronous resource operations on.
Definition ResourceImporter.hpp:206
URLSession & mURLSession
The URL session to be used to load resources.
Definition ResourceImporter.hpp:203
virtual ~ResourceImporter()=default
Destroys the resource importer.
SupportStatus
An enumeration that contains the possible importer support status.
Definition ResourceImporter.hpp:225
@ Generic
Indicates that the format is supported by the importer, but it uses a generic parser.
@ Unsupported
The format is unsupported and the importer don't know how to interpret the data.
@ Supported
Indicates that the format is supported by the importer.
virtual Async< SupportStatus > supports(const ResourceURL &url)=0
Checks if the import supports the given resource.
The ResourceManager is the main class responsible for managing and handling all resources in the engi...
Definition ResourceManager.hpp:47
Creates a new resource importer.
Definition ResourceImporter.hpp:248
A Uniform Resource Identifier (URI) is a unique sequence of characters that identifies a logical or p...
Definition URI.hpp:54
The metadata associated with the response to a URL load request, independent of protocol and URL sche...
Definition URLSession.hpp:245
An object that coordinates a group of related, network data transfer tasks.
Definition URLSession.hpp:399
Definition Variant.hpp:15
Definition Application.hpp:19
std::unique_ptr< T, Deleter > UPtr
UPtr is a smart pointer that owns and manages another object through a pointer and disposes of that o...
Definition SmartPtr.hpp:28
std::shared_ptr< T > SPtr
SPtr is a smart pointer that retains shared ownership of an object through a pointer.
Definition SmartPtr.hpp:37
cti::continuable< Args... > Async
Defines a non-copyable continuation type which uses the function2 backend for type erasure.
Definition Async.hpp:22
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
auto move(Vector3 position)
Moves a entity to the given position.
Definition Helpers.hpp:22
::CeresEngine::ResourceHandle< Resource > HResource
Definition Forward.hpp:47
SPtr< Resource > ResourcePtr
Definition Forward.hpp:47
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition Span.hpp:668
A single resource imported by an importer.
Definition ResourceImporter.hpp:28
UUID suggestedUUID
A suggested UUID for the resource.
Definition ResourceImporter.hpp:36
String suggestedName
A suggested name for the imported resource.
Definition ResourceImporter.hpp:39
Variant< HResource, ResourcePtr > resource
The primary imported resource.
Definition ResourceImporter.hpp:30
ImportedResource()=default
Creates a new empty ImportedResource struct.
A structure that contains the imported resources returned by an importer.
Definition ResourceImporter.hpp:65
ImportedResources()=default
Creates a new empty ImportedResources struct.
Vector< ImportedResource > resources
The resources returned by the importer.
Definition ResourceImporter.hpp:68
Definition ResourceImporter.hpp:108
const ResourceImportOptions & options
Definition ResourceImporter.hpp:110
ResourceTypeInfo desiredResource
Definition ResourceImporter.hpp:109
A structure that contains import options that describes how a resource should be imported.
Definition ResourceImportOptions.hpp:16
Definition ResourceImporter.hpp:130
UPtr< ResourceImportOptions > importOptions
A pointer to import options from the peeking.
Definition ResourceImporter.hpp:132
Definition ResourceImporter.hpp:113
const ResourceTypeInfo * typeInfo
Specifies the type of resource to import.
Definition ResourceImporter.hpp:116
URLResponse urlResponse
The URL response for the request that may have been performed for file peeking.
Definition ResourceImporter.hpp:121
InputStream inputStream
Points to a input stream that cam be used for peeking.
Definition ResourceImporter.hpp:127
A structure that specifies data for an import session.
Definition ResourceImporter.hpp:136
const ResourceTypeInfo * typeInfo
Specifies the type of resource to import.
Definition ResourceImporter.hpp:143
const UPtr< ResourceImportOptions > importOptions
A pointer to the import options to be used for the request.
Definition ResourceImporter.hpp:139
URLResponse urlResponse
The URL response for the request that may have been performed for file peeking.
Definition ResourceImporter.hpp:153
ResourceImporter *const importer
The importer that successfully peeked the file.
Definition ResourceImporter.hpp:148
InputStream inputStream
Only defined if urlResponse is defined.
Definition ResourceImporter.hpp:159
A structure that describes type information for a resource.
Definition Resource.hpp:63
Represents a universally unique identifier (UUID).
Definition UUID.hpp:27