7 #ifndef NAZARA_RESOURCELOADER_HPP 8 #define NAZARA_RESOURCELOADER_HPP 10 #include <Nazara/Core/Enums.hpp> 11 #include <Nazara/Core/Resource.hpp> 12 #include <Nazara/Core/ResourceParameters.hpp> 13 #include <Nazara/Core/String.hpp> 16 #include <type_traits> 22 template<
typename Type,
typename Parameters>
25 static_assert(std::is_base_of<ResourceParameters, Parameters>::value,
"ResourceParameters must be a base of Parameters");
30 using ExtensionGetter = bool (*)(
const String& extension);
31 using FileLoader = bool (*)(Type* resource,
const String& filePath,
const Parameters& parameters);
32 using MemoryLoader = bool (*)(Type* resource,
const void* data, std::size_t size,
const Parameters& parameters);
33 using StreamChecker = Ternary (*)(
Stream& stream,
const Parameters& parameters);
34 using StreamLoader = bool (*)(Type* resource,
Stream& stream,
const Parameters& parameters);
41 static bool LoadFromFile(Type* resource,
const String& filePath,
const Parameters& parameters = Parameters());
42 static bool LoadFromMemory(Type* resource,
const void* data, std::size_t size,
const Parameters& parameters = Parameters());
43 static bool LoadFromStream(Type* resource,
Stream& stream,
const Parameters& parameters = Parameters());
45 static void RegisterLoader(ExtensionGetter extensionGetter, StreamChecker checkFunc, StreamLoader streamLoader, FileLoader fileLoader =
nullptr, MemoryLoader memoryLoader =
nullptr);
46 static void UnregisterLoader(ExtensionGetter extensionGetter, StreamChecker checkFunc, StreamLoader streamLoader, FileLoader fileLoader =
nullptr, MemoryLoader memoryLoader =
nullptr);
49 using Loader = std::tuple<ExtensionGetter, StreamChecker, StreamLoader, FileLoader, MemoryLoader>;
50 using LoaderList = std::list<Loader>;
54 #include <Nazara/Core/ResourceLoader.inl> 56 #endif // NAZARA_RESOURCELOADER_HPP TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
static bool LoadFromMemory(Type *resource, const void *data, std::size_t size, const Parameters ¶meters=Parameters())
Loads a resource from a raw memory, a size and parameters.
Definition: ResourceLoader.inl:163
static void UnregisterLoader(ExtensionGetter extensionGetter, StreamChecker checkFunc, StreamLoader streamLoader, FileLoader fileLoader=nullptr, MemoryLoader memoryLoader=nullptr)
Unregisters the loader.
Definition: ResourceLoader.inl:313
Core class that represents a string.
Definition: String.hpp:22
static bool LoadFromFile(Type *resource, const String &filePath, const Parameters ¶meters=Parameters())
Loads a resource from a file.
Definition: ResourceLoader.inl:56
Core class that represents a loader of resources.
Definition: ResourceLoader.hpp:23
static void RegisterLoader(ExtensionGetter extensionGetter, StreamChecker checkFunc, StreamLoader streamLoader, FileLoader fileLoader=nullptr, MemoryLoader memoryLoader=nullptr)
Registers the loader.
Definition: ResourceLoader.inl:295
Core class that represents a stream.
Definition: Stream.hpp:19
static bool IsExtensionSupported(const String &extension)
Checks whether the extension of the file is supported.
Definition: ResourceLoader.inl:27
static bool LoadFromStream(Type *resource, Stream &stream, const Parameters ¶meters=Parameters())
Loads a resource from a stream and parameters.
Definition: ResourceLoader.inl:244