Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::ResourceLoader< Type, Parameters > Class Template Reference

Core class that represents a loader of resources. More...

Public Types

using ExtensionGetter = bool(*)(const String &extension)
 
using FileLoader = bool(*)(Type *resource, const String &filePath, const Parameters &parameters)
 
using MemoryLoader = bool(*)(Type *resource, const void *data, std::size_t size, const Parameters &parameters)
 
using StreamChecker = Ternary(*)(Stream &stream, const Parameters &parameters)
 
using StreamLoader = bool(*)(Type *resource, Stream &stream, const Parameters &parameters)
 

Static Public Member Functions

static bool IsExtensionSupported (const String &extension)
 Checks whether the extension of the file is supported. More...
 
static bool LoadFromFile (Type *resource, const String &filePath, const Parameters &parameters=Parameters())
 Loads a resource from a file. More...
 
static bool LoadFromMemory (Type *resource, const void *data, std::size_t size, const Parameters &parameters=Parameters())
 Loads a resource from a raw memory, a size and parameters. More...
 
static bool LoadFromStream (Type *resource, Stream &stream, const Parameters &parameters=Parameters())
 Loads a resource from a stream and parameters. More...
 
static void RegisterLoader (ExtensionGetter extensionGetter, StreamChecker checkFunc, StreamLoader streamLoader, FileLoader fileLoader=nullptr, MemoryLoader memoryLoader=nullptr)
 Registers the loader. More...
 
static void UnregisterLoader (ExtensionGetter extensionGetter, StreamChecker checkFunc, StreamLoader streamLoader, FileLoader fileLoader=nullptr, MemoryLoader memoryLoader=nullptr)
 Unregisters the loader. More...
 

Detailed Description

template<typename Type, typename Parameters>
class Nz::ResourceLoader< Type, Parameters >

Core class that represents a loader of resources.

Member Function Documentation

◆ IsExtensionSupported()

template<typename Type , typename Parameters >
bool Nz::ResourceLoader< Type, Parameters >::IsExtensionSupported ( const String extension)
static

Checks whether the extension of the file is supported.

Returns
true if supported
Parameters
extensionExtension of the file

◆ LoadFromFile()

template<typename Type , typename Parameters >
bool Nz::ResourceLoader< Type, Parameters >::LoadFromFile ( Type *  resource,
const String filePath,
const Parameters &  parameters = Parameters() 
)
static

Loads a resource from a file.

Returns
true if successfully loaded
Parameters
resourceResource to load
filePathPath to the resource
parametersParameters for the load
Remarks
Produces a NazaraError if resource is nullptr with NAZARA_CORE_SAFE defined
Produces a NazaraError if parameters are invalid with NAZARA_CORE_SAFE defined
Produces a NazaraError if filePath has no extension
Produces a NazaraError if file count not be opened
Produces a NazaraWarning if loader failed
Produces a NazaraError if all loaders failed or no loader was found

◆ LoadFromMemory()

template<typename Type , typename Parameters >
bool Nz::ResourceLoader< Type, Parameters >::LoadFromMemory ( Type *  resource,
const void *  data,
std::size_t  size,
const Parameters &  parameters = Parameters() 
)
static

Loads a resource from a raw memory, a size and parameters.

Returns
true if successfully loaded
Parameters
resourceResource to load
dataRaw memory of the resource
sizeSize available for the read
parametersParameters for the load
Remarks
Produces a NazaraError if resource is nullptr with NAZARA_CORE_SAFE defined
Produces a NazaraError if size is 0 with NAZARA_CORE_SAFE defined
Produces a NazaraError if parameters are invalid with NAZARA_CORE_SAFE defined
Produces a NazaraWarning if loader failed
Produces a NazaraError if all loaders failed or no loader was found

◆ LoadFromStream()

template<typename Type , typename Parameters >
bool Nz::ResourceLoader< Type, Parameters >::LoadFromStream ( Type *  resource,
Stream stream,
const Parameters &  parameters = Parameters() 
)
static

Loads a resource from a stream and parameters.

Returns
true if successfully loaded
Parameters
resourceResource to load
streamStream of the resource
parametersParameters for the load
Remarks
Produces a NazaraError if resource is nullptr with NAZARA_CORE_SAFE defined
Produces a NazaraError if stream has no data with NAZARA_CORE_SAFE defined
Produces a NazaraError if parameters are invalid with NAZARA_CORE_SAFE defined
Produces a NazaraWarning if loader failed
Produces a NazaraError if all loaders failed or no loader was found

◆ RegisterLoader()

template<typename Type , typename Parameters >
void Nz::ResourceLoader< Type, Parameters >::RegisterLoader ( ExtensionGetter  extensionGetter,
StreamChecker  checkFunc,
StreamLoader  streamLoader,
FileLoader  fileLoader = nullptr,
MemoryLoader  memoryLoader = nullptr 
)
static

Registers the loader.

Parameters
extensionGetterA function to test whether the extension (as a string) is supported by this loader
checkFuncA function to check the stream with the parser
streamLoaderA function to load the data from a stream in the resource
fileLoaderOptional function to load the data from a file in the resource
memoryLoaderOptional function to load the data from a raw memory in the resource

◆ UnregisterLoader()

template<typename Type , typename Parameters >
void Nz::ResourceLoader< Type, Parameters >::UnregisterLoader ( ExtensionGetter  extensionGetter,
StreamChecker  checkFunc,
StreamLoader  streamLoader,
FileLoader  fileLoader = nullptr,
MemoryLoader  memoryLoader = nullptr 
)
static

Unregisters the loader.

Parameters
extensionGetterA function to test whether the extension (as a string) is supported by this loader
checkFuncA function to check the stream with the parser
streamLoaderA function to load the data from a stream in the resource
fileLoaderOptional function to load the data from a file in the resource
memoryLoaderOptional function to load the data from a raw memory in the resource

The documentation for this class was generated from the following files: